def binary_search(numbers, number):
    """Binary search

    Locates the number in the list of sorted numbers. Looks at the middle element, and proceeds recursively to the left
    or to the right, depending on whether the number was smaller or bigger, respectively

    Returns the position of the found number, or the position at which the number should be inserted to preserve order

    Time complexity T(n) = O(log n)
    Space complexity S(n) = O(log n)
    """
    def bin_search(a, b):
        """a and b are inclusive indices"""
        if a == b:
            return a if number <= numbers[a] else a + 1
        middle = (a + b) // 2
        if number <= numbers[middle]:
            return bin_search(a, middle)
        else:
            return bin_search(middle + 1, b)

    return bin_search(0, len(numbers) - 1)