2/11/98 day 10 Qoute of the day, ``Someone has to be bigger than the other.''
used by Kruskal's algorithm
Have a large array (one entry per element) which points towards a representative member of each equivalence class. Each equivalence class has some root representative member.
Union is implemented by linking the root of one tree to the root of another tree.
Improvement: (weighted union) Link the smaller tree to the larger tree to improve balance. It's necessary to keep along a 'size' field.
Recurse towards the root and return the root.
Improvement: (path compression) When you find the representative from an element, adjust every pointer in the path to point directly towards the root.
Let T, a tree. height(T)=#edge on max length path
lemma: with weighted union |T| ³ 2height(T)
proof: assume |T1| ³ 2h(T1) , |T2| ³ 2h(T2) and without loss of generality |T1| ³ |T2|
T = union(T1,T2) .
case 1: height(T) = height(T1) . Ok, because the height hasn't increased while the size has.
tcase 2: height(T) = 1+height(T2) . Ok, because 21+height(T2) = 2*2height(T2) £ 2*|T2| £ |T2|+|T1| = |T|
This is pretty fast.
Now, define the ackermann function as A(k) = Ak(2) .
Define the inverse Ackermann as: a(n) = min{k:A(k) ³ n} . This grows pretty slow.
Rank increases while a node is a root, but never increases when it is not a root.
define: 0 £ d(u) = max{k|rank(parent(u)) ³ A(rank(u)) . Then for n ³ 5 , d(n) £ a(n)
'Find' has a(n) cost because it can only be charged once for each value of d.
let x' = parent(x), v = root
If x gets rank(x) charges then d(x) increases. This means it can in incur at most rank(x)a(n) charges. This is a rather large number in comparison to a(n) but we are save by the lemma limiting the number of nodes at a particular rank.
total charges < åi = 1log(n)ra(n)([(n)/( 2r-2)]) £ na(n)åi = 1infinity[(r)/( 2r-2)] = O(na(n))
This means with m union-finds on a set of size n, the timing is O((m+n)a(n))