Tree algorithms, step by step

37 interview patterns, each animated next to its C++ code. Press Space to play or pause, and ← → to step.

Sample tree in level order:

C++

          
Snippets assume struct Node { int val; Node *left = nullptr, *right = nullptr; Node(int v) : val(v) {} };