Logic of Interpolation Search
int Interpolation-search(int a[50],int low,int high,int s)
{
int mid;
if(low<=high)
{
mid=low+(high-low)*((s-a[low])/(a[high]-a[low]));
if(a[mid]==s)
{
return(mid);
}
else
{
if(a[mid]>s)
{
Interpolation-search(a,low,mid-1,s);
}
else
{
Interpolation-search(a,high,s);
}
}
}
return(-1);
}
No comments:
Post a Comment