Gallop across sorted arrays with exponential jumps (1, 2, 4, 8...), then binary search the found range. Perfect for unbounded arrays. O(log n) — fast and elegant.
// WHAT YOU'LL LEARN
Prerequisites: Binary search · Sorted arrays · Logarithms
// DEFINITION
Exponential search (also called galloping search or doubling search) finds a target in a sorted array by first jumping with exponentially increasing steps (1, 2, 4, 8, 16...) until it overshoots the target, then binary searches the small range where the target must be.
It works on sorted arrays and has O(log n) time complexity. Its superpower: it works even when you don't know the array size — perfect for unbounded or infinite arrays.
// INTERACTIVE VISUALIZER
Pick a target and press play. Watch the galloping phase jump with exponentially increasing steps, then the binary search phase narrow down the exact index.
Your friend is somewhere in a very long line of people sorted by height. You don't know how long the line is! Instead of checking person by person, you take bigger and bigger jumps — 1 step, 2 steps, 4 steps, 8 steps, 16 steps... until you jump PAST your friend. Then you go back one jump and binary searchthe small range. That's exponential search!
Press PLAY to start the search!
// ALGORITHM · STEP BY STEP
// FLOWCHART · ALGORITHM VISUALIZATION
Press PLAY to trace the algorithm through the flowchart.
// PSEUDOCODE · EXECUTION FLOW
Press PLAY to step through the algorithm line by line.
// EXPONENTIAL VS BINARY
Both are O(log n), but exponential search shines when you don't know the array size. Drag the slider to compare comparison counts.
Gallop (log n) + binary (log n) = 2·log n
Needs known size. Halve the search space.
For n=1,024, both are O(log n), but exponential search takes roughly 2× more comparisons than binary search. The real advantage: exponential search works on unbounded arrayswhere you don't know n!
// COMPLEXITY COMPARISON
| Algorithm | Time (Best) | Time (Worst) | Space | Needs Size? |
|---|---|---|---|---|
| Exponential | O(1) | O(log n) | O(1) | No ✨ |
| Binary | O(1) | O(log n) | O(1) | Yes |
// PRACTICE & ASSESS
Now that you've learned the concept, put it into practice. Solve coding problems and take quizzes to reinforce what you've learned.
// TUTORIAL QUIZZES · LEVELS 1–9
Nine progressive quizzes from Level 1 to Level 9. Each has 10 questions with a 10-minute timer. XP scales with level — L1 gives 10 XP, L9 gives 90 XP. Click a quiz to expand and begin.
// REFERENCES
// READY?
Practice 1,000+ coding problems, follow career roadmaps, and get hired.