Ad

Checking If Inserting Values In Order Into An Initially Empty Minimum Binary Heap Is Correct

- 1 answer

Can someone tell me if I have produced the right minimum binary heap after inserting these values in order into an initially empty minimum binary heap?

[23, 41, 19, 59, 10, 15, 40]

enter image description here

Ad

Answer

Yes. That is the correct result for that input.

The heap evolves as follows:

       23
      _23
     /  
   41
      _19_
     /    \
   41      23
      _19_
     /    \
   41      23
  /
 59
      _10_
     /    \
   19      23
  /  \
 59  41
      _10_
     /    \
   19      15
  /  \    /
 59  41  23
      _10_
     /    \
   19      15
  /  \    /  \
 59  41  23  40
Ad
source: stackoverflow.com
Ad