DSA- Interpolation Search
DSA- Interpolation Search
http://www.tutorialspoint.com/data_structures_algorithms/interpolation_search_algorithm.htm
Copyright © tutorialspoint.com
Interpolation search is an improved variant of binary search. This search algorithm works on the
probing position of required value. For this algorithm to work properly the data collection should
be in sorted form and equally distributed.
Binary search has huge advantage of time complexity over linear search. Linear search has worst-
case complexity of Οn whereas binary search has Οlogn.
There are cases where the location of target data may be known in advance. For example, in case
of telephone directory, if we want to search telephone number of Morphius. Here, linear search
and even binary search will seem slow as we can directly jump to memory space where names
start from 'M' are stored.
Even when the data is sorted, binary search does not take advantage of that to probe the position
of desired data.
If match occurs then index of item is returned. To split the list into two parts we use the following
method −
where −
A = list
Lo = Lowest index of the list
Hi = Highest index of the list
A[n] = Value stored at index n in the list
If middle item is greater than item then probe position is again calculated in the sub-array to the
right of the middle item other wise item is search in sub-array to the left of the middle item. This
process continues on sub-array as well until the size of subarray reduces to zero.
Algorithm
As its an improvisation of existing BST algorithm, we are mentioning steps to search 'target' data
value index, using position probing −
Pseudocode
A → Array list
N → Size of A
X → Target Value
Procedure Interpolation_Search()
Set Lo → 0
Set Mid → -1
Set Hi → N-1
if A[Mid] = X
EXIT: Success, Target found at Mid
else
if A[Mid] < X
Set Lo to Mid+1
else if A[Mid] > X
Set Hi to Mid-1
end if
end if
End While
End Procedure