Question: Consider a variation of tree based Union-Find where the Union operation is based on the size of the tree, i.e., the number of nodes in
Consider a variation of tree based Union-Find where the Union operation is based on the size of the tree, i.e., the number of nodes in the tree. When forming the union of two trees, we take the root of the subtree with smaller size and make it a child of the root with larger size. The pseudo-code for union by size is: procedure UnionBySize(, y) 1 'FindSet (z); 2 yFindSet (y); s if ('.size 2 y'.size) then 4 y.parent z'; s sizesizey size; 6 else Tparenty s size 'size+y size; 9 end Let a and y' be the roots of two t and height(T) denote the height of tree T. size denote the (a) Assume that a'size 2 V.size. Prove that UnionBySize(r,y) creates a tree T whose height is at most max(height(T), height(Ty) +1). (b) Assume that: . z'.size y'.size, and .'size heght() and 'size 22heigh) Let T be the tree created by UnionBySize(a). Using part a), prove that size(T) height(T) size(T) 2 2heightT) height (T) 3 log2(size(T)). (e) Using part b), prove that for every tree T created by a sequence of UnionBySize operations, (d) Using part e), prove that for every tree T created by a sequence of UnionBySize operations
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
