Embercode
✕
Binary Search TreesQuick quiz

Kth with sizes

7 questions. Covers Kth smallest with subtree sizes in Python.

Questions 1 to 5 of 7

  1. 1. On the tree built by inserting 50, 30, 70, 20, 40, 60, 80 and 35 in that order, what size does node 30 store?
  2. 2. On the same 8-value tree (50, 30, 70, 20, 40, 60, 80, 35), what does kth_largest(root, 2) return?
  3. 3. Put the steps for deleting 30 from the tree 50, 30, 70, 20, 40, 60, 80, 35 in the order the lesson's delete function runs them. Node 30 has two children.

    Use the arrows to put the steps in order.

    1. 1.Delete 35 from the right subtree, which removes the node under 40
    2. 2.Recompute each size on the way back up to the root
    3. 3.Copy 35 into the node that held 30
    4. 4.Find the successor: the smallest key in the right subtree of 30, which is 35
  4. 4. Match each name from this lesson to what it does.

    Choose the matching item for each row.

  5. 5. What does this print? It uses insert and size from this lesson. ``python root = None for key in [50, 30, 70, 20, 40, 60, 80, 35]: root = insert(root, key) root = insert(root, 45) print(root.size, root.left.size, root.left.right.size) ``

4 question(s) left on this page.