38 38 votes Consider a max heap, represented by the array: $40, 30, 20, 10, 15, 16, 17, 8, 4$. $$\begin{array}{|l|l|}\hline \text{Array index} & \text{1} & \text{2} & \text{3} & \text{4} & \text{5} & \text{6} & \text{7} & \text{8} & \text{9} \\\hline \text{Value} & \text{40} & \text{30} & \text{20} & \text{10} &\text{15} & \text{16} & \text{17} & \text{8} & \text{4} \\\hline \end{array}$$ Now consider that a value $35$ is inserted into this heap. After insertion, the new heap is $40, 30, 20, 10, 15, 16, 17, 8, 4, 35$ $40, 35, 20, 10, 30, 16, 17, 8, 4, 15$ $40, 30, 20, 10, 35, 16, 17, 8, 4, 15$ $40, 35, 20, 10, 15, 16, 17, 8, 4, 30$ Data Structures gatecse-2015-set1 data-structures binary-heap easy + – Misbah Ghaya 11.2k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 55 55 votes Heap is complete binary tree. To insert a new element, we put it at the end of the tree and move up towards root till heap property is satisfied. Here, $35$ comes as child of $15$, with the path $40-30-15-35$. So, we swap $15, 35$ and then $30, 35$ to get the new path $40-35-30-15$. So, new heap will be $40 \ 35 \ 20 \ 10 \ 30 \ 16 \ 17 \ 8 \ 4 \ 15$. Correct Answer: $B$ Arjun answered Feb 15, 2015 • edited May 5, 2019 by Naveen Kumar 3 Arjun comment Share Follow See all 5 Comments 5 5 Comments reply Show 2 previous comments Sanjay Sharma commented Apr 9, 2021 reply Follow flag every almost complete binary tree is also complete binary tree . 0 0 replyShare Nirmalya Pratap 1 commented Sep 3, 2021 reply Follow flag Arjun sir never provide easy question solution but why here :p 1 1 replyShare Devarapalli Vamsi 13 commented Aug 6, 2024 reply Follow flag How 20 is in higher level than 30, is it okay? (I got that it is the better one from the options, but just clarifing about the property of heap) 0 0 replyShare Please log in or register to add a comment.