Trees

Problem shape

Beginner
8
3
10
1
6
9
14
Core idea

Height is one plus the maximum height of the left and right subtrees.

Step 1 / 5
Problem shape
Current lesson

Tree Height Lab

Trees Beginner

Tree Height

Welcome to the Tree Height algorithm lab. Height is one plus the maximum height of the left and right subtrees. Use it when: Use to reason about balance, depth, and recursive tree structure. The time complexity is O(n), and the space complexity is O(h). The pseudocode is: height(node) if node is null return 0 return 1 + max(height(node.left), height(node.right)) As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(n)

Space

O(h)

Pseudocode

height(node)
  if node is null return 0
  return 1 + max(height(node.left), height(node.right))
Open deeper structure lesson
1.0x