Jump Search searches a sorted array by skipping ahead in fixed-size blocks of length √n rather than inspecting every element. Once it finds a block whose upper bound is at least the target, it performs a short linear scan inside that block. It bridges the gap between Linear Search and Binary Search on sorted arrays.
step = floor(sqrt(n)), prev = 0
while arr[min(step, n) - 1] < target:
prev = step
step = step + floor(sqrt(n))
if prev >= n: return -1
while arr[prev] < target:
prev = prev + 1
if prev == min(step, n): return -1
if arr[prev] == target: return prev
return -1
Control speed:
With block size m = floor(sqrt(n)), Jump Search checks indices m − 1, 2m − 1, 3m − 1, and so on until the element at that index is greater than the target or the array ends. It then linearly scans from the previous block start prev up to the current block limit to check for an exact match.
Choosing a block size of m = √n balances the two phases: at most n/√n block jumps are needed to bracket the target, followed by at most √n linear comparisons inside the matching block. That gives Jump Search an O(√n) worst-case runtime — significantly faster than linear scanning while making strictly forward jumps during the search phase.
Jump Search is slower than Binary Search in random-access RAM. However, it is valuable on storage media or linked skip structures where jumping backward is expensive — for example, magnetic tapes, compressed forward-only streams, or large sequentially cached blocks — because the jump phase moves strictly forward and the algorithm steps backward at most once.
Metric / Operation | Complexity | Description |
|---|---|---|
| Best Case | O(1) | When the target sits at index 0 or at the end of the very first jumped block. |
| Average Case | O(√n) | Combines at most n/√n block jumps with at most √n linear comparisons inside the matching block. |
| Worst Case | O(√n) | When the target sits at the end of the final block or exceeds every element in the array. |
| Space Complexity | O(1) | Uses constant extra space for block boundaries and block size. |
With block size m, Jump Search makes at most n / m jumps and at most m - 1 linear checks. Minimizing (n / m) + m gives m = √n, yielding O(√n) total comparisons.
Jump Search moves forward sequentially and only steps backward at most once (into the target block), making it advantageous on media or data structures where jumping backward is costly.
When n is not an exact multiple of floor(sqrt(n)), the final block is smaller than step − prev. Clamping with min(step, n) prevents out-of-bounds reads, while checking prev >= n exits cleanly when the target exceeds the largest element.
to join the discussion
Hand-picked resources to deepen your understanding
© 2025 See Algorithms. Code licensed under MIT, content under CC BY-NC 4.0