Implementing Disjoint Set using Linked List.
Implementation
- Each set is a linked list
make-set()make a linked listx.setis a pointer to x’s owning listfind-set(x)will follow the pointerunion(S1,S2)merges linked lists, always move smaller list into the larger one.
Amortized Analysis
- Finding
x.settakes at most times (walking up the tree) - There are set fields to update
- Total number of updates is at most
- Amortized time for operations
make-set(),find-set(),union()overall