GATE Computer ScienceHardGATE CS (PYQ pattern)
The array [4, 10, 3, 5, 1, 8, 7, 2, 9, 6, 11, 12] is converted into a max-heap by Floyd's bottom-up build (sift-down from the last non-leaf to the root). What is the total number of swaps and the final value at index 5 (0-indexed)?
- A. 8 swaps, 4
- B. 10 swaps, 4
- C. 8 swaps, 10
- D. 6 swaps, 7
Correct answer: A. 8 swaps, 4
Sift down nodes at indices 5 down to 0, swapping with the larger child each time; the swaps total 8 and the final heap is [12, 11, 8, 9, 10, 4, 7, 2, 5, 6, 1, 3].
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- 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…