Question: 1. We are given two programs A and B that use two different implementations of the union-find data structure. Program A applies path compression when

1. We are given two programs A and B that use two different implementations of the union-find data structure. Program A applies path compression when it performs each find) operation; whereas Program B does not apply path compression for its find() operations. Both programs start off with the same initial union-find data structure shown below. Note that this union-find data structure contains only one tree in its forest and element 'a' is its root. Also, note that character labels are assigned for each element which is okay as long as you work with the tree representation (and not the vector implementation) for this example. Assume that both programs perform the same sequence of find) operations in the following specified order from left to right: find(y), find(x), find(k), find(y), find(x), find(h) Calculate the number of steps each of the above find() operations takes to climb from the element being searched to the root node. For example, the number of such steps if one were to perform a find(d on the above shown initial tree will be 1 (under both programs). Give your answer by filling the number of steps for each find() operation in the table below: Program A (w/path compression) Program B (w/o path compression) 1. find(y) 2. find(x) 3.find() 4. find(y) 5. find(x) 6. find(h) Total
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
