Skip to content
Interview

Interview

Binary Search Explained: 1 Million Sorted Items in at Most 20 Steps

· Binary search algorithm explained | 10 lakh items, max 20 steps

How binary search works: check the middle, drop the half that can't hold the target, repeat. Finding 55 in a sorted list of 15 takes 4 steps instead of 11, and 1 million items need at most 20. O(log n), but the list must be sorted.

Interview SheetBinary Search, explained in fullThe idea, the steps, the complexity and the code in four languages, plus the rest of the Binary Search pattern.