0
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.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
fds
  • 1
  • 3

1 Answers1

0

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.

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
Shubham K.
  • 93
  • 1
  • 2
  • 13