next up previous
Next: Up: Previous:

Linked-List Representation



Use linked list to represent set of objects.

Each object contains a pointer to the rep, the key, and a pointer to next.



Operations

Make-Set(x) $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; O(1)
$\;\;\;\;\;$rep(x) = x
$\;\;\;\;\;$next(x) = NIL



Find-Set(x) $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; O(1)
$\;\;\;\;\;$return rep(x)



Union(x, y) $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; $\Theta$(size of x)
$\;\;\;\;\;$foreach object in rep(x)
$\;\;\;\;\;$ $\;\;\;\;\;$insert object into y
$\;\;\;\;\;$ $\;\;\;\;\;$rep(object) = rep(y)
$\;\;\;\;\;$remove x


next up previous
Next: Up: Previous: