recategorized by
1,569 views
1 votes
1 votes

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$
recategorized by

1 Answer

4 votes
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:

Related questions

3 votes
3 votes
2 answers
1
gatecse asked Dec 17, 2017
1,248 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 ...
3 votes
3 votes
2 answers
2
gatecse asked Dec 17, 2017
3,737 views
Which one of the following property is correct for a red-black tree?Every simple path from anode to a descendant leaf contains the same number of black nodes.If a node is...
2 votes
2 votes
2 answers
3
gatecse asked Dec 17, 2017
1,263 views
A strictly binary tree with $10$ leavescannot have more than $19$ nodeshas exactly $19$ nodeshas exactly $17$ nodeshas exactly $20$ nodes
1 votes
1 votes
1 answer
4
gatecse asked Dec 17, 2017
881 views
The minimum number of stacks needed to implement a queue is$3$$1$$2$$4$