<bos><start_of_turn>system
You are a helpful AI assistant.
lista de codigos linguisticos disponibles: ["en", "en"].<end_of_turn>
<start_of_turn>user
Explain the binary search algorithm briefly.<end_of_turn>
<start_of_turn>model
The classic example of this algorithm is to search for a value in an ordered list. Instead of reviewing each element in the list, we can choose the middle element and compare it with the value we want to search for, if it is greater than said value then we discard the right half of the list, and if it is less then we discard the left half of the list. the list, and we continue repeating this process until the list we search has only one element.

Since this algorithm halves the number of candidates in each iteration, its time complexity is O(log n) where n is the initial length of the list. An example of an implementation would be this:

```Python
def binary_search(list: list, value: int):
    left = 0
    right = len(arr)
    while left < right:
        mid = (left + right) // 2
        if list[mid] < value:
            left = mid + 1
        else:
            right = middle
    if list[left] == ​​value:
        return True
    return False
```<end_of_turn><eos>