You are on page 1of 1

1.

We are looking for the element 4 and initially start is equal


to 0 and n is equal to n-1 .That is 8 in our example now using
the formula we will calculate the position to look for the
element and by putting the corresponding values of start
and e in the formula.We get 0+(8 -0)/(15-1)*(4-
1)=1.Therefore we now take the value of index 1 which is 2
and is not equal to 4 and as 4 is greater than 2.We will make
start equal to current position + 1.
2. Therefore start now has index 2 and there will be no change
in the value of n which would again be 8 and now we will
again calculate the value of position using our formula and
putting the corresponding value of start e in the formula.We
get 2+(8-2)/(15-4)*(4-4)=2.
3. Now we will check the value at index 2 and the value at
index 2 is equal to 4 which is the element we were looking
for so we can simply see that we found the element at index
2 .Unlike binary search we were able to find the element 4 in
two steps. This is because with binary search we were
always looking at the middle index while with interpolation
search we started looking at index which were closer to the
element we were looking for.If the events is not present in
the array we will perform interpolation search until start is
less than or equal to end and the element we are looking for
is greater than or equal to the element .

You might also like