< Back

Post Lab 29

Heaps

For each of the following statements, draw the state of the heap after each insertion. You may draw the heap using a python list structure, or a true binary tree structure.


  1.       initial_list = [1, 2, 3, 4, 5]
          heap = MinHeap()
    
          for element in initial_list:
              heap.insert(element)
        
  2.       initial_list = [2, 1, 4, 3, 5]
          heap = MinHeap()
    
          for element in initial_list:
              heap.insert(element)
        
  3.       initial_list = [5, 2, 3, 4, 1]
          heap = MinHeap()
    
          for element in initial_list:
              heap.insert(element)
        
  4.       initial_list = [1, 2, 3, 4, 5]
          heap = MinHeap()
    
          for element in initial_list:
              heap.insert(element)
    
          secondary_list = [10, 9, 8, 7, 6]
          for element in secondary_list:
              heap.insert(element)