Question: Disjoint Sets The uptrees used to represent sets in the union - find algorithm can be stored in two n - element arrays. The up
Disjoint Sets
The uptrees used to represent sets in the unionfind algorithm can be stored in two element arrays. The up array stores the parent of each node or if the node has no parent The weight array stores the number of items in a set its weight if the node is the root representative node of a set. If a node is not a root the contents of its location in the weight array are undefined we don't care what value it holds, it can be zero or any other number.
The following shows a collection of sets containing the numbers through without the weight array filled in:
a Draw a picture of the uptrees represented by the data in the up array shown above.
b Now, draw a new set of uptrees to show the results of executing:
unionfind find;
find ;
Regardless of how the trees from part a were constructed, here assume that find uses path compression and that union uses unionbysize aka union by weight In case of ties in size, always make the higher numbered root point to the lower numbered one. Unioning a set with itself does nothing.
c Update the up and weight arrays at the top of the previous page to reflect the picture after part b That is fill in the contents of the weight array and update the contents of the up array.
d What is the worst case bigO running time of a single find operation if union by size aka union by weight and path compression are used total # of elements in all sets. no explanation required
e Assuming that you are using union by size and path compression, how long would we expect a sequence of union operations and find operations to take? total # of elements in all sets Express your answer in terms of bigOno explanation required
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
