pythonbinary-heap

Checking if Inserting values in order into an initially empty minimum binary heap is correct


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


Solution

  • 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