Data Structures - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Data Structures

Description:

... implement hash tables and heaps. Write Java code to ... Heap fast access to largest item. Graph models many real-world situations. Some definitions... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 16
Provided by: UST
Category:
Tags: data | structures

less

Transcript and Presenter's Notes

Title: Data Structures


1
Data Structures
  • Joe Komar

2
Course 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

3
Data Structure
  • An arrangement of data in a computers memory
    (sometimes on disk)
  • Includes
  • Linked lists
  • Stacks
  • Binary trees
  • Hash tables
  • Graphs
  • Etc.

4
Algorithms
  • Manipulate the data in data structures in various
    ways
  • Searching
  • Sorting
  • Inserting
  • Deleting

5
Why 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.

6
Overview 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

7
Some 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

8
Object-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)

9
Object-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

10
Java 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
11
Java I/O Review
public static char getChar() throws IOException
String s getString() return
s.charAt(0)
12
Java I/O Review
public static int getInt() throws IOException
String s getString() return
Integer.parseInt(s)
13
Java I/O Review
public static double getDouble() throws
IOException String s
getString() Double aDub
Double.valueOf(s) return
aDub.doubleValue()
14
Java 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")
15
Summary
  • 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
Write a Comment
User Comments (0)
About PowerShow.com