Node by node with recursion: sums, depth, paths and search trees.
Key ideas
- A tree function is usually: base case on
None, otherwise combine the left and right results. - Every
.left/.rightis a read. Visiting each node once is O(n). - In a search tree (BST), smaller values are on the left, larger on the right: you can skip half without visiting it.
Pattern
def go(node):
if node is None:
return empty_answer
left = go(node.left)
right = go(node.right)
return combine(node.val, left, right)Finish these first:Stacks & Queues
Lessons
Each lesson explains one idea from zero and ends with a few tasks. Lessons open in order; the explanation can be read at any time.
Boss
04
Diameter
Function
The boss opens when every lesson of the topic is finished. Solve it too and the topic is complete, and the topics after it open.