Union-Find (Disjoint-Set) Quick-Practice Quiz

Q1. In a DSU that uses **path compression only** (no rank/size), what is the worst-case time to execute one `find(x)` *before* any path has been compressed?




Q2. Immediately after construction (`parent[i] = i` for all *i*), what is the **rank** of every element when you use union-by-rank?




Q3. What *always* triggers an increment to a root’s rank in union-by-rank?




Q4. Suppose two sets have sizes 4 and 9. Using **union-by-size**, which root becomes the new parent?




Q5. After a long sequence of mixed operations, the amortised cost per operation with **both** path compression *and* union-by-rank is:




Q6. You call `union(a, b)` and it returns **false**. Which statement is guaranteed true?




Q7. In an 8-element DSU with rank, the largest rank value you could possibly see *before any path compression* is:




Q8. Consider the sequence `union(1,2)`, `union(3,4)`, `union(1,4)`, `find(2)`. Using rank and full path compression, what is the **depth of node 3 immediately after the final find**?




Q9. Why does **rank never decrease**, even though path compression shortens real heights?




Q10. In a parallel algorithm you keep one DSU instance per thread and later **merge DSUs** pairwise. Which optimisation is most critical during the merge phase to avoid O(N²) work?




data-structures-and-algorithms