CSC300: Quiz Answers [4/4] Previous pageContents

You can check your answer in TestUF.java.
Uncomment the correct line in getUF to return the correct type of UF.
Put the following in main:

  show(10, "9 0, 3 4, 5 8, 7 2, 2 1, 5 7, 0 3, 4 2");

Using QuickFindUF:  

       10[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 9  0:  9[0, 1, 2, 3, 4, 5, 6, 7, 8, 0]
 3  4:  8[0, 1, 2, 4, 4, 5, 6, 7, 8, 0]
 5  8:  7[0, 1, 2, 4, 4, 8, 6, 7, 8, 0]
 7  2:  6[0, 1, 2, 4, 4, 8, 6, 2, 8, 0]
 2  1:  5[0, 1, 1, 4, 4, 8, 6, 1, 8, 0]
 5  7:  4[0, 1, 1, 4, 4, 1, 6, 1, 1, 0]
 0  3:  3[4, 1, 1, 4, 4, 1, 6, 1, 1, 4]
 4  2:  2[1, 1, 1, 1, 1, 1, 6, 1, 1, 1]

Using QuickUnionUF:  
 
       10[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 9  0:  9[0, 1, 2, 3, 4, 5, 6, 7, 8, 0]
 3  4:  8[0, 1, 2, 4, 4, 5, 6, 7, 8, 0]
 5  8:  7[0, 1, 2, 4, 4, 8, 6, 7, 8, 0]
 7  2:  6[0, 1, 2, 4, 4, 8, 6, 2, 8, 0]
 2  1:  5[0, 1, 1, 4, 4, 8, 6, 2, 8, 0]
 5  7:  4[0, 1, 1, 4, 4, 8, 6, 2, 1, 0]
 0  3:  3[4, 1, 1, 4, 4, 8, 6, 2, 1, 0]
 4  2:  2[4, 1, 1, 4, 1, 8, 6, 2, 1, 0]

Using WeightedUF:

       10[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 9  0:  9[9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 3  4:  8[9, 1, 2, 3, 3, 5, 6, 7, 8, 9]
 5  8:  7[9, 1, 2, 3, 3, 5, 6, 7, 5, 9]
 7  2:  6[9, 1, 7, 3, 3, 5, 6, 7, 5, 9]
 2  1:  5[9,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