See Algorithms
SEE ALGORITHMS

Jump Search Visualization

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.


Pseudocode

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

Visualizer


Jump probeCandidate blockCheckingEliminatedFound

Control speed:


How It Works

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.

When to Use

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.

Time & Space Complexity

Metric / Operation
Complexity
Description
Best CaseO(1)When the target sits at index 0 or at the end of the very first jumped block.
Average CaseO(√n)Combines at most n/√n block jumps with at most √n linear comparisons inside the matching block.
Worst CaseO(√n)When the target sits at the end of the final block or exceeds every element in the array.
Space ComplexityO(1)Uses constant extra space for block boundaries and block size.

Common Interview Questions

Why is sqrt(n) the optimal block size for Jump Search?

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.

When might Jump Search be chosen instead of Binary Search?

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.

Why does Jump Search probe min(step, n) - 1 and check prev >= n during the jump phase?

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.


💬  Discussion

to join the discussion


Curious to Learn More?

Hand-picked resources to deepen your understanding


Learn DSA on Udemy
Learn DSA on Udemy
As an Udemy Associate, I earn from qualifying purchases.

© 2025 See Algorithms. Code licensed under MIT, content under CC BY-NC 4.0