Consider a max heap, represented by the array: .
Now consider that a value 35 is inserted into this heap. After insertion, the new heap is
GATE CSE 2015Data Structures › Heaps & Priority QueuesVerified
(B) 40 , 35 , 20 , 10 , 30 , 16 , 17 , 8 , 4 , 15 40, 35, 20, 10, 30, 16, 17, 8, 4, 15 40 , 35 , 20 , 10 , 30 , 16 , 17 , 8 , 4 , 15
Insert 35 at the next free position (index 10) and perform the standard max-heap insert operation: repeatedly compare it with its parent and swap upward while it is larger than the parent.
Inserting a value into a max-heap requires appending it and then sifting it upward until the parent is at least as large. The value 35 rises from index 10 through index 5 to index 2, producing the array in option B.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.