Construct a heap for the list 2, 15, 12, 10, 6, 14, 8 by successive key insertions (top-downalgorithm). (10 p.)
Question
Construct a heap for the list 2, 15, 12, 10, 6, 14, 8 by successive key insertions (top-downalgorithm). (10 p.)
Solution
Sure, here are the steps to construct a heap for the list 2, 15, 12, 10, 6, 14, 8 using successive key insertions (top-down algorithm):
-
Start with an empty heap.
-
Insert the first element, 2. The heap is now: [2].
-
Insert the next element, 15. Since 15 is greater than 2, swap them. The heap is now: [15, 2].
-
Insert the next element, 12. Place it as a child of 2. The heap is now: [15, 2, 12].
-
Insert the next element, 10. Place it as a second child of 2. The heap is now: [15, 2, 12, 10].
-
Insert the next element, 6. Place it as a child of 12. The heap is now: [15, 2, 12, 10, 6].
-
Insert the next element, 14. Place it as a second child of 12. Since 14 is greater than 12, swap them. The heap is now: [15, 2, 14, 10, 6, 12].
-
Insert the last element, 8. Place it as a child of 10. The heap is now: [15, 2, 14, 10, 6, 12, 8].
So, the final heap after successive key insertions is: [15, 2, 14, 10, 6, 12, 8].
Similar Questions
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?*2 points1,3,4,5,7,8,9,101,4,3,9,8,5,7,101,3,4,5,8,7,9,101,3,7,4,8,5,9,10
Program to implement heap sort
A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is given below: 10, 8, 5, 3, 2 Two new elements ”1‘ and ”7‘ are inserted in the heap in that order. The level-order traversal of the heap after the insertion of the elements is:10, 8, 7, 5, 3, 2, 110, 8, 7, 5, 3, 1, 510, 8, 7, 5, 2, 1, 510, 8, 7, 3, 2, 3, 5
A priority queue is implemented as a max-heap initially, it has five elements. The level-order traversal of the heap is as follows: 20, 18, 15, 13, 12. Suppose two new elements ‘10’ and ‘17’ are inserted in the heap in that order. Find the level-order traversal of the heap after the insertion of the element.
Given an array of element 0, 5, 9, 1, 3, 10, 8, 6,11. Which of the following is the correct sequence when we pop the elements 1 by 1, after inserting all the elements in a min-heap?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.