📜  数据结构 |堆 |问题 12

📅  最后修改于: 2021-09-08 13:26:06             🧑  作者: Mango

元素 32, 15, 20, 30, 12, 25, 16 按照给定的顺序一个一个地插入到最大堆中。由此产生的最大堆是。

tree
(一)
(乙)
(C) c
(D) d答案:(一)
解释:

32, 15, 20, 30, 12, 25, 16 

After insertion of 32, 15 and 20
          32
        /    \
      15      20
 
After insertion of 30
          32
        /    \
      15      20
     /
    30
Max Heap property is violated, so 30 is swapped with 15
          32
        /    \
      30      20
     /
    15

After insertion of 12
          32
        /    \
      30      20
     /  \
    15  12

After insertion of 25
          32
        /    \
      30      20
     /  \     /
    15  12   25
Max Heap property is violated, so 25 is swapped with 20
          32
        /    \
      30      25
     /  \     /
    15  12   20


After insertion of 16
          32
        /    \
      30      25
     /  \     /  \
    15  12   20  16 

这个问题的测验