38 38 votes Consider a binary max-heap implemented using an array. What is the content of the array after two delete operations on $\left\{25,14,16,13,10,8,12\right\}$ $\left\{14,13,12,10, 8\right\}$ $\left\{14,12,13,8,10\right\}$ $\left\{14,13,8,12,10\right\}$ $\left\{14,13,12,8,10\right\}$ Data Structures gatecse-2009 data-structures binary-heap normal + – go_editor 14.2k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments Amjad. commented Dec 5, 2025 i edited by Amjad. Dec 5, 2025 reply Follow flag i think @jeets is taking about removing the first element from the max-heap $ \ i.e \ ( A[0] )\ $and then incrementing the first index and doing the build-heap from $A[1 \ to \ n]$then we will have to modify the code according to the index for the left and right index which will incur extra cost, which may increase the time complexity and result in different max heap tree.i might be wrong, please do correct my understanding 0 0 replyShare petals90 commented Dec 5, 2025 reply Follow flag @Amjad. I think @jeets is saying we delete the two highest elements in the array {25,14,16,13,10,8,12} i.e delete 25 and 16 and then build the max heap using the remaining array {14,13,10,8,12} which is itself a max heap but is very different from the options provided. 0 0 replyShare js__ commented Dec 5, 2025 reply Follow flag yeah , my concept was wrong , as per my concept all options would have been correct ,this image represents the correct steps 3 3 replyShare Please log in or register to add a comment.
Best answer 54 54 votes During delete, the root element is removed, replaced with the last element and heap property is corrected by pushing the root downwards. So, for first delete, $25 \ 14 \ 16 \ 13 \ 10 \ 8 \ 12 \rightarrow 12 \ 14 \ 16 \ 13 \ 10 \ 8 \rightarrow 16 \ 14 \ 12 \ 13 \ 10 \ 8$ (the element not satisfying max-heap property is exchanged with the largest of its children) (heap property satisfied) Second delete: $16 \ 14 \ 12 \ 13 \ 10 \ 8 \rightarrow 8 \ 14 \ 12 \ 13 \ 10 \rightarrow 14 \ 8 \ 12 \ 13 \ 10 \rightarrow 14 \ 13 \ 12 \ 8 \ 10$ (heap property satisfied) Correct Answer: $D$ Arjun answered Apr 29, 2016 • edited May 5, 2019 by Naveen Kumar 3 Arjun comment Share Follow See all 2 Comments 2 2 Comments reply parthiv1278 commented Jun 5, 2025 reply Follow flag Why 25 was deleted first? 0 0 replyShare manya03 commented Aug 30, 2025 reply Follow flag @parthivajith241 Because it’s a max-heap, the root i.e. 25 here is the largest element. In a delete operation, we always remove the root first and then replaces it with the last element. 1 1 replyShare Please log in or register to add a comment.
12 12 votes Answer is : [D] {14,13,12,,8,10} Desert_Warrior answered Jun 5, 2016 • edited Jan 25, 2018 by Puja Mishra Desert_Warrior comment Share Follow See 1 comment 1 1 comment reply rajarshi commented Jan 2, 2020 reply Follow flag Thnx 0 0 replyShare Please log in or register to add a comment.
11 11 votes option d abhishekmehta4u answered Mar 23, 2019 abhishekmehta4u comment Share Follow 0 reply Please log in or register to add a comment.