CS
Data Structure: Heaps
Objectives
Heaps
Priority Queues
Heap sort
Priority Queues
In a number of applications a data structure that can produce
the smallest item in a collection is useful.
Obviously any sorted list can do the job.
However, we may wis
Data Structures
Hash Tables
Hash Tables
Hashing allows us to nd elements in a data structure
quickly without making a linear search
A hash function computes an integer value (called
the hash code) from an object
That integer can then be used t
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Hash Tables
0
1
2
3
4
2014 Goodrich, Tamassia, Godlwasser
Hash Tables
0256120001
9811010002
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Binary Search Trees
<
2
1
2014 Goodrich, Tamassia, Goldwasser
6
9
>
4 =
Binary Search Trees
8
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Heaps
2
5
9
2014 Goodrich, Tamassia, Goldwasser
6
7
Heaps
1
Recall Priority Queue ADT
q
q
q
A pr
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Skip Lists
S3 
+
S2 
15
S1 
15
23
15
23
S0 
2014 Goodrich, Tamassia, Goldwasser
Skip Lists
1
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Analysis of Algorithms
Input
2014 Goodrich, Tamassia, Goldwasser
Algorithm
Analysis of Algorithm
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Adaptable Priority
Queues
3 a
5 g
2014 Goodrich, Tamassia, Goldwasser
Adaptable Priority Queues
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Maps
2014 Goodrich, Tamassia, Goldwasser
Maps
1
Maps
A map models a searchable collection of
key
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Priority Queues
2014 Goodrich, Tamassia, Goldwasser
Priority Queues
1
Priority Queue ADT
q
q
q
A
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Trees
Mammal
Dog
2014 Goodrich, Tamassia, Goldwasser
Pig
Trees
Cat
1
What is a Tree
q
q
q
In com
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Recursion
2014 Goodrich, Tamassia, Goldwasser
Recursion
1
The Recursion Pattern
q
q
q
q
Recursio
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Queues
2014 Goodrich, Tamassia, Goldwasser
Queues
1
The Queue ADT
q
q
q
q
The Queue ADT stores a
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
ObjectOriented Programming
2014 Goodrich, Tamassia, Goldwasser
ObjectOriented Programming
1
Te
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Java Primer 1: Types, Classes
and Operators
2014 Goodrich, Tamassia, Goldwasser
Java Primer 1
1
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Java Primer 2: I/O Methods
and Control Flow
2014 Goodrich, Tamassia, Goldwasser
Java Primer 2
1
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Doubly Linked Lists
2014 Goodrich, Tamassia, Goldwasser
Doubly Linked Lists
1
Doubly Linked List
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Arrays
2014 Goodrich, Tamassia, Goldwasser
Arrays
1
Array Definition
q
q
An array is a sequenced
CSCI3007 OCL Tutorial Background The Royal and Loyal (R&L) company handles loyalty programs for companies that offer their customers various kinds of bonuses (E.g., bonus points, air miles, reduced rates, a larger car for the rate of a smaller one in a Ca
Loyalty Program Information System Requirements
The Royal and Loyal (R&L) company handles loyalty programs for companies that offer their customers various kinds of bonuses (E.g., bonus points, air miles, reduced rates, a larger car for the rate of a smal
Behavior Modeling
Class models express properties that are true of a system at all times Although they are general, they fail to convey interesting behavioral aspects of systems
That is, how objects respond to external stimuli
A variety of alternative
EXAMPLE
Vector Y = SORT(Vector X) pre: true post: ORDERED(Y) PERMUTATION(X,Y)
Sorting Routine
Provide an Englishlanguage statement describing the expected behavior of a routine SORT(X,Y) where X is an input vector of integers and Y is an output vector
DESIGN PATTERNS
A design pattern is a solution to a problem in a context
descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context  Gamma et al.
It is a means of capturing and reusi
OCL (1.4)
Object Constraint Language Official part of UML Strongly typed declarative specification of system properties Assertions plus collection classes plus a notation for navigating in UML diagrams Supported by Rational Rose, ArgoUML, Poseidon/Octopu
Modeling with UML (1.4) Class Model Diagrams
UML class model diagrams are commonly used to represent the structural aspects of system design problems A class diagram consists of a collection of object classes and the relationships among them
Classes
A c
Motivation
With the Library Problem, we saw that we could use a UML class model diagram to conceptualize the main participants in a problem and their relationships The modeling process actually helped us improve the requirements by raising various questi
Exercise StateChart Model of a Clock Radio
Imagine you had to prepare an analysis model of the external behavior of a clock radio What steps would you take to do this?
Statechart Modeling Method
1. 2. 3. 4. 5. 6. 7. 8.
Prepare usage scenarios Determine e
UML Class Diagrams
May also contain interfaces, objects, packages, relationships Sometimes called "static structure diagrams" Unified Modeling Language (UML), version 1.5
www.omg.org/technology/documents/formal/uml.htm
Examples taken from UML Reference
Ambulance System
for Patient Transportation
CS6310 Software Architecture & Design Assignment #2 Design in Other Fields January 17, 08 17 08 Minho Lee Wonjong Song SangHyun Kim Junhui Yun
Problem Area Problem Area
Transporting Patients is Important Issue
