Trees and Priority Queues

  1. You are implementing a tree and decide you want to store the depth of every node in the node itself. The only problem is that when you insert nodes in the tree, every node below the inserted node needs to change its depth. Write a function that increases the value of depth in a node and all nodes below it
  2. For the two trees, Perform a preorder and a postorder traversal. For the binary tree, also perform an inorder traversal.
    a)
    b)
  3. What is the main drawback of implementing a tree with an array?
  4. What is the output of the following code:
          pq = PriorityQueue()
          pq.insert('A', 4)
          pq.insert('B', 3)
          pq.insert('C', 5)
          print(pq.removeMin())
          pq.insert('D', 2)
          pq.insert('E', 1)
          print( pq.removeMin())
          pq.insert('F', 3)
          pq.insert('G', 6)
          print(pq.removeMin())  
          print(pq.removeMin())  
          pq.insert('H', 7)
          pq.insert('I', 0)
          print(pq.removeMin())  
          print(pq.removeMin())  
          print(pq.removeMin())  
        
  5. 15 items are inserted into a min priority queue with the following priorities: 100, 58, 95, 77, 67, 62, 35, 66, 49, 54, 42, 33, 39, 99, 15. .
    1. Draw the resultant min priority queue if it were implemented as an unsorted array.
    2. Draw the resultant min priority queue if it were implemented as a sorted array.
    3. Draw a min heap after 7 inserts.
    4. Draw the heap after all 15 inserts.
    5. Draw the heap after 8 removeMin()s