Title: Data Structures
1Data Structures
2Course objectives
- Describe what data structures and algorithms are
- Write Java code to do simple and complex sorting
- Write Java code to implement stacks and queues
- Write Java code to implement linked lists
- Write Java code to implement various types of
trees - Write Java code to implement hash tables and
heaps - Write Java code to implement graphs
- Describe when to use which types of data
structures
3Data Structure
- An arrangement of data in a computers memory
(sometimes on disk) - Includes
- Linked lists
- Stacks
- Binary trees
- Hash tables
- Graphs
- Etc.
4Algorithms
- Manipulate the data in data structures in various
ways - Searching
- Sorting
- Inserting
- Deleting
5Why study data structures
- Programmers tools e.g. stacks, queues
- Real-world data storage needs
- Student records
- Inventory records
- Etc.
- Real-world modeling
- Queues, stacks
- Graphs routes between locations, printed
circuit boards, etc.
6Overview of data structures
- Array basis of many other structures
- Stack last-in first-out processing
- Queue first-in first-out processing
- Linked list quick insertion and deletion
- Binary tree quick if balanced tree
- Red-black tree tree always balanced
- 2-3-4 tree start of disk storage
- Hash table very fast access if key is known\
- Heap fast access to largest item
- Graph models many real-world situations
7Some definitions
- Database all data to be dealt with in a
particular situation (restricted definition) - Record units into which a database is divided
- Field smallest logical unit
- Key unique identifier for a record
- Search key the particular key value youre
looking for
8Object-Oriented Review
- Objects model of real world containing methods
and variables (instance of a class) - Classes blueprints for objects
- Creating objects the new operator in Java
(also called instantiating an object) - Invoking methods use object name, followed by
the dot operator (.) followed by the method name
along with parameters needed - (See example program)
9Object-Oriented Review
- Constructors to create new objects
- Access modifiers public, private, protected
- Inheritance using a superclass to create a
subclass (parent-child, base-derived) - Polymorphism different methods are called at
run time based on actual object calling - Related by inheritance
- Implements an interface
10Java I/O Review
public static String getString() throws
IOException InputStreamReader isr
new InputStreamReader(System.in)
BufferedReader br new BufferedReader(isr)
String s br.readLine() return s
11Java I/O Review
public static char getChar() throws IOException
String s getString() return
s.charAt(0)
12Java I/O Review
public static int getInt() throws IOException
String s getString() return
Integer.parseInt(s)
13Java I/O Review
public static double getDouble() throws
IOException String s
getString() Double aDub
Double.valueOf(s) return
aDub.doubleValue()
14Java I/O Review (see Komars site, QMCS490,
Working with Files)
try FileReader f new
FileReader("ReadIt.java") BufferedReader
b new BufferedReader(f) String s
null do s b.readLine()
if (s ! null)
System.out.println(s) while (s !
null) catch (Exception e)
System.out.println("File Error")
15Summary
- Data structure is an organization of data
- Correct choice of data structure is critical
- Algorithm is a procedure to accomplish a task
- In Java an algorithm is typically a method
- Data structures are programmers tools, useful in
storing real-world data, and in modeling the
real-world - Database, record, key, and search key are terms
to remember