Skip to content
StackDecode
TreesAnimated

Height of Binary Tree

1 + the larger height of the two children.

Time

O(n)

Extra space

O(h)

Use it for

Basis of many tree algorithms.

How it works

  1. The height of an empty tree is 0.
  2. The height of a node is 1 plus the larger height of its two subtrees.
  3. Compute children first (post-order), then the parent. O(n).

Watch it run

Loading animation…