Skip to main content

๐ŸŽฎ 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
loโ–ผ
1
3
5
7
9
11
13
hiโ–ผ
15
Search for 11 in a sorted array โ€” O(log n).

๐Ÿ Your turnโ€‹

Loading editorโ€ฆ

๐Ÿง  Challenge yourselfโ€‹

  1. Return the insertion point for a missing target (where it would go).
  2. Implement lower_bound (first index with a[i] >= target).
  3. Why is mid = lo + (hi-lo)//2 sometimes preferred over (lo+hi)//2?

Continue the path โ†’ Sorting Algorithms