Skip to content

BST insert & search
one step at a time.

Smaller values go left and bigger go right, so every comparison rules out a whole subtree.

Free to use. Step forward and back at your pace, and share a link to the exact step you are stuck on.

What you actually watch.

The part a dry run on paper loses: the state, at every step.

Smaller values go left and bigger go right, so every comparison rules out a whole subtree. That sentence is easy to agree with and hard to hold in your head on step nine, which is where most people lose the thread.

So the visualiser keeps it in front of you: the walk through the tree, and the order nodes come out in. The line of code being executed is highlighted as the picture changes, so the drawing and the code never drift apart. Step forward, step back, or let it play.

Put your own input in. BST insert & search on a clean example teaches you the shape; bst insert & search on an empty input, a single element, or one with duplicates teaches you the thing an interviewer asks about.

How it runs, step by step.

The same order the visualiser moves in, so the list and the picture match.

  1. 1Start at the root and go down one branch.
  2. 2Handle the node before, between or after its subtrees: that choice is the traversal.
  3. 3Come back up when a subtree is finished.
  4. 4Every node is visited once, so the walk costs O(n).

Inputs worth trying.

The cases that teach something. Each one is a preset in the tool, with the reason it is there.

  • Balanced orderRoot first, then the middles: three levels hold seven values.
  • Sorted inputEvery value goes right: the tree becomes a linked list and search checks all seven.
  • Target missingWatch where the search falls off the tree: that is where 45 would be inserted.
  • Target is the rootOne comparison.
  • Single valueA one-node tree: the search stops after one check.
  • DuplicatesThe second 20 and the second 40 are ignored.
  • Zig-zagNot sorted, yet still one node per level: a tall tree from alternating values.

What it costs.

The two numbers an interviewer will ask for, and what they mean here.

Time
O(log n) avg · O(n) worstcounted as real operations while it runs, not quoted from a table
Space
O(n)what the algorithm holds besides the input itself
Pattern
TreesEvery node is the root of a smaller problem.

Once you can see it, go and use it.

Watching is the first ten minutes. The pattern sticks when you solve with it.

Everything in the app, in one place.

Practice, interviews and the tools, all free to start. Swipe to see the rest.

Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app

About bst insert & search.

Open it in the app and the answers are easier to see than to read.

Open the visualiser
What does the bst insert & search visualiser show?

Every step of the algorithm on input you choose: the walk through the tree, and the order nodes come out in, with the line of code being executed highlighted beside it. You can step forward, step back, or let it play. Spelled visualizer or visualiser, it is the same tool.

What is the time complexity of bst insert & search?

O(log n) avg · O(n) worst time and O(n) space. The visualiser counts the real operations as it runs, so you can watch the number grow instead of taking the formula on trust.

Can I use my own input?

Yes. Type your own array, string or graph and the algorithm runs on that, including the edge cases that break a solution in an interview.

Is it free?

Yes. The app is free to start, with 100 AI credits when you sign up and 100 every month, and watching an algorithm costs no credits.