Exercise 9 Name __________________
Score __/ 19
Document last modified:
for i ¬ 1 to 8 do MAKE-SET(xi)
produces the data structure p where every xi is the only member and the representative of the set; and the data structure c, the number of elements in the set i:
i 1 2 3 4 5 6 7 8 p[i]|c[i] 1|1 2|1 3|1 4|1 5|1 6|1 7|1 8|1
| i | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| Line 1 p[i] | ||||||||
| Line 2 p[i] | ||||||||
| Line 3 p[i] | ||||||||
| Line 4 p[i] | ||||||||
| Line 5 p[i] | ||||||||
| Line 6 p[i] |
Line 5 answer:
Line 6 answer:
|
FIND-SET (x)
if p[ x ] ¹ x then return FIND-SET ( p[ x ] )
return x
UNION (x, y)
a ¬ FIND-SET (x)
b ¬ FIND-SET (y)
p[ a ] ¬ b
|
|
|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| p | ||||||
| d |