teacher
Sign in

Binary Search

Halve the search range each step using an invariant, so a lookup in a million sorted items takes about twenty comparisons.

35 minCF 1000–14006 interactive12 problems

The problem

You have a sorted array of 10^6 numbers and 10^6 questions of the form: where does x first appear, and how many times does it appear?

1 of 9