Part 1: Multiple Choice
Enter your answers on the Scantron sheet.
We will not mark answers that have been entered on this sheet.
Each multiple choice question is worth 2.5 marks.
In all the questions below, log(x) means log2 (x). You might nd this fact us
Part 1: Multiple Choice
Enter your answers on the Scantron sheet.
We will not mark answers that have been entered on this sheet.
Each multiple choice question is worth 3.5 marks.
1. Two algorithms, A and B , have time complexities fA (n) and fB (n), respe
DATA STRUCTURES FOR
GRAPHS
Edge list
Adjacency lists
Adjacency matrix
E
NW 35
DL 247
BOS
AA 49
LAX
DL 335 AA 1387 AA 523 AA 411 UA 120 AA 903 UA 877
DFW
JFK
MIA
ORD
TW 45
SFO
V
Data Structures for Graphs
1
Data Structures for Graphs
A Graph! How can w
Breadth-First Search
L0
L1
B
L2
2004 Goodrich, Tamassia
A
Breadth-First Search
C
E
D
F
1
Breadth-First Search ( 12.3.3)
Breadth-first search
(BFS) is a general
technique for traversing
a graph
A BFS traversal of a
graph G
Visits all the vertices and
edge
Depth-First Search
A
B
D
E
C
2004 Goodrich, Tamassia
Depth-First Search
1
Depth-First Search ( 13.3.1)
Depth-first search (DFS)
is a general technique
for traversing a graph
A DFS traversal of a
graph G
Visits all the vertices and
edges of G
Determines w
Hash Tables
0 1 2 3 4
025-612-0001 981-101-0002
451-229-0004
2004 Goodrich, Tamassia
Hash Tables
1
Hash Functions and Hash Tables
A hash function h maps keys of a given type to integers in a fixed interval [0, N 1] Example: h(x) = x mod N is a hash funct
Perferct Hashing
Perfect hashing functions cen be found when all the key values to be
inserted in the table are known un advance.
For example, consider a compiler that uses a hash table to store the
reserved words of a programming language, say Pascal.
Th
Shortest Paths
A
8
B
8
2
2004 Goodrich, Tamassia
Shortest Paths
2
7
5
E
C
3
0
2
4
1
9
D
8
F
3
5
1
Weighted Graphs ( 12.5)
In a weighted graph, each edge has an associated numerical
value, called the weight of the edge
Edge weights may represent, distance
CS 2210 Data Structures and Algorithms
Fall 2014
Instructor
Roberto Solis-Oba
Lecture times: Tu 1:30-3:30 pm and Th 2:30-3:30 pm
Oce: MC417
Email: solis@csd.uwo.ca
Oce hours: Monday and Thursday 3:30 pm to 5:00 pm
Additional oce hours on week when an assi
In computer science, a tree is an abstract model
of a hierarchical structure
A tree consists of nodes with a parent-child
relation
Applications:
Organization of a company
Subtree: tree consisting of a node and its
descendants
A
B
E
C
F
I
J
G
D
H
K
Ordered
Sorting with an Ordered Dictionary
We can use an ordered
dictionary to sort a set
of values
1. Insert the elements one
by one with a series of
insert operations
2. Remove the elements in
sorted order with a series
of smallest() and
remove() operations
The
Part 1: Multiple Choice
Enter your answers on the Scantron sheet.
We will not mark answers that have been entered on this sheet.
Each multiple choice question is worth 2.5 marks.
In all the questions, log(x) means log2 (x).
1. Consider the following pairs
Part 1: Multiple Choice
Enter your answers on the Scantron sheet.
We will not mark answers that have been entered on this sheet.
Each multiple choice question is worth 3.5 marks.
In all the questions below, log(x) means log2 (x). This fact might be useful
Part 1: Multiple Choice
Enter your answers on the Scantron sheet.
We will not mark answers that have been entered on this sheet.
Each multiple choice question is worth 3.5 marks.
In all the questions below, log(x) means log2 (x). This fact might be useful
CS 2210 Assignment 1
1)
To show
1
n
is O(1) we must find constants c > 0 and n0 1 such that
1
n
n n0
c,
We multiply both sides of the inequality by n (we can do this as n n 0 1, so n is
positive) to get
1 c * n, n n0
Now we can choose c = 1 and the above
CS2210b: Data Structures and Algorithms
Winter 2015: Final Examination
180 minutes
Instructions:
Write your name and student number in the space provided
Please check that your exam is complete. It should have 19 pages in total
The examination has a to
GRAPHS
Denitions
Examples
The Graph ADT
PVD
LAX
HNL
STL
DFW
FTL
Graphs
1
What is a Graph?
A graph G = (V,E) is composed of:
V: set of vertices
E: set of edges connecting the vertices in V
An edge e = (u,v) is a pair of vertices
Example:
V= cfw_a,b,c
Dictionaries
2004 Goodrich, Tamassia
Dictionaries
1
Dictionary ADT
The dictionary ADT models a
searchable collection of keyelement entries
The main operations of a
dictionary are searching,
inserting, and deleting items
Multiple items with the same
key a
i
s SBF ) U(A 7(% TC 0' C h2 1 7dwv6hpgfdBF "
F ) )
D C ) W % )
Y
A ) 5 1 b F C b' )% e) F s
s 80!B7(V 9 !b C 8g& 8) S vW
b ) ' 5F@ W
5
y 9 b ) P%) ) C
% u0' 7(% b v(% 87(% U1 77wv6hpBF " s y
1 1 ) W
C W ' ) W 1 Y 2 A ) 5 1 b F C b ' ) % b@ F
s 8XfB7`V
CS2210
Data Structures and Algorithms
Lecture 7: Priority Queues and Heaps
Instructor: Olga Veksler
Outline
Priority queue ADT
2 Simple List-based implementation for Priority
Queue
Heap Data structure
not as efficient as possible
First moderately complex
CS2210
Data Structures and Algorithms
Lecture 10: AVL TREES deletion
6
v
8
3
z
4
Review of Removal in BST
Case 2: node v storing entry to
be removed has no leaf child
either largest key entry in left
subtree of v or smallest key entry
in right subtree of
CS2210
Data Structures and Algorithms
Lecture 8: Binary Search Trees
<
2
1
6
9
>
4 =
Instructor: Olga Veksler
8
Outline
Return to the ordered dictionary ADT
will spend the next 2-3 weeks on several different ways
of implementing an ordered dictionary ADT
Outline
Review
Data Structures
Abstract Data Types
2 Principles of OO Programming
encapsulation
reusability
Java interfaces
can be used to specify ADT in Java
helps with encapsulation
2
Data Structures
Data Structures
Is a systematic way of organizing and
CS2210
Data Structures and Algorithms
Lecture 11: Multiway and (2,4) Trees
9
2 5 7
2004 Goodrich, Tamassia
10 14
Outline
A new type of search trees, Multiway Seach Tree
for ordered dictionary ADT
Searching in multiway trees
(2,4) trees: special case of m
CS2210
Data Structures and Algorithms
Lecture 6: Trees
Make Money Fast!
Stock
Fraud
Ponzi
Scheme
Bank
Robbery
Instructor: Olga Veksler
2004 Goodrich, Tamassia
Outline
Tree as an ADT
Terminology on Trees
Special case of Trees:
Binary trees
Basic Propertie
CS2210
Data Structures and Algorithms
Lecture 9: AVL TREES
definition, properties, insertion
6
v
8
3
z
4
BST Performance
BST with n nodes and of height h
methods find, insert and remove take O(h) time
h is O(n) in the worst case and O(log n) in the best c
CS2210
Data Structures and Algorithms
Lecture 2:
Analysis of Algorithms
Asymptotic notation
Instructor: Olga Veksler
2004 Goodrich, Tamassia
Outline
Comparing algorithms
Pseudocode
Theoretical Analysis of Running time
primitive Operations
counting primit