You are on page 1of 6

Interpolation Search

Group Members
Shehroz Ali 21101001-116
M.Ibrahim - 107
Malik Abdullah -067
Introduction :

The Interpolation Search is an improvement over Binary


Search for instances, where the values in a sorted array are
uniformly distributed. Interpolation constructs new data points
within the range of a discrete set of known data points. Binary
Search always goes to the middle element to check. On the
other hand, interpolation search may go to different locations
according to the value of the key being searched. For example,
if the value of the key is closer to the last element,
interpolation search is likely to start search toward the end
side.
Some Major Points :
 Interpolation search is an imporovement over bineary search.
 Binary Search always checks the value at middle index. But interpolation search may check at
different location based on the value of element being searched.
 For interpolation search to work efficiently the array elements /data should be sorted &
uniformly distributed.

Time Complexity of Interepolation Search :


O(log log n)
its Time comlexity is faster then Binary Search & linear Search ..

Time complexity O(n) .. & O(log n).. (O stands for Not).


A 1 2 4 6 7 10 11 14 15
1. Elements must be sorted & uniform
distributed.
0 1 2 3 4 5 6 7 8 2. We make start =0 & end =n-1.
pos 3. We calculate position ( pos ) to start
searching at :

start end Formula : pos =


start+{(end-strart)/(A[end]-A[start]*(e-
e=4 A[start])}
▪ if A[pos]==e , element found at index pos.
start end pos
▪ Otherwise if e < A[pos] we make start =
0 8 0+(8-0)/15-1*(4-1) pos + 1

8/14*3= 1 . ▪ Else if e < A[pos]we make end = pos -1.


p
o
s

▪ A 1 2 4 7 10 11 14 15
6
0 1 2 3 4 5 6 7 8
s
t e
r n
Found at a d
t
index 2
start end pos
2 8 2+(8-2)/(15-4)*(4-4)
2+6/11*0=2.
Implementation using c++

int interpolationSearch( int A[],int n,int e)


A --- array of elements
{
int start,end,pos;
n --number of elements start=0;
end=n-1;
while(start <= end && e >=A[start] && e =< A[end] )
e _ element searching for {
pos=start+ (((double)(end-start)/(A[end]-
A[start]))*(e-A[start]));
pos- postion to search at if(A[pos] == e)
(current postion)
return pos;

You might also like