Disjoint Set / Union-Find Flashcards
(46 cards)
What is a disjoint set?
A collection of sets where no element appears in more than one set.
What is the union-find data structure?
A data structure that tracks a partition of elements into disjoint sets.
What are the main operations of disjoint set?
Find and Union.
What does the find operation do?
Determines the representative (or root) of the set containing an element.
What does the union operation do?
Merges two disjoint sets into a single set.
What is path compression?
An optimization that flattens the structure of the tree to speed up future find operations.
What is union by rank?
An optimization that attaches the shorter tree under the root of the taller tree.
What is the time complexity of find and union with optimizations?
Nearly O(1), specifically O(α(n)), where α is the inverse Ackermann function.
What is the inverse Ackermann function?
A very slowly growing function used in the analysis of disjoint set operations.
What is a representative element in a disjoint set?
The element used to identify the set, usually the root of the tree.
How is a disjoint set represented?
As a forest of trees using parent pointers.
What is the parent array in union-find?
An array where each index points to its parent, used to represent sets.
What is the rank array used for?
To keep track of the height or depth of trees in union-find.
What is the initial value of each element in the parent array?
Each element is initially its own parent.
What is the use of union-find in Kruskal’s algorithm?
To detect cycles while building a minimum spanning tree.
How do you check if two elements are in the same set?
Compare their roots using the find operation.
What is the space complexity of disjoint set with n elements?
O(n)
How is path compression implemented?
By making each node on the path point directly to the root.
What is union by size?
An optimization where the smaller set is attached to the larger one.
Which is better: union by rank or union by size?
Both are efficient; union by rank is more commonly used.
Can union-find be used in dynamic connectivity problems?
Yes, to maintain and query components efficiently.
What is a real-world use case of disjoint sets?
Tracking connected components in a network.
What is the role of union-find in maze generation?
To ensure that adding a passage does not create a cycle.
What is the role of disjoint sets in clustering?
To group similar data points during algorithms like k-clustering.