Splay Trees/B-trees
Chapter 4
Ioannis Stamos
Amor%zed cost
Consider a sequence of M operations(insert/delete/nd)
What is the total cost?
What is the average cost per operation?
Amor%zed cost
Consider a sequence of M operations (insert/delete/n
TheDisjointSetClass
EquivalenceRelations
RelationR onasetS:foreverypair(a,b)witha,binS,aRbis
eitherTorF.IfaRbisT=>aisrelatedtob.
Examples:
a p es:
Relation<onthesetcfw_0,1,2,3,4,5,6
.Manymore.
E i l
Equivalence relationR:
l ti R
aRa,foralla(reflexive)
Priority Queues
(Skew Heaps, Binomial Queues)
Skew Heaps
Self-adjusting heaps
Leftist heaps vs. skew heaps
Avl trees vs. splay trees
O(logN) amortized cost
Merge similar as in le
Sorting II
(A General Lower Bound for Sorting, External
Sorting),
A General Lower Bound for Sor1ng
Theorem: Any sorting algorithm that uses only
comparisons requires (N logN) comparisons in the
worst case !
Holds
Graph Algorithms
(Topological Sorting, Shortest Paths, Dijkstra)
[Remember to select a Topic]
Graphs
G=(V,E)
Set V=cfw_v1,v2,: vertices
Set E=cfw_(vi,vj) | vi, vj in V: edges
Weighted graph: weight on edge (E=cfw_(vi,vj,wij): vi, vj in V, wij is the weigh
CSCI 335
Third assignment
Total: 100 points
Due 4/2/2015
Please, follow the blackboard instructions on writing and submitting
programming assignments
We will not debug your assignment. It should run correctly to receive credit.
Hashing (30 points)
Impleme
Csci 335 Assignment 2
Due Thursday, March 12 th
Using and Comparing Tree Implementations
The goal of this assignment is to become familiar with trees and compare the performance
of the basic binary search tree with
-1-
Software Design and Analysis III
CSCI 335
Spring 2015
Monday/Thursday 11:10-12:25, HN 1516
Instructor:
Ioannis Stamos, [email protected]
http:/www.cs.hunter.cuny.edu/~ioannis
WWW:
Course related material can be found at blackboard
Visit it regul
Csci 335 Assignment 5
Due Thursday May 14
Graph Representation
You will read a directed graph from a text file. Below is an example:
Graph1.txt
5
0 1 0.2 3 10.1 4 0.5 -1
1 0 1.5 -1
2 1 100.0 3 5
,fi*i A,*
A, /l . At
rr
4tttrs $"'r 3
lf 1o
!#rzo *'t I t
e"4 C1 (f
"tY
tytg
q
ta cfw_t
t.3
tl (Wt,";ucfw_-J
r!
$fit
cfw_
t
I
u
r-A
Y
4
t
*wt
!
4
t
t
-"4"
I
I
cfw_:cfw_-t i (r'4 (or*
t
i
I
t
;*"*
i=l
,y14 z, S
lvt
f l#"+ 2c44a
t
|?e
*
,b
"^,
l,
z
-,?
Zoa
Trees/AVL trees
Chapter 4
Trees (general)
Tree (example)
Implementa1on
What if the number of children per parent is not
known?
Implementa1on
Example (Unix le system)
Traversals?
Tree Traversal
Calculate Directory
Sets & Maps in Standard Library
Chapter 4
Ioannis Stamos
STL container: set
From STL sgi denitions:
Set is a Sorted Associative Container that stores objects
of type Key.
Set is a Simple Associative Container,
Nte
,rk"'
cfw_ -"*-*s-'-:
- g+oy
*r,
t tJPu\T
2t *
t,
M
T,
74te&
t S li2Yt
t
4
t
p
*Tr
8*n
il.:t Y+l
13* t
flke?t?
(pq.-1r
I
t,P) h*.%*f
?wrNfu*
Mte-q
$+zM
f"t
FpL.P
.
l>
cfw_?,*1
\ r
q'G+D
Ftk
*
.^-, BnQ#
Ntr I
p(f' ST:'F
cfw_t
"+
J
1
,i;ltl
jr+LM
g+ LA
Splay Trees/B-trees
Chapter 4
Ioannis Stamos
Amor%zed cost
Consider a sequence of M operations(insert/delete/nd)
What is the total cost?
What is the average cost per operation?
Amor%zed cost
Consider a sequence o
Algorithm Analysis Mathematical Background
Chapter 2
Series
Upper bound on T(N)
Lower bound on T(N)
Tight bound on T(N)
Relative Rates of Growth
A nal deni-on
Little-Oh:
T(N) = o(p(N) if for all constants c there exist an n0:
T(N) < cp(N) w
Class Mechanics & Introduction (Chapter 1)
Ioannis Stamos
Instructor
Ioannis Stamos, Professor
PhD from Columbia University in 2001.
Teaches at Hunter & the Graduate Center
http:/www.cs.hunter.cuny.edu/~ioannis
Director of Computer Vision laboratory
Trees/AVL trees
Chapter 4
Trees (general)
Tree (example)
Implementa1on
What if the number of children per parent is not
known?
Implementa1on
Example (Unix le system)
Traversals?
Tree Traversal
Calculate Directory Size
Calculate size of direct
Lists/Stacks/Queues and the STL
Chapter 3
List/Stack/Queue ADTs
Already covered in 235
We will emphasize the STL and use of iterators
Vector vs. List in the STL
STL vector:
Constant time indexing
Slow to add data in the middle
Fast to add d
Algorithm Analysis Mathematical Background
Chapter 2
Series
Upper bound on T(N)
Lower bound on T(N)
Tight bound on T(N)
Relative Rates of Growth
A nal deni-on
Little-Oh:
T(N) = o(p(N) if for all constants c there exist an n0:
T(N) < cp(N) w
Algorithm Design Techniques
Divide and Conquer, Dynamic Programming
Divide and Conquer
Examples ?
General solution to equation
T(N) = a T(N/b) + (Nk)
Divide and Conquer
Examples ?
General solution to equati
Sorting II
(A General Lower Bound for Sorting)
A General Lower Bound for Sor1ng
Theorem: Any sorting algorithm that uses only
comparisons requires (N logN) comparisons in the
worst case !
Holds true for average case as well.
What does this mean
Graph Algorithms
(Negative costs, Acyclic Graphs, Event-node graphs)
[Remember to select a Topic]
NegaNULLe edge costs
Dijkstra may not work
If there are no negative-cost cycles solution exists, but
is expensive: O(|V|*|E|).
WITH negative-cost cy
The Disjoint Set Class
Equivalence Rela-ons
Relation R on a set S: for every pair (a,b) with a, b in S, a R b is either T
or F. If a R b is T => a is related to b.
Examples:
Relation < on the set cfw_0,1,2,3,4,5,6
.Many more.
Equivalence relat