Jump ahead √n at a time to find the right block, then scan it linearly.
A middle ground between linear and binary search for sorted data: about √n jumps plus at most √n linear steps. Useful when jumping backwards is costly.
Time: best O(1), average O(√n), worst O(√n). Space: O(1). Difficulty: Intermediate.
procedure jumpSearch(A, target):
step ← √n; prev ← 0
while A[min(step, n)−1] < target:
prev ← step; step ← step + √n
if prev ≥ n: return −1
for i ← prev to min(step, n)−1:
if A[i] = target: return i
return −1