Interpolation Search, explained step by step
Interpolation Search estimates the target’s position from its value — like opening a dictionary near "W" for "Williams" — instead of always probing the middle.
Intuition: Guess where the value should be on a ruler, then correct the guess.
How it works
- Estimate pos from where the target sits between arr[low] and arr[high].
- If arr[pos] is the target, stop.
- Otherwise narrow the range to the side that can contain the target and repeat.
Complexity
- Best: O(1)
- Average: O(log log n)
- Worst: O(n)
- Space: O(1)
- Stable: no
When to use it
Large sorted arrays whose values are roughly uniformly distributed (IDs, timestamps).
Interview questions
- What is the worst case and when does it happen?
- Why does interpolation search need uniformly distributed data?