Recursion
TimeO(n)SpaceO(h)
A node's depth is one plus the deeper of its two subtrees. The recursion descends to the leaves, then the call stack unwinds, computing each subtree's depth on the way back up.
Key idea. A node's depth is 1 + the deeper subtree. The call stack does the bookkeeping as recursion unwinds back up.
1
Loading…
—