Embercode
✕
Binary Search TreesQuick quiz

BST iterator

6 questions. Covers BST iterator with a stack in Python.

Questions 1 to 5 of 6

  1. 1. The BstIterator class from this lesson is built on this tree. What does the program print? ``python it = BstIterator(build(10, 5, 15, 3, 7)) next(it) print(next(it), it.peek()) ``
  2. 2. What does this program print? ``python it = BstIterator(build(8, 4, 12, 2, 6)) n = 0 for v in it: if v > 4: n += 1 print(n, next(it, None) is None) ``
  3. 3. Why is the iterator's stack never bigger than the height of the tree?
  4. 4. After __next__ pops a node X, what does the iterator push next?
  5. 5. Insert the values 9, 8, 7, 6, 5, 4, 3, 2, 1 into a BST, one at a time in that order. Then run a full walk with BstIterator and read its max_size afterwards. What is it?

    Type a number.

5 question(s) left on this page.

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