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
- The height of an empty tree is 0.
- The height of a node is 1 plus the larger height of its two subtrees.
- Compute children first (post-order), then the parent. O(n).
Watch it run
Loading animation…