• retagged by
2,161 views
1 1 vote

A priority queue is implemented as a $Max$-$heap.$Initially, it has $5$ elements. The level order traversal of the heap is $10,8,5,3,2.$ Two new elements $1$ and $7$ are inserted into the heap in that order. The level order traversal of the heap after the insertion of the elements is

  1. $10,8,7,5,3,2,1$
  2. $10,8,7,2,3,1,5$
  3. $10,8,7,1,2,3,5$
  4. $10,8,7,3,2,1,5$

1 Answer

4 4 votes

                                                10 level 0

                                        8                        5 level1

                             3                 2                                level 2

after insertion of...

                                            

                                               10 level 0

                                        8                        5 level1

​​​​​​​                          3                     2            1                     level 2

heap property is still satisfied... then we will insert next 7

                                         

                                              10 level 0

                                        8                        5 level1

​​​​​​​                          3                     2            1                 7   level 2

here 5<7 then swap 7 & 5....

                                           

                                              10 level 0

                                        8                        7 level1

​​​​​​​                          3                     2            1                 5   level 2

  .....

now traverse...10,8,7,3,2,1,5

Answer:
Position:
Show:

Related questions

9 9 votes
2 answers 2 answers
2.6k
2.6k views
gatecse asked Dec 17, 2017
2,555 views
Match the following and choose the correct answer in the order $A, B,C$$\begin{array}{|ll|ll|} \hline \text{A.} & \text{Heap Construction} & \text{p.} & O(n\log n) \\\hli...
28 28 votes
3 3 answers
16.9k
16.9k views
admin asked Feb 15, 2023
16,927 views
Let $A$ be a priority queue for maintaining a set of elements. Suppose $A$ is implemented using a max-heap data structure. The operation $\text{EXTRACT-MAX} (A)$ extracts...
2 2 votes
2 2 answers
1.5k
1.5k views
admin asked Mar 30, 2020
1,546 views
A priority queue is implemented as a Max-Heap. Initially, it has $5$ elements. The level-order traversal of the heap is: $10,8,5,3,2$. Two new elements $1$ and $7$ are in...
3 3 votes
2 answers 2 answers
1.9k
1.9k views
gatecse asked Dec 17, 2017
1,855 views
The $in$-$order$ and $pre$-$order$ traversal of a binary tree are $\text{d b e a f c g}$ and $\text{a b d e c f g}$ respectively.The $post$-$order$ traversal of a binary ...