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.![Animated sliding window over the array [2, 1, 5, 1, 3, 2]: a three-number window adds the new number and subtracts the old one, showing sums 8, 7, 9 and 6 and a maximum of 9.](https://i.ytimg.com/vi/NM5paB6_7wg/maxresdefault.jpg)
![Animated Two Sum walkthrough on the array [3, 8, 4, 6, 1] with target 10: each number asks what it needs, a dictionary stores the numbers already seen, and 6 finds 4, returning indices [2, 3].](https://i.ytimg.com/vi/Fa-tiOP33hY/maxresdefault.jpg)

