What should a child tell its parent?
Picture
A rooted tree lets you solve a large question by asking each child about its own subtree. The powerful decision is the summary the child returns. Height, total value, and whether a subtree is balanced are different summaries over the same structure.
Predict
One child subtree has height 3 and the other height 5. Is the parent’s height 9, 6, or something else? Count height in nodes, with an empty tree having height zero.
Reveal the reasoning
It is 1 + max(3, 5) = 6. A downward path chooses one child; it does not visit both branches. If the question asked for total nodes instead, addition would be appropriate.
Go deeper: derive the combination from the question
Represent a binary node as (value, left, right) and an empty tree as None.
def height(node):
if node is None:
return 0
_, left, right = node
return 1 + max(height(left), height(right))
tree = (8, (3, None, None), (10, None, (12, None, None)))
assert height(tree) == 3
assert height(None) == 0
The leaf 12 returns 1; node 10 receives (0, 1) and returns 2; root 8 receives (1, 2) and returns 3. This is postorder reasoning: finish child dependencies before combining at the parent.
Every node is processed once, so time is O(n) and recursion space is O(h), where h is height. A chain has h=n; a balanced binary tree has logarithmic height. “Tree” alone does not imply logarithmic algorithms.
For a diameter measured in edges, a path through a node could use both child branches, giving left_height + right_height. But the summary sent upward is still the best single downward branch. Sometimes the answer you record at a node differs from what its parent needs.
Analogy limit: a family hierarchy illustrates parent-child structure, but a general graph can have shared descendants and cycles. The assumption that child subtrees are disjoint must be checked before reusing this reasoning.
Change one rule
Find the sum along a root-to-leaf path that must equal a target. Can subtree height answer that question?
Check the variation
No. The question needs values and path context, such as the target still remaining after visiting ancestors. The structure stayed the same; the information flow changed.
Connect
Context passing sends information down. Tree DP returns multiple conditional answers upward when one number is insufficient.