Searching

Problem shape

Intermediate
4
8
15
16
23
42
Core idea

Find the first index whose value is greater than or equal to a target.

Step 1 / 5
Problem shape
Current lesson

Lower Bound Lab

Searching Intermediate

Lower Bound

Welcome to the Lower Bound algorithm lab. Find the first index whose value is greater than or equal to a target. Use it when: Use for insertion position, frequency range, and monotonic predicate problems. The time complexity is O(log n), and the space complexity is O(1). The pseudocode is: low = 0, high = n while low < high mid = (low + high) / 2 if a[mid] < target low = mid + 1 else high = mid return low As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(log n)

Space

O(1)

Pseudocode

low = 0, high = n
while low < high
  mid = (low + high) / 2
  if a[mid] < target low = mid + 1
  else high = mid
return low
Open deeper structure lesson
1.0x