Skip to main content

Jump Search (or Block Search)

Definition​

Jump search, also known as block search, is an algorithm for searching sorted arrays efficiently. It works by jumping ahead by fixed steps to find a range where the target element might be located, then performing a linear search within that range for the exact match

Practice​

jumpSearch(arr, key):
n = arr.length
jump_size = floor(sqrt(n))
prev = 0
while n > prev and arr[min(jump_size, n) - 1] < key:
prev = jump_size
jump_size += floor(sqrt(n))
if prev >= n:
return -1
for i from prev to min(jump_size, n):
if arr[i] == key:
return i
return -1