Translate

Visit to www.mrmcse.com

10 March 2018

Write down the algorithm for recursive binary search




Algorithm for recursive binary search:

Algorithm BinSearch(a,i,lx)

{
if(l = i) then
{
if (x = a[i] then return i;
else return 0;
}

else
{
mid:=[(i+l)/2];
if (x=a[mid]) then return mid;
else if (x<a[mid]) then
return BinSearch (a,i,mid-1,x);
else return BinSearch (a,m+1,L,x);
}
}



No comments:

Post a Comment