+1 vote
in Data Structures & Algorithms I by (88.2k points)
Given an array of element 5, 7, 9, 1, 3, 10, 8, 4. Which of the following are the correct sequences of elements after inserting all the elements in a min-heap?

(a) 1,3,4,5,7,8,9,10

(b) 1,4,3,9,8,5,7,10

(c) 1,3,4,5,8,7,9,10

(d) 1,3,7,4,8,5,9,10

My doubt stems from Binary Heap in section Heap of Data Structures & Algorithms I

The question was asked during an online exam.

1 Answer

+1 vote
by (672k points)
selected by
Best answer
The correct choice is (a) 1,3,4,5,7,8,9,10

Easy explanation - Building a min-heap the result will a sorted array so the 1, 3, 4, 5, 7, 8, 9, 10 is correct. If we change the implementation strategy 1, 4, 3, 8, 9, 5, 7, 10 is also correct. (First filling the right child rather than left child first).

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.