5.2: Binary Search
Binary Search is an algorithm that is highly efficient when compared to Linear Search, provided that certain conditions are met. In this case, Binary Search follows the divide-and-conquer principle, which we have talked about in detail in Chapter 4.
To further understand this concept, let's take a closer look at how it works. First, Binary Search examines the middle element of a sorted list. If the target value is equal to this middle element, it means that we have successfully found our target and the search process can be terminated. However, if the target value is less than the middle element, we can assume that the target value cannot be found in the right half of the list. As a result, the search process will only continue on the left half of the list. On the other hand, if the target value is greater than the middle element, we can safely assume that the target value cannot be found in the left half of the list. Hence, the search process will only continue...