Embercode
✕
Binary Search TreesQuick quiz

Sorted inputs and balanced builds

7 questions. Covers Sorted array to a height-balanced BST.

Questions 1 to 5 of 7

  1. 1. Using the Node struct and build from this lesson, and a preorder function that prints each key, then walks the left subtree, then the right subtree, what does this code print? ``cpp vector<int> a = {1, 2, 3, 4, 5}; auto root = build(a, 0, static_cast<int>(a.size())); preorder(root.get()); ``
  2. 2. The Node struct, build and height from this lesson are used by this code. What does it print? ``cpp vector<int> b = {1, 2, 3, 4, 5, 6}; auto root = build(b, 0, 6); cout << "root " << root->key << ", height " << height(root.get()) << '\n'; ``
  3. 3. A plain binary search tree, with no rebuilding, gets the keys 1 to n inserted one at a time, in that order. How does the total number of comparisons for all n inserts grow as n gets larger?
  4. 4. A plain binary search tree gets the keys 1 to 20 inserted one at a time, in that order, with no rebuilding. What is the total number of comparisons made by all 20 inserts?

    Type a number.

  5. 5. True or false: a balanced build from the sorted keys 1 to 1000 gives a tree of height 10.

5 question(s) left on this page.

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