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](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f466f587a0f_17366f466f51e21f.jpg)
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
Get step-by-step solutions from verified subject matter experts
