AlgoLab

O(√n)·O(1) space
511181928314243454851515563647377969899

Search runs on a sorted copy of your array, because binary and jump search need sorted input. The bars are that sorted copy.

Searching a sorted array of 20 items for 51 by jumping ahead in fixed-size blocks.

Searching a sorted array of 20 items for 51 by jumping ahead in fixed-size blocks.
  1. 1set the block size to the square root of the array length
  2. 2compare the last value of the current block with the target
  3. 3if that value is smaller than the target, jump to the next block
  4. 4once a block might hold the target, step through it from its start
  5. 5the target is found
  6. 6the target is not in the array
Comparisons
0
Writes
0
Accesses
0

Complexity

BestO(1)
AverageO(√n)
WorstO(√n)
Extra spaceO(1)
√n at n=20 predicts 4; this run took 0.

Jump search

Jump search checks the last value of successive fixed-size blocks, advancing block by block until it finds one whose end is not smaller than the target, then scans that block one value at a time. It requires the array to be sorted first, and uses a block size equal to the square root of the array's length.

When it is the right choice

Jump search is a reasonable middle ground when random-access jumps (as binary search makes) are more expensive than sequential access, for instance stepping through a structure that is fast to scan forward but slow to seek within. For a plain in-memory array, binary search's O(log n) is strictly better than jump search's O(√n), so jump search is mainly of interest for what it demonstrates about trading comparisons for simplicity.

How it works

Worth noticing

Cost

Best
O(1)
Average
O(√n)
Worst
O(√n)
Extra space
O(1)

Worth comparing

All algorithms