Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Tree Height Lab
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
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)) 1.0x