# Jump search

In computer science, a **jump search** or **block search** refers to a search algorithm for ordered lists. It works by first checking all items *L*_{km}, where and *m* is the block size, until an item is found that is larger than the search key. To find the exact position of the search key in the list a linear search is performed on the sublist *L*_{[(k-1)m, km]}.

The optimal value of *m* is √*n*, where *n* is the length of the list *L*. Because both steps of the algorithm look at, at most, √*n* items the algorithm runs in O(√*n*) time. This is better than a linear search, but worse than a binary search. The advantage over the latter is that a jump search only needs to jump backwards once, while a binary can jump backwards up to log *n* times. This can be important if a jumping backwards takes significantly more time than jumping forward.

The algorithm can be modified by performing multiple levels of jump search on the sublists, before finally performing the linear search. For an *k*-level jump search the optimum block size *m*_{l} for the *l*^{th} level (counting from 1) is *n*^{(k-l)/k}. The modified algorithm will perform *k* backward jumps and runs in O(*kn*^{1/(k+1)}) time.

## Implementation

AlgorithmJumpSeach Input: An ordered listL, its lengthnand a search keys. Output: The position ofsinL, ornothingifsis not inL.a← 0b← ⌊√n⌋whileL_{min(b,n)-1}<sdoa←bb←b+ ⌊√n⌋ifa≥nthenreturnnothingwhileL_{a}<sdoa←a+ 1ifa= min(b,n)returnnothingifL_{a}=sthenreturnaelsereturnnothing

## See also

- Jump list
- Interpolation search
- Linear search - runs in O(
*n*) time, only looks forward - Binary search - runs in O(log
*n*) time, looks both forward and backward

## References

- Paul E. Black, jump search at the NIST Dictionary of Algorithms and Data Structures.
- Ben Shneiderman,
*Jump Searching: A Fast Sequential Search Technique*, CACM, 21(10):831-834, October 1978.