GATE Computer ScienceHardGATE CS (PYQ pattern)
The keys 20, 15, 30, 10, 5, 25, 3, 18, 1 are inserted one by one into an initially empty min-heap (array form, each insert sifts up). How many swaps occur in total, and which key is at array index 4 (0-indexed) at the end?
- A. 13 swaps, key 15
- B. 12 swaps, key 20
- C. 12 swaps, key 15
- D. 6 swaps, key 15
Correct answer: C. 12 swaps, key 15
Sift-up after each insertion: the swap counts are accumulated step by step to 12. The final heap array is [1, 3, 5, 10, 15, 30, 25, 20, 18]; building bottom-up instead would give a different array.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A max-heap is built from [50, 30, 40, 10, 20, 35, 25, 5, 8, 15, 12] by bottom-up heapify. Two delete-max operations are then performed…
- How many different max-heaps (valid arrays) can be formed using the 10 distinct keys 1 to 10?
- A hash table of size 11 uses linear probing with h(k) = k mod 11. Keys 43, 22, 33, 54, 65, 76, 87, 14, 25 are inserted in this order (no…
- A table of size 11 uses quadratic probing h(k, i) = (k mod 11 + i^2) mod 11. Keys 23, 34, 45, 56, 67, 78, 89 (all congruent to 1 mod 11)…
- Twenty keys are hashed into a chained table with 8 slots, each key independently and uniformly. What are the expected number of colliding…
- struct node { int d; struct node n; }; struct node f(struct node p, int k) { if (p == NULL) return NULL; struct node cur = p, prev = NULL…