Skip to content
Mad4Study

Engineering & Science

GATE Computer Science

  • GATE CS
  • 2026–27 pattern practice
  • Data Structures
  • Heaps
  • Medium

The max-heap [50,30,40,10,20,35,25][50, 30, 40, 10, 20, 35, 25] is stored in an array with the root at index 1. After inserting 4545 with the standard sift-up procedure, at which index does 4545 end up?

Trees

Pick an option to check your answer.

Insert 45 at the next free slot, index 8. Its parent is index 4 (value 10); 45 > 10, so swap, and 45 is at index 4. The new parent is index 2 (value 30); 45 > 30, so swap, and 45 is at index 2. The next parent is index 1 (value 50); 45 < 50, so stop. 45 ends at index 2.

Why not the others

  • 1 would need 45 to be larger than the root 50, which it is not.
  • 4 is where 45 sits after its first swap with 10, but it must still be compared with its new parent 30.
  • 8 is where 45 is first placed; it is larger than its parent 10, so it moves up.

Report an error

GATE CS · Data Structures · Trees