0

Consider the program

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)

I would like to determine the height of the disjoint set.

What I understand?

MakeSet(i) creates a new set whose only member is pointed by i, and

Unique(i,j) unites two dynamic sets containing objects i and j, into a new set Si ∪ Sj

So, the first for loop will populate a set with 60 elements, then the second for loop combines the elements making the set's lenth half of 60 which is 30. but next we are using 3*i, and i ranges till 20 so doesn't it go out of range. Or did I understand it wrong?

What will be the height of the disjoint set?

Thanks in advance.

newUser
  • 3
  • 2
  • You didn't specify how the disjoint set was structure was implemented. If it uses the standard union-by-rank/size with path compression, then the final Find loop will ensure there are only 2 levels -- no paths to a root with more than 1 edge. – Matt Timmermans May 09 '20 at 01:15

1 Answers1

0

I don't know what do you mean by height, but here Union(i,j) means the set which contains the element i and the set which contains the element j will be merged. Still, the merged set contains all the elements which previously belonged to the sets containing i and j.

for i from 1 to 20:
  Union(i, 3*i)

The above code means the set which contains the element i will be merged with the set containing the element 3*i. So, it doesn't go out of range.

Finally, Find(i) will tell which set contains the element i.

Muhimin_Osim
  • 106
  • 6