The disjoint-set union operation first uses the disjoint-set find operation to locate the blocks of a set partition containing . If they are different blocks of a set partition , replace them by their union ; every other block of a set partition stays as it was. If the two disjoint-set representatives agree, no merge is needed. Here unite returns True exactly when it merges two different blocks of a set partition. A successful call decreases their count by one; a redundant call preserves it. The name union is also customary. Some interfaces instead accept already found disjoint-set representatives, making that linking step a separate operation.
For an original example, initialize as seven singleton sets. Apply the calls in this order:
The first five calls succeed. After the third, the partition of a set is ; after the fifth it is . The sixth returns False: are already together. The blocks of a set partition number , counting the initial state. A disjoint-set find operation on cannot merge it with any other member.
Figure 1.
Five successful disjoint-set union operations and one redundant call on seven elements
. Each coloured enclosure is one block of a set partition. Columns identify the same seven members in every row; enclosures show membership rather than parent pointers. Details.
This is exactly the kind of changing membership needed by Kruskal component merging: an accepted edge joins two current connected components of a graph, while an edge whose endpoints already have equal disjoint-set representatives is rejected. The existing Kruskal's algorithm worked example follows that application. A disjoint-set forest stores membership efficiently without repeatedly enumerating every block of a set partition.
When merging two blocks in quick-find, let and be fixed saved labels. Replacing every old occurrence of by preserves all other blocks. A scan loop invariant says processed cells already have their specified final labels while unprocessed cells still have their old labels. Recomputing during this mutation can change the replacement label after the cell for is processed, causing remaining old- cells to be missed. Saving both labels makes the update criterion stable and the invariant provable.

Articles by others on the same topic (0)

There are currently no matching articles.