int Binarysearch(int *a, int n){
int start = a;
int end = a+n;
if((a+n) >=1){
int mid = (start+end)/2;
if(a+mid == n){
return mid;
}
if(a+mid > x){
return(Binarysearch(a,a+mid-1));
}
return (Binarysearch(a,a+mid-1));
}
return -1;
}
int Binarysearch(int *a, int n){
int start = a;
int end = a+n;
if((a+n) >=1){
int mid = (start+end)/2;
if(a+mid == n){
return mid;
}
if(a+mid > x){
return(Binarysearch(a,a+mid-1));
}
return (Binarysearch(a,a+mid-1));
}
return -1;
}
hello @JaveedYara
no the implementation needs some correcton.
int Binarysearch(int *a,int key, int start,int end){
if(start >end) // base case
return -1;
int mid = (start+end)/2;
if(a[mid] == key){
return mid;
}
if(a[mid] > key){
return Binarysearch(a,key,start,mid-1);
}
return (Binarysearch(a,key,mid+1,end));
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.