Skip to content
StackDecode
SearchingAnimated

Jump Search

Jump ahead in blocks of √n, then scan the one block that can hold the target.

Time

O(√n)

Extra space

O(1)

Use it for

Sorted data where moving backwards is costly.

How it works

  1. On a sorted list, choose a jump size of about √n.
  2. Jump ahead block by block until the value at the end of a block is ≥ the target.
  3. The target, if present, must be inside that block.
  4. Do a linear scan inside the block.
  5. About 2√n steps in the worst case: between linear and binary search, but only moves forward.

Watch it run

Loading animation…