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-down algorithm). (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
What will be the number of passes to sort the elements using insertion sort?14, 12,16, 6, 3, 10
What will be the number of passes to sort the elements using insertion sort?14, 12,16, 6, 3, 106571
The heap data structure is the most efficient way of implementing the ..................a)Priority queueb)None of the mentionedc)Front queued)Back queue
Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?Insertion SortQuick SortHeap SortMerge Sort
In a doubly linked list, the number of pointers affected for an insertion operation will be
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.