Binary search on array

sir can u explain binary search with example request h sir

hello @Aarti.com it is our duty to explain you.
see binary search is the algorihtm in whoch there is precondition that the array should be sorted only.
if it is sorted then we can change our range accordingly.
like if the array is:
1 3 5 7 9
and you want to search for the element 9 then it will be searched in the way like first it will calculate the mid of the size of the array
mid is 2 i.e 5/2=2.
array[2]=5 which is less then the value we have to find.
so we will change our range from next element of 2 to the last element from 3-5;
mid will be 4.
still the key is less and not found.
then the range will from 5 to 5
so mid will be 5
and the element will be find at 5th index.
in this way binary search works.
Happy Learning !!

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.