GATE Computer ScienceVery hardGATE CSE
A disjoint-set forest over elements 1..8 starts with each element as its own root. It uses union by rank (on equal ranks, the root of the second argument becomes the child) and path compression in find. The operations union(1,2), union(3,4), union(1,3), union(5,6), union(7,8), union(5,7), union(1,5) are performed, then find(8) and find(4). What is the parent of element 8 afterwards?
- A. 7
- B. 1
- C. 5
- D. 3
Correct answer: B. 1
Union(1,2): 1 root. (3,4): 3 root. (1,3): equal rank 1, 3 under 1. (5,6): 5 root; (7,8): 7 root; (5,7): 7 under 5. (1,5): equal rank 2, 5 under 1. find(8) compresses 8 → root 1.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- On a machine where char needs 1-byte, short 2-byte and int 4-byte alignment (each member at the next offset divisible by its own size, and…
- A directed acyclic graph on vertices 1–6 has edges 1→3, 2→3, 3→4, 2→5, 4→6, 5→6 and 1→5. How many distinct topological orderings does it…
- A complete binary tree with 100 nodes (levels filled left to right, array positions 1 to 100) is given. Let X be the number of leaves and…
- int G(int n) { if (n < 3) return 1; return G(n-1) + G(n-2) + G(n-3); } Including the initial call, how many calls to G are made in total…
- int A(int m, int n) { if (m == 0) return n+1; if (n == 0) return A(m-1, 1); return A(m-1, A(m, n-1)); } Including the first call, how many…
- A min-heap is built from the array [19, 4, 17, 8, 2, 15, 9, 1, 12, 6, 3, 18, 11, 7, 14] by Floyd's bottom-up method: for i = ⌊n/2⌋−1 down…