10 cards · Example

Binary Search & Divide-and-Conquer Algorithms

Master interval halving mechanics, logarithmic recurrence relations, pointer boundaries, and real-world systems applications.

Add Card

0/500
0/500
Cards (10)
#1
Term
What is the mandatory precondition for applying binary search?
Definition
The input sequence must be monotonically ordered (sorted in ascending or descending order). Without order, comparing against the midpoint provides zero information about which half contains the target.
#2
Term
How is the midpoint computed to avoid 32-bit integer overflow?
Definition
Evaluating (low + high) / 2 risks integer overflow when low + high > 2^{31} - 1 in fixed-width integer environments (e.g. C++, Java).
#3
Term
What is the asymptotic time complexity of binary search?
Definition
  • Best Case: (target located at initial midpoint)
  • Average Case:
  • Worst Case: (target at extreme ends or absent entirely)
Recurrence relation: .
#4
Term
What are the pointer adjustment rules in canonical binary search?
Definition
While low <= high:
  • If arr[mid] < target: search upper half by setting low = mid + 1
  • If arr[mid] > target: search lower half by setting high = mid - 1
  • If arr[mid] === target: return index mid
  • If low > high: target is not present (return -1)
#5
Term
What is the worst-case number of comparisons for an array of 1,024 elements?
Definition
11 comparisons.
Since , binary search divides the search space in half at each iteration: comparisons.
#6
Term
What is the auxiliary space complexity of iterative vs recursive binary search?
Definition
  • Iterative Binary Search: auxiliary space (stores only pointers low, high, mid).
  • Recursive Binary Search: auxiliary space due to call-stack frames.
#7
Term
How does lower_bound search handle duplicate elements?
Definition
When arr[mid] >= target, it updates high = mid (or high = mid - 1) rather than halting, continuing to explore the left sub-array to guarantee finding the first occurrence of the target.
#8
Term
How does binary search performance compare to linear search on 1,000,000 items?
Definition
  • Linear Search (): Up to 1,000,000 element comparisons.
  • Binary Search (): At most comparisons.
Binary search is ~50,000× faster at this scale.
#9
Term
Name three critical systems engineering applications of binary search.
Definition
1. Database B-Trees: Navigating keys within internal nodes.
2. Git Bisect: Pinpointing the regression-introducing commit in repository checkouts.
3. Network Routing: Longest-prefix matching on sorted IP ranges.
#10
Term
What is the termination condition when the target is absent from the array?
Definition
The loop terminates when low > high, indicating the active search interval has shrunk to zero elements.