GATE Computer ScienceHardGATE CS (PYQ pattern)
Keys 15, 9, 12, 4, 18, 7, 3, 10, 21, 6 are inserted one by one into an empty binary min-heap (array representation, standard sift-up). Then one delete-min is performed (last element moved to the root, then sifted down). The resulting array is:
- A. [4, 6, 7, 10, 9, 12, 15, 18, 21]
- B. [4, 6, 7, 10, 18, 12, 9, 15, 21]
- C. [4, 6, 7, 10, 9, 12, 18, 15, 21]
- D. [4, 6, 7, 10, 9, 12, 18, 21, 15]
Correct answer: C. [4, 6, 7, 10, 9, 12, 18, 15, 21]
After the insertions the heap is [3, 6, 4, 10, 9, 12, 7, 15, 21, 18]. Delete-min moves 18 to the root and sifts it down: against children 6 and 4 it swaps with 4, then against 12 and 7 it swaps with 7, leaving [4, 6, 7, 10, 9, 12, 18, 15, 21].
More Algorithms questions
- Floyd's Build-Heap performs at most height(v) exchanges while sifting down node v, so its exchanges are bounded by H = Σ height(v) over…
- A 3-ary min-heap stores 1000 keys in an array A[0..999], with the children of A[i] at 3i + 1, 3i + 2 and 3i + 3. How many of the keys are…
- Computing x¹²⁷ by multiplication, where each step multiplies two powers already computed (squarings count as multiplications), what is the…
- Euclid's algorithm gcd(a, b) repeatedly replaces (a, b) by (b, a mod b) until b = 0, counting one step per mod operation. Over all pairs 1…
- The Sieve of Eratosthenes on 2..100 crosses out the multiples of each prime p ≤ 10, starting from p² (p², p² + p, …). How many numbers are…
- The Tower of Hanoi with 6 disks is played on three pegs in a row (left, middle, right), and a disk may move only between adjacent pegs…