Binary Search & Search Space PruningPhase 1

Stage 1 of 5
Foundational Mental Model

Binary Search & Search Space Pruning

Why this lesson right now?Adaptive Pedagogy

You encountered memory indexing and boundary traps in recent problem attempts. This 25-minute interactive module directly targets those exact gaps before advancing to downstream tree and graph traversals.

### What is Binary Search? Binary Search finds a target in a **sorted array** in **$O(\log N)$ time** by halving the search space at each iteration.

The Golden Equation (Integer Overflow Protection): In languages like C++, Java, or Go with fixed 32-bit integers, calculating `mid` as `(low + high) / 2` can cause **arithmetic overflow** if `low + high > 2,147,483,647`. Use the robust formula: $$\text{mid} = \text{low} + \left\lfloor\frac{\text{high} - \text{low}}{2}\right\rfloor$$

Search Logic: 1. If `arr[mid] === target`: Return `mid`. 2. If `arr[mid] < target`: Target lies in right half ➔ `low = mid + 1`. 3. If `arr[mid] > target`: Target lies in left half ➔ `high = mid - 1`.

Time Complexity
O(log N)
Space Complexity
O(1) iterative | O(log N) recursive