Additional Contents
Disjoint Sets Data Structure (Chap. 21)
Multiple Operations
An Application of Disjoint-Set
CONNECTED-COMPONENTS(G)
SAME-COMPONENT(u,v)
Linked-List Implementation
Linked-lists for two sets
head
tail
c
h
e
tail
f
g
head
tail
f
c
g
head
Set {c,h,e}
Set {f, g}
UNION of
two Sets
h
e
UNION Implementation
Weighted-Union Heuristic
for any x in a set of n elements. Consider that each time, the UNION
will at least double the length of united set, it will take at most lg n
UNIONS to unite n elements. So each x’s back-to-representative pointer
can be updated at most lg n times.
Disjoint-set Implementation: Forests
c
f
h
e
c
c
c
f
d
d
h
e
c
c
Set {c,h,e}
Set {f,d}
UNION
Straightforward Solution
Union by Rank & Path Compression
Path Compression
f
e
d
c
f
e
d
c
Algorithm for Disjoint-Set Forest
MAKE-SET(x)
LINK(x,y)
FIND-SET(x)
Worst case running time for m MAKE-SET, UNION, FIND-SET operations is:
O(mα(n)) where α(n)≤4. So nearly linear in m.
UNION(x,y)
1. LINK(FIND-SET(x),FIND-SET(y))
Analysis of Union by Rank with Path Compression�(by amortized analysis)
A very quickly growing function and its inverse
Quickness of Function Ak(j)’s Increase
How Quick Ak(j) Increase
>> A2(2047) =22048.2048-1 >22048 =(24)512 =(16)512
Inverse of Ak(n):α(n)
Another very slow increasing function
O(mα(n)) bound: Property of Ranks
O(mα(n)) bound proof
Potential Function
level(x) and iter(x)
Relations among rank[p[x]], level(x) and iter(x)
Properties for Potential Function φq(x)
Potential Changes of Operations
Amortized Costs of Operations
Amortized Costs of Operations (cont.)
Amortized Costs of Operations (cont.)
Proof of Lemma 21.12 (cont.)
Proof of Lemma 21.12 (cont.)
≥Ak(rank[p[x]]) (since Ak(j) is strictly increasing)
≥Ak(Ak(iter(x))(rank[x]))
=Ak(i+1)(rank[x])
Upper bound for Disjoint-sets
Summary
A typical example using Disjoint Set –�Kruskal's algorithm (Minimum Spanning Tree)
Minimum Spanning Tree -Prim’s Algorithm,
Shortest paths among all pairs—�Floyd-Warshall algorithm
Floyd-Warshall algorithm (cont.)
Floyd-Warshall algorithm (cont.)