Embercode
✕
Binary TreesQuick quiz

Iterative traversals

8 questions. Covers Iterative postorder with one stack.

Questions 1 to 5 of 8

  1. 1. What does this print? ``cpp auto a = make(5, make(3, make(1), make(4)), make(8)); for (int x : inorder(a.get())) std::cout << x << ' '; ` inorder is the stack version from this lesson, and make` builds a node.
  2. 2. What does this print? ``cpp auto p = make(8, make(4, make(2), make(6)), make(12)); std::size_t peak = 0; preorder_with_peak(p.get(), peak); std::cout << "peak stack size: " << peak << '\n'; ` preorder_with_peak` is the version from this lesson that records the largest stack size.
  3. 3. What does this print? ``cpp auto t = make(10, make(6, make(2), make(7)), make(14, make(12), nullptr)); for (int x : postorder(t.get())) std::cout << x << ' '; ` postorder is the one-stack version with the last` pointer from the previous lesson.
  4. 4. Why does the postorder version need a last pointer, while the preorder version does not?
  5. 5. The kth_smallest function from this lesson is called on the 7-node tree with root 4 and k = 4. What does it return, and what happens to the rest of the tree?

5 question(s) left on this page.