Question: 4. (a). [5 marks] Below is the textbooks code for the union algorithm on the weighted quick-union data structure for doing union-by-size. Recall entry i

 4. (a). [5 marks] Below is the textbooks code for the

4. (a). [5 marks] Below is the textbooks code for the union algorithm on the weighted quick-union data structure for doing union-by-size. Recall entry i in array idl] corresponds to the parent of vertex i and each entry in the sz[] array keeps track of the number of nodes in the tree rooted at node i, for each i from 0 to n-1. Rewrite the code to do union-by-height instead. Here, you will have an array ht[], instead of sz[], where each entry is the height of the tree rooted at node i. public void union(int p, int q)f int i find(p); int j find(q); if (i-j) return; if (sz[i]

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 Databases Questions!