Searching

Jump Search

Target:
Size:14
Visualizer is loading, please wait...
Execution Narrative
Step 1 of 9Start
Line 1
Starting Jump Search for target 55. Computed optimal block jump size = floor(sqrt(14)) = 3.
Comparisons0
Operations0

Overview & Concept

Jump Search (Block Search) searches a sorted array by jumping ahead by fixed steps of size m = ⌊√n⌋ until an element greater than the target is found, then performs a linear search backward within that block. It achieves O(√n) time complexity, bridging the gap between linear and binary search.

How It Works

Optimal Block Size: Step size m = ⌊√n⌋ mathematically minimizes total jumps and linear checks.

Block Skipping: Compares A[m], A[2m], A[3m]... to target to bypass blocks of elements.

Local Linear Search: Once A[k × m] > target, linear search scans backward from index (k - 1) × m.

Step-by-Step Execution

1. Compute Step SizeSet step = Math.floor(Math.sqrt(n)), prev = 0.
2. Jump AheadWhile A[Math.min(step, n) - 1] < target, advance prev = step and step += Math.floor(Math.sqrt(n)).
3. Boundary CheckIf prev ≥ n, target does not exist; return -1.
4. Linear Search BlockIterate from prev up to Math.min(step, n) - 1; if match found, return index.

Asymptotic Complexity Analysis

MetricBest CaseAverage CaseWorst CaseSpace Complexity
Complexity BoundO(1)O(√n)O(√n)O(1)
ExplanationOptimal input arrangement minimizing operations.Expected time for uniformly distributed randomized inputs.Adversarial degenerate conditions requiring full traversal.Auxiliary memory allocated beyond original input size.

Pseudocode & Invariants

Algorithm Logic
procedure jumpSearch(A, target):
  m = floor(sqrt(n)); step = m; prev = 0
  while A[min(step, n) - 1] < target:
    prev = step; step += m
    if prev >= n: return -1
  for i = prev to min(step, n) - 1:
    if A[i] == target: return i
  return -1
Algorithmic Invariants
  • Block Invariant: Target, if present, resides within index range [prev, min(step, n) - 1].
Correctness Guarantee: Invariants hold true prior to loop entry, are preserved during every iteration, and guarantee correct post-condition upon termination.

Advantages & Disadvantages

Key Advantages

  • •O(√n) time is significantly faster than O(n) linear search.
  • •Jumps strictly backward only once: ideal for systems where backward seeking is expensive.

Trade-offs & Limitations

  • •Slower than Binary Search O(log n).
  • •Requires sorted data.

Real-World Applications

One-Way Media / Tape Drives

Searching data streams where seeking forward is cheap but seeking backward is slow.

Decision Guide: When to Use

Ideal Scenarios

  • ✓When jumping forward is substantially cheaper than jumping backward.

Consider Alternatives When

  • ✕When full random access is available (Binary Search is strictly superior).

Compare trade-offs and complexity across complementary tools in AlgoViz.