AlgoLab
AlgorithmsCompare
AlgoLab
AlgorithmsCompareGitHub

© 2026 AlgoLab. Open source.

AlgorithmsSearchingJump Search
Searchingintermediatesortedblock-searchsqrt-n

Jump Search

Jump Search works on sorted arrays by jumping ahead sqrt(n) positions at a time until an element greater than the target is found, then doing a linear search backward in the previous block. The optimal jump size is sqrt(n), giving O(sqrt(n)) time complexity — better than linear but worse than binary.

Complexity

Best
O(1)
Average
O(√n)
Worst
O(√n)
Space
O(1)

Visualizer

Implementation

int jumpSearch(vector<int>& arr, int target) {
    int n = arr.size(), step = sqrt(n), prev = 0;
    while (arr[min(step,n)-1] < target) { prev = step; step += sqrt(n); if (prev >= n) return -1; }
    while (arr[prev] < target) { prev++; if (prev == min(step,n)) return -1; }
    return arr[prev] == target ? prev : -1;
}

How It Works

1.Block-Based Search

Jump Search divides the sorted array into blocks of size sqrt(n). It jumps between blocks until it finds a block that might contain the target, then linearly searches that block.

2.Optimal Jump Size

The optimal jump size minimizes total comparisons: n/m block jumps plus m linear steps. Setting n/m = m gives m = sqrt(n), for a total of 2*sqrt(n) comparisons in the worst case.

3.Comparison with Binary Search

Jump Search is O(sqrt(n)) vs Binary Search O(log n). Binary Search is always faster asymptotically, but Jump Search only moves forward — useful for media files or tape storage where backward seeks are expensive.

Related Algorithms

SearchBinary SearchSearchLinear SearchSearchInterpolation Search

Test Your Knowledge

Quiz coming soon for this algorithm.

Back to all algorithms