Data Structures & AlgorithmsVery hardProduct-company MCQ pattern
A disjoint-set (union-find with union by rank and path compression) over 7 elements (0 to 6), each initially its own component, runs this sequence in order: union(2, 0), union(4, 6), union(6, 3), union(6, 4), union(3, 6), union(5, 3). How many distinct components remain?
- A. 4
- B. 3
- C. 1
- D. 2
Correct answer: B. 3
Each union merges two components only if they have different roots (a union on elements already in the same component changes nothing); tracing all 6 operations with path compression leaves 3 distinct components.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Keys 55, 65, 75 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 4, 49, 97, 15, 7, 96, 24, 50 are inserted in this order into an empty BST. Using the BST-specific LCA algorithm (walk down from the…
- Keys 38, 28, 18 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- An undirected graph has edges (u–v: weight) A–C:16, B–C:30, C–D:17, A–D:2, A–B:3, B–D:12. What is the weight of its minimum spanning tree?
- Undirected graph edges: C–D, D–B, C–B, A–C, A–B, A–D. Using a BFS 2-colouring, is this graph bipartite?
- A disjoint-set (union-find with union by rank and path compression) over 7 elements (0 to 6), each initially its own component, runs this…