Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Data Structures and Algorithms Union-Find Question 1 Give the id[] array that re

ID: 3559859 • Letter: D

Question

Data Structures and Algorithms

Union-Find

Question 1

Give the id[] array that results from the following sequence of 6 union operations on a set of 10 items using the quick-find algorithm.

    3-8   7-3   8-5   5-9   8-1 0-9

Recall: our quick-find convention for the union operation p-q is to change id[p] (and perhaps some other entries) but not id[q].

Answer for Question 1

The correct answer is: 1 1 2 1 4 1 6 1 1 1

Here is the id[] array after each union operation:
      0 1 2 3 4 5 6 7 8 9
3-8: 0 1 2 8 4 5 6 7 8 9
7-3: 0 1 2 8 4 5 6 8 8 9
8-5: 0 1 2 5 4 5 6 5 5 9
5-9: 0 1 2 9 4 9 6 9 9 9
8-1: 0 1 2 1 4 1 6 1 1 1
0-9: 1 1 2 1 4 1 6 1 1 1

============================================================================

Question 2

Give the id[] array that results from the following sequence of 9 union

operations on a set of 10 items using the weighted quick-union algorithm from lecture.

    8-5   4-9   4-2   6-3   7-1 0-3 2-5   1-0   4-3

Recall: when joining two trees of equal size, our weighted quick union convention is to

make the root of the second tree point to the root of the first tree. Also, our weighted

quick union algorithm uses union by size (number of nodes), not union by height.

Answer for Question 2

============================================================================

Question 3

Which of the following id[] array(s) could be the result of running the weighted quick union

algorithm on a set of 10 items? Check all that apply.

Ans:

Y              3 2 6 2 6 6 6 6 6 6                2-1 3-0 6-5 7-5 8-6 1-3 9-7 5-2 1-4

Y              0 1 1 3 4 0 9 7 8 9                0-5 9-6 1-2

N             4 9 9 9 3 9 9 9 3 0                The id[] array contains a cycle: 0->4->3->9->0

N             9 9 9 5 5 6 6 9 4 5               

Size of tree rooted at parent of 5 < twice the size of tree rooted at 5

N             0 9 3 5 9 5 4 9 4 3                Height of forest = 4 > lg N = lg(10)

==============================================================================

Size of tree rooted at parent of 5 < twice the size of tree rooted at 5

Explanation / Answer

2)

((((((()))))))))))))))))))))))))))))))))))

output is

the first number is p and the second number is q. q I belive is the result of the id array