Searching Algorithms
Pick a target and watch the search hunt for it — every value it checks, every index it rules out, and the exact pseudocode line doing the work.
Linear Search
The simplest search strategy: examine each element in sequence, from the first index to the last, and stop as soon as one equals the target. It makes no assumption about ordering, so it works on any array — but in the worst case (target absent, or last in the array) it must inspect every element.
Open visualizer
O(log n) · O(1) spaceBinary Search
A divide-and-conquer search that requires a sorted array. It compares the target to the middle element of the current window: an exact match returns immediately, a smaller middle value discards the left half, and a larger one discards the right half. Halving the window every step is what gives it logarithmic time — the same shape as walking down a balanced binary search tree.
Open visualizer
O(√n) · O(1) spaceJump Search
A middle ground between linear and binary search for sorted arrays. It first jumps ahead in fixed-size blocks (optimally of size √n) until it finds a block whose last element is not smaller than the target, then falls back to a plain linear scan within that one block to pinpoint the value.
Open visualizer
O(log log n) avg, O(n) worst · O(1) spaceInterpolation Search
An improvement on binary search for sorted, numeric data. Rather than always probing the middle, it estimates where the target is likely to sit by linearly interpolating between the values at the two ends of the window — the way you'd flip straight to the 'M' section of a phone book instead of opening it in the middle. It's fastest when values are roughly uniformly distributed; on skewed data it degrades toward linear search.
Open visualizer
O(log n) · O(1) spaceExponential Search
Also called galloping search. Designed for sorted arrays (including unbounded ones) where the target is likely near the front: it doubles a bound — 1, 2, 4, 8, … — until the value there meets or passes the target, which brackets the target inside a range at most twice the distance to its true position. A regular binary search over that small bracket then finds the exact index.
Open visualizer
O(log₃ n) · O(1) spaceTernary Search
A divide-and-conquer search that splits the current window into three equal parts using two midpoints instead of one. Comparing the target against both midpoints lets it discard one third (or, if the target lies between them, two thirds) of the window each step. It still runs in logarithmic time, but needs roughly 50% more comparisons per level than binary search, so binary search remains the standard choice for plain lookups.
Open visualizer