Posted by Elliott Nash |
Filed under binary search, binary search algorithm, perform binary search, .net binary search
Binary Search Algorithm
The principle of a binary search can be generalized to any type of problem provided the elements of the search can form a sorted list or sequence and it is possible to make a comparison on the order in the sequence.
Playing the number game: Say we have a number range from 0 to 100, and now you have to pick the number I’m thinking of and depending on your guess ill answer with either “correct”, “higher” or “lower”. What number would you choose? The binary search provides the quickest solution to this problem; the number you should choose is 50.
The binary search algorithm is one of the most efficient methods for locating the position of an element in a sorted list. The way it functions is by going straight to the middle of the list and checking whether the value is greater than, less than or equal to the element it's looking for. If equal to, then the element has been found, if not, then the algorithm eliminates half the list from consideration, and repeats the procedure on the remaining half. Thus, the number of elements needing to be checked is halved each time.More...
853a6de8-458e-41ed-8fff-2a6131faa7ca|0|.0