AlgoViz
← Back to trail

One Box at a Time

Easy+15 XP

Why searching is even a problem: a computer can't see all the boxes at once — it opens them one by one.

No visualization loaded.

Watch

i

Press Run to begin.

When you look at a row of numbers, your eyes take it all in at once and you spot what you want instantly. A computer can't do that. It can only look inside one box at a time. That single limitation is the reason 'searching' is a real problem — and why clever methods like binary search were invented.

Wait, why can't the computer just see all the numbers at once like I do?

Your brain processes the whole picture in parallel. A computer's processor follows instructions one step at a time: 'open box 0, compare it, open box 1, compare it…' It's incredibly fast at each step, but it's still going one box at a time underneath.

If it's so fast, why do we care how many boxes it opens?

With 5 boxes, opening them all is nothing. But real programs have millions or billions of boxes. At that size, 'open every box' can take minutes, while a smart method opens only a handful. The number of boxes opened is the cost we're trying to shrink.

Is opening every box ever unavoidable?

If the boxes are in no particular order, yes — to be CERTAIN a value isn't there, you must open every box. The only way to do better is to add structure first, like sorting the boxes. That's the trade-off the whole course is built around.

What does 'opening a box' mean in real code?

It's reading one position of the array, like arr[3]. Every time the program reads a position to compare it, that's one box opened. Counting those reads is how we measure whether an algorithm is fast or slow.

Hold on — you said binary search avoids opening every box, but also that you CAN'T shortcut it. Which is true?

Both, and here's the catch that makes it click: on an UNSORTED pile you really must open every box to be sure — there's no shortcut. Binary search only works once the boxes are SORTED. Sorting is the 'extra help' that buys the shortcut: once values are in order, peeking at one box tells you which whole half to throw away. So it's not magic, it's a trade — you pay to sort first, then searching gets cheap. That's exactly why the next lesson is 'What is Sorted?'

🧠A computer opens boxes one at a time. Fewer boxes opened = faster. Every search algorithm is a strategy to open fewer boxes.
box being opened nowfound itopened, wasn't it