1. Jump size
Use about square root of n as the block size.
Math.floor(Math.sqrt(arr.length))Typorithm · medium
Step 1 of 8 · intro card
Search Algorithms
Jump Search skips through a sorted array by blocks, then linearly scans the one block that could contain the target.
Jump Search assumes the array is sorted.
It checks the last value of each block to skip ranges that are too small.
Once the target could be inside a block, it scans that block one item at a time.
A square-root block size balances jumping and scanning work.
Requires sorted input.
Jump by sqrt(n) sized blocks.
Use block end values to skip ranges.
Scan only the candidate block.
Time is O(sqrt n).
function jumpSearch(arr, target) {
const jump = Math.floor(Math.sqrt(arr.length));
let start = 0;
let end = jump;
while (start < arr.length && arr[Math.min(end, arr.length) - 1] < target) {
start = end;
end += jump;
}
for (let i = start; i < Math.min(end, arr.length); i++) {
if (arr[i] === target) return i;
}
return -1;
}Connect each part of the code to the concept before you type.
Use about square root of n as the block size.
Math.floor(Math.sqrt(arr.length))start marks the beginning of the current block.
let start = 0If the block's last value is still too small, the target cannot be inside it.
arr[Math.min(end, arr.length) - 1] < targetMove to the next block after skipping this one.
start = endAfter finding the possible block, scan inside it linearly.
for (let i = start; i < Math.min(end, arr.length); i++)Return the index when the target is found inside the block.
if (arr[i] === target) return iRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.
Algorithm lab · interactive
InputArray [1,3,5,7,9,11,13,15] · target 9
Follow temporary values, local state and supporting structures at this step.
Local state · indices and saved values
Around this step
Small, reproducible examples · ← → step · Space play/pause · Home/End first/last state