Algorithm visualizer
Pick an algorithm, enter your own numbers or use a preset, then step through the run. The pseudocode and the explanation follow each step.
Each node's left subtree holds smaller values and its right subtree holds larger ones. Insert and search follow one path down the tree.
Precondition: Values must be distinct. Up to 9 values so the tree stays readable.
Insert the values 1, 2, 3, 4. What shape does the tree take, and how does that change the search cost?
Step 1 of 18
The tree is empty, so 8 becomes the root.