Skip to content

Data structures and algorithms · Searching

Searching

Look at everything, or halve the problem each time. · 10 minutes

To find something in a list with no order to it, you look at each item until you find it. That is linear search, and in the worst case — the item is last, or missing — it looks at all n.

Predict first

I pick a number from 1 to 1,000,000 and answer "higher" or "lower" to your guesses. With the best strategy, how many guesses do you need at most?