Prove that this algorithm is correct

43 Views Asked by At

I don't get how this works. Could you please prove this? Thanks.

def binary_search(array) -> int:
    def condition(value) -> bool:
        pass

    left, right = min(search_space), max(search_space) # could be [0, n], [1, n] etc. Depends on problem
    while left < right:
        mid = left + (right - left) // 2
        if condition(mid):
            right = mid
        else:
            left = mid + 1
    return left
1

There are 1 best solutions below

0
Olivolja On

I believe you would benefit from reading/watching a video on BinarySearch https://www.youtube.com/watch?v=P3YID7liBug.