Recursion and Trees
73 / 170Recursion and TreesLesson 6 of 13About 44 min
The most important idea in the unit. What a node reports to its parent is not always what the answer is.
Run deepest_and_forks on the tree T(1, T(2, T(4), T(5)), T(3)). For each node give what depth returns and what forks holds immediately after that node has been handled. Nodes are visited in postorder: 4, 5, 2, 3, 1.
| node | returns | forks after |
|---|---|---|
| 4 | ||
| 5 | ||
| 2 | ||
| 3 | ||
| 1 |
Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.