Embercode
✕
Binary Search TreesQuick quiz

Sorted inputs and balanced builds

7 questions. Covers Sorted list to a height-balanced BST in Python.

Questions 1 to 5 of 7

  1. 1. This is the build function from the lesson. What does this program print? ``python a = [1, 2, 3, 4, 5, 6] r = build(a, 0, len(a) - 1) print(r.value, r.left.value, r.right.value) ``
  2. 2. The same build function gets this list. What does the program print? ``python b = [2, 4, 6, 8, 10, 12, 14, 16] r = build(b, 0, len(b) - 1) print(r.value, r.left.value, r.right.value) ``
  3. 3. Insert the values 1 to 12 into a plain BST one at a time, in increasing order. Each insert makes one comparison for every node it passes on the way down. What is the total number of comparisons for the whole build?

    Type a number.

  4. 4. The lesson's build_from_sorted is given a sorted list of 1,000 values. What is the height of the tree it makes?

    Type a number.

  5. 5. A friend says: "If I shuffle the values before inserting them into a BST, the height is always about log n, whatever the input." Which answer is correct?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.