Skip to content

Binary search
one step at a time.

Check the middle of what is left and throw away the half that cannot hold the answer.

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.

Check the middle of what is left and throw away the half that cannot hold the answer. 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 search space halving, and the half thrown away greyed out. 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. Binary search on a clean example teaches you the shape; binary 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. 1Keep the answer inside a range, lo to hi.
  2. 2Look at the middle of what is left.
  3. 3Decide which half cannot hold the answer and throw it away.
  4. 4Repeat on the half that remains until the range holds one value.

Where people get this one wrong.

These are not made up. Each one is a switch in the tool: turn it on, run the same input, and watch the state go wrong.

  • Linear scanChecks every number from the left: n checks in the worst case instead of about log₂ n.
  • Bug: while (lo < hi)Stops one step early, so the last candidate is never checked. Try a target at either end of the array.
  • Bug: lo = midForgets that mid was already checked. When two numbers are left, lo never moves and the loop never ends.

Inputs worth trying.

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

  • Not in the arrayWatch where lo ends up.
  • Target is the last numberRun the lo < hi bug on this one.
  • DuplicatesIt finds a 3, not necessarily the first one.
  • Two numbers leftRun the lo = mid bug on this one.

What it costs.

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

Time
O(log n)counted as real operations while it runs, not quoted from a table
Space
O(1)what the algorithm holds besides the input itself
Pattern
Binary searchHalve the search space with every check.

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 binary search.

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

Open the visualiser
What does the binary search visualiser show?

Every step of the algorithm on input you choose: the search space halving, and the half thrown away greyed out, 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 binary search?

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

Why does my binary search code fail on some inputs?

Usually one of the known traps. The visualiser ships the real ones for this algorithm (while (lo < hi), lo = mid), so you can switch the bug on, run it, and watch exactly where the state goes wrong.

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.