Question: Consider the following procedure Foo ( n ) , where the operations Make - Set ( x ) , Find - Set ( x )

Consider the following procedure Foo(n), where the operations Make-Set(x), Find-Set(x), and Union (x, y) are implemented using disjoint-set forest with union by rank as discussed in class.
Foo(n)
1 for i =1 to n
2 Make-Set(i)
3 for i =1 to n/2
4 Union(i, i + n/2)
5 for j = n downto n/2+1
6 if Find-Set(j)!= Find-Set(j -1)
7 Union(j, j -1)
Perform Foo(8).
(1) How many trees will be generated after executing the second for loop (lines 3 & 4)?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!