← Back

Binary Search

Divide sorted array to locate target in log time.

searchbinary-searcharraysUpdated 2025-09-01

Precondition

  • Array must be sorted

Algorithm

  • mid = l + (r-l)/2
  • Compare & narrow half

Complexity

  • Time O(log n)
  • Space O(1)