i was unable to make a recursive function for binary search please provide a solution with explanantion for it.
Binary search using recursion
To make binary search recursion you have to do it like this:
suppose:
F(): it’s your function that returns the value
Start: Start point of an array
End: End point of an array
Mid: Mid point of an array
Target: Target value of an array to be find
int F(Array, Start, Mid, End, Target){
if(Start>=End){
`return -1;`
}
if(Array[mid]==target){
` return mid;`
}
if(Array[mid]>target){
`F(Array, Start, (Mid-1+start)/2 , Mid-1, Target);`
}
else{
` F(Array, Mid+1, (Mid+1+end)/2 , end, Target);`
}
}
This is the pseudo code that will be helpful for you
start> int this what do u mean by > in thr pseudo code
i can’t understand what are you saying ?
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.