AlgoLab

O(log n)·O(1) space
511181928314243454851515563647377969899

Search runs on a sorted copy of your array, because binary and jump search need sorted input. The bars are that sorted copy.

Searching a sorted array of 20 items for 51 by doubling a bound until it passes the target, then binary searching inside it.

Searching a sorted array of 20 items for 51 by doubling a bound until it passes the target, then binary searching inside it.
  1. 1check whether the target is at the very first position
  2. 2starting from a bound of 1, double the bound until its value is at least the target, or the bound runs past the end of the array
  3. 3binary search for the target within the bracket the doubling just found
  4. 4find the midpoint of the current range
  5. 5compare the value at the midpoint with the target
  6. 6the target is found
  7. 7the target is smaller, so search the left half of the range
  8. 8the target is larger, so search the right half of the range
  9. 9the target is not in the array
Comparisons
0
Writes
0
Accesses
0

Complexity

BestO(1)
AverageO(log n)
WorstO(log n)
Extra spaceO(1)
log₂ n at n=20 predicts 4; this run took 0.

Exponential search

Exponential search checks the first position, then doubles a bound — 1, 2, 4, 8, and so on — comparing the value at each new bound with the target until it finds one that is at least as large, or runs past the end of the array. That doubling finds a bracket at most twice as wide as it needs to be, and an ordinary binary search then runs inside just that bracket.

When it is the right choice

Exponential search earns its keep searching an unbounded or unindexed sequence, where finding "the end" to binary search against is itself expensive or impossible — doubling forward costs little extra over the eventual binary search, and it needs no upfront size. On an ordinary in-memory array, where the size is already known, it does the same job as binary search with a little extra bookkeeping and offers no advantage. Reframed honestly for what this tool can actually show: at a capped array size of 48, doubling from 1 needs at most six probes before it exceeds the array, so the doubling phase here is a curiosity, not the main event — the idea worth watching is the two-phase shape, bracket first, then halve.

How it works

Worth noticing

Cost

Best
O(1)
Average
O(log n)
Worst
O(log n)
Extra space
O(1)

Worth comparing

All algorithms