CSE525 Lec14
Disjoint-set
Disjoint-Set data structure
Maintain a collection of disjoint-sets and support the following operations. Every set has a unique identifier - for this lecture, identifier must be a “leader” element in the set. Leader implicitly indicates a set.
{ 3 , 19 , 10 , -2 } { 12 , 5 , AB , 7 } { 43, 12, 51, Q }
Disjoint-Set using reversed trees
Complexity of …
Give a technique to generate a sequence of ops. on n elements so that Find(x) takes Ө(n) time.
Reversed-Trees + Union-by-depth
During union, join the shorter tree to the root of the deeper tree (not the other way).
Q: How to know “shorter” and “deeper” ?
Lemma: For any set A, |A| >= 2depth(A). [ ⇒ depth(A) <= log(#elements of A) ]
Proof:
Q: How are the complexities affected?
O(1)
Ө(log n)
Ө(log n)
Let x = leader of A. Induction on the size of the set with x as leader.
Shallow Reversed Trees + Threading
Complexity of …
Give a technique to generate a sequence of ops. on n elements so that Union(x) takes Ө(n) time on average.
Shallow Reversed Trees + Threading + Wtd Union
During union, join the smaller tree to the root of the larger tree (not the other way).
Q: How to know “smaller” and “larger” ?
Complexity of MakeSet? Find? WtdUnion?
Lemma: The leader/root-pointer of any element changes at most log(n) times.
Lemma: t MakeSet & s WtdUnion takes O(t + s log s) time.