NAMES:

LOGINS:

PRECEPT:

COS 226 Exercises on Union-Find


References: Lecture 1 and Chapter 1 in Algs3(1-4)


1. Draw the resulting tree after running the quick-find algorithm (Program 1.1) on the sequence:
0-2, 1-4, 2-5, 3-6, 0-4, 6-0, 1-3

Caution: Make sure that your tree is produced exactly as in Program 1.1, so don't interchange the roles of p and q.
















2. Draw the tree corresponding to the following id[] array. Can this be the result of running weighted quick union without path compression? Explain why this is impossible or give a sequence of operations which results in this array.

  i    0 1 2 3 4 5 6 7 8 9 
--------------------------
id[i]  0 0 1 2 4 4 5 3 1 0

Hint: Refer to Property 1.3.