A handful of words show up in every tree problem. Pin them down now.
Left and Right are nil).The same set of values can form very different trees:
2 1
/ \ \
1 3 2
\
3
The left tree is balanced — its height is small (≈ log n) relative to the number of nodes. The right one is degenerate: every node has a single child, so it's really a linked list wearing a tree costume, height n − 1. Operations that should be O(log n) on a balanced tree degrade to O(n) on a degenerate one.
Most algorithms in this section visit every node once, so they run in O(n) time. The extra space is the recursion depth — O(h), where h is the height. That's O(log n) for a balanced tree but O(n) for a degenerate one. Keep height in mind: it governs the memory a recursive traversal uses.
Next: the two fundamental ways to visit those nodes.