.

Binary Search Algorithm

The sequential search algorithm is very slow. In the event that we now have a list of a million elements, we must do a million comparisons within the worst case. When the list isn’t sorted, this is the only solution. When the list is sorted, however, we areable to make use of a better algorithm known as binary search. In most cases, programmers use a binary search whenever a list is large.

A binary search starts by testing the data within the element from the center of the actual list. This determines if the focus on is within the first half or even the second half of the actual list. If it's within the first half, there is no need to further check the second half. If it's within the second half, there is no need to further check the first half.

An Example of a binary search :

Example of a binary search
.