Algorithms · Visualized
Jump Search
Searching Algorithms
Six search strategies on a sorted array — from the obvious linear scan to log-time binary search and beyond.
Jump Search works on sorted arrays by jumping ahead in fixed-size blocks (commonly √n) instead of checking one element at a time. Time: O(√n) average, O(√n) worst; space: O(1).
Big-O: Binary O(log n), Linear O(n), Jump O(√n), Interpolation O(log log n) avg, Exponential O(log n).
Jump Search
SearchingJump Search works on sorted arrays by jumping ahead in fixed-size blocks (commonly √n) instead of checking one element at a time. Once it finds a block where the target could be, it does a simple linear search inside just that block.
How Jump Search Works
- Decide a block/jump size, typically the square root of the array length.
- Jump forward by that block size, checking the value at each jump point, until you find a block whose last element is ≥ the target (or you reach the end).
- Once the right block is found, step back to the start of that block.
- Perform a linear search within that block to find the exact target.
- If the target isn't in the block, it's not in the array.
Jump Search Worked Example
Input: {array: [1, 4, 9, 12, 15, 19, 23, 28, 33, 41], target: 28, blockSize: 3}
Jump to index2 (9): 9<28, keep jumping. Index5 (19): 19<28, keep jumping. Index8 (33): 33≥28, stop jumping — target is in the block before index8. Linear search from index5 to index8: 19,23,28 → found 28 at index7.
import math
def jump_search(a, target):
n = len(a)
step = int(math.sqrt(n))
prev = 0
while a[min(step, n) - 1] < target:
prev = step
step += int(math.sqrt(n))
if prev >= n:
return -1
for i in range(prev, min(step, n)):
if a[i] == target:
return i
return -1Behind the Scenes Execution
Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.
Jump Search Time & Space Complexity
When to Use Jump Search
- Sorted arrays where jumping back is expensive (e.g. some storage systems), so you want fewer 'seek' operations than binary search's random-access jumps but faster than linear search.
- A middle-ground algorithm taught to illustrate block-based search strategies.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Keep the momentum going
Step through a related structure, pattern or course — the ideas reinforce each other and stick faster.