๐ฎ Binary Search (Practice)
Companion to the Binary Search guide. See the search space halve each step, then write the classic loop.
๐ฌ Watch it workโ
Binary Search โ halving the search spaceStep 1 / 5
Search for 11 in a sorted array โ O(log n).
๐ Your turnโ
Loading editorโฆ
๐ง Challenge yourselfโ
- Return the insertion point for a missing target (where it would go).
- Implement
lower_bound(first index with a[i] >= target). - Why is
mid = lo + (hi-lo)//2sometimes preferred over(lo+hi)//2?
Continue the path โ Sorting Algorithms