+ 1

What is binary search?

3rd Oct 2017, 12:39 PM
Anshika Maurya
Anshika Maurya - avatar
2 Answers
+ 1
First of all it applicable only for sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful. If the search ends with the remaining half being empty, the target is not in the array.
3rd Oct 2017, 1:22 PM
Alpha Rays
Alpha Rays - avatar
Binary search is a algorithm used for searching some value in a list(array). it only works on a sorted list. How- declare two variables-upper bound, lower bound. run a loop find its mid value & target it. if you get what you want then break the loop. otherwise if number is < than what you want set lower bound = mid point (it depends on the way list is sorted here consider list sorted in ascending order).if number > than what you want set upper bound = mid point.
3rd Oct 2017, 5:01 PM
shobhit - avatar