Data structures · Trees and traversals

Recursion on trees

One pattern answers most questions about a tree: answer for the empty tree, then build each node's answer from its two subtrees.