GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A max-heap is built from [90, 80, 70, 60, 50, 40, 30, 20, 10, 15, 25, 35, 45, 55, 65] by bottom-up heapify. Then the key at index 14 is increased to 85 and the key at index 8 (in the array after the first operation) is increased to 100, each followed by sift-up. How many swaps do the two sift-ups perform together, and what is the root afterwards?

  1. A. 5 swaps, root 100
  2. B. 6 swaps, root 100
  3. C. 5 swaps, root 90
  4. D. 4 swaps, root 100

Correct answer: A. 5 swaps, root 100

The heapified array is 90 80 70 60 50 45 65 20 10 15 25 35 40 55 30. Increasing index 14 to 85 swaps up 2 time(s); increasing index 8 to 100 swaps up 3 times to the root.

More Programming and Data Structures (GATE) questions

Exams that ask this topic