Title: Chapter 1 Overview
1Chapter 1 Overview
2Outlines
- What are Data Structures and Algorithms Good for?
- Overview of Data Structures
- Overview of Algorithms
- Some Definitions
- Object-Oriented Programming
- Software Engineering
- Java for C Programmers
- Java Library Data Structures - Collections
3This chapter will answer
- What are data structures and algorithms?
- What good will it do me to know about them?
- Why can't I just use arrays and for loops to
handle my data? - When does it make sense to apply what I learn
here?
P001
4What are data structures and algorithms?
- Data Structures are arrangement of data in a
computers memory (or sometimes on a disk). - Include arrays, linked lists, binary trees, and
hash tables. - Algorithms manipulate the data in these
structures in various ways - Searching for particular data item sorting the
data, .
P002
5What are Data Structures and Algorithms Good for?
- You can apply them to solve
- Real-World data storage ( for User)
- Personal record
- Index cards
- Data base
- Programmers Tools (for Program)
- Stacks, Queues, priority queues,
- Real-World Modeling
- Graph for airline routes between cities
P002
Modify page 2
6Cardfile
P003
7Overview of Data Structures
P004
Modify page 4
8Overview of Algorithms
- Many of the algorithms we'll discuss apply
directly to specific data structures. - Insert a new data item.
- Search for a specified item.
- Delete a specified item.
- May also need to know how to iterate through all
the items in a data structure - visiting each one in turn so as to display it or
perform some other action on it. - Most Important Algorithm Sorting (Ch37)
- Recursion is also important for designing some
algorithm. (Ch6)
P005
Modify page 5
9Some Definitions
- Database to refer to all the data that will be
dealt with in a particular situation. - Record the units into which a database is
divided. - Field A Record is usually divided into several
fields. - Key To search for a record within a database you
need to designate one of the record's fields as a
key (search key).
P005
10Key, Search key
P006
11Object Oriented Programming
- Basic introduction to OOP
- See Appendix B for future reading
- OOP was invented because procedural languages,
such as C, Pascal, and BASIC, were found to be
inadequate for large and complex programs. - Lack of correspondence between the program and
the real world.(??????????!) - Internal organization of the program.(?????,
??,??,????????????)
P007
12Problems with Procedural Languages
- Poor Modeling of the Real World
- Difficult to model the real-word using procedural
language. - Functions carry out a task, while data
(variables) stores information, but most
real-world objects do both these things. - Large programs may be difficult to implement.
- Crude Organizational Units
- Procedural programs are organized by dividing the
code into functions (methods). - Focus on functions.
- Variables Local variables (within methods) and
Global variables (whole program) without other
choose !? - Local v.s. global variable ?
- Solution ?? ? OOP
P008
Modify page 8
13Objects in a Nutshell
- An object contains both functions and variables.
( Encapsulation ) - Functions are called methods and variables are
called fields. - OOP solves several problems simultaneously.
- A programming object correspond more accurately
to objects in the real world. - Solve issue of global data in the procedural
model.
P008
Modify page 8
14Objects in a Nutshell
- A class is a specification - a blueprint - for
one or more objects.
class Thermostat private float
currentTemp private float desiredTemp
public void furnace_on() // method body
goes here public void furnace_off()
// method body goes here // end
class Thermostat
Modify page 9
15Objects in a Nutshell
- Creating Object new XXX()
- Allocate memory for store information.
Thermostat therm1, therm2 // create two
references therm1 new Thermostat() // create
two objects and therm2 new Thermostat() //
store references to them
therm2
therm1
0x1020
0x1000
P009
16Objects in a Nutshell
- Accessing Objects Methods
therm2.furnace_on()
System.out.println(therm2.currentTemp)
therm2
0x1020
17A Runnable Object-Oriented Program
Modify page 12
18Some notes for BankApp
- Constructors
- A constructor is a special method that's called
automatically whenever a new object is created. - A constructor allows a new object to be
initialized in a convenient way. - A constructor always has exactly the same name as
the class - You can have many constructors with different
signatures. ( overloading ) - Access modifiers
- determine what methods can access a method or
field. - Keywords public, private, protected, ltdefaultgt
Modify page 13
19Some notes for OOP
- Encapsulation ? Nature, Robustness, Reusing !
- Class access control
- Inheritance (subclassing) ? Reusing !
- Inheritance is the creation of one class, called
the extended or derived class (subclass), from
another class called the base class(Super class). - The extended class has all the features of the
base class, plus some additional features. - Polymorphism ? Extensibility Flexibility !
- Polymorphism involves treating objects of
different classes in the same way. - these different classes must be derived from the
same base class. - Polymorphism simplifies and clarifies program
design and coding.
P013
20Software Engineering
???????
????(??)
????
????
?????
?????
P014
21Java for C Programmers
- Study it carefully by yourself if you are
interested to this topic. - Key issues
- Reference and Pointers (no pointer).
- new operator and Garbage collection for memory
(object) management. - Difference between and equals()
- Primitive data-type and reference data-type
- How to handle Input and Output?
P01522
22Java Library Data Structures
- Java Collection, some pre-defined classes
- java.util.
- Vector, Dictionary, Stack, Hashtable,
- In this book we'll largely ignore these built-in
classes. - We're interested in teaching fundamentals, not in
the details of a particular data-structure
implementation. - Reference to the collection book, Java
Collections An Introduction to Abstract Data
Types, Data Structures and Algorithms
P022
23End of Chapter 1