InterviewSolution
Saved Bookmarks
| 1. |
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: |
|
Answer» Initially heap has 10, 8, 5, 3, 2 10 / \ 8 5 / \3 2After insertion of 1 10 / \ 8 5 / \ /3 2 1 No need to heapify as 5 is GREATER than 1.After insertion of 7 10 / \ 8 5 / \ / \3 2 1 7Heapify 5 as 7 is greater than 5 10 / \ 8 7 / \ / \3 2 1 5No need to heapify any further as 10 isgreater than 7 |
|