Jump Search, explained step by step
Jump Search checks every √n-th element of a sorted array to find the block that could contain the target, then scans that block linearly.
Intuition: Skim a book a chapter at a time, then read page by page once you overshoot.
How it works
- Pick a block size of √n.
- Jump block by block until a block end is ≥ target.
- Linearly scan inside that block.
Complexity
- Best: O(1)
- Average: O(√n)
- Worst: O(√n)
- Space: O(1)
- Stable: no
When to use it
Sorted data where jumping backwards is expensive (e.g. linked storage or tape-like media).
Interview questions
- Why is √n the optimal jump size?
- When would you choose Jump Search over Binary Search?