0
votes
for i from 1 to 60:
  MakeSet(i)
for i from 1 to 30:
  Union(i, 2*i)
for i from 1 to 20:
  Union(i, 3*i)
for i from 1 to 12:
  Union(i, 5*i)
for i from 1 to 60:
  Find(i)

Assume that the disjoint sets data structure is implemented as disjoint trees with union by rank heuristic and with path compression heuristic.

Compute the maximum height of a tree in the resulting forest.

1

1 Answers

0
votes

Answer is 1

Here is the explanation:

There is at least one tree of height 1 in the forest. Also, all trees have height at most 1, since the last for-loop calls Find() for all 60 elements. Since path compression is used, each non-root node will be attached directly to the corresponding root in this loop, and hence all the trees will have height at most 1.