@@ -0,0 +1,1706 @@
+def binary_search(array: list, lower_bound: int, upper_bound: int, value: int) -%3E int:%0A    %22%22%22%0A    This function carries out Binary search on a 1d array and%0A    return -1 if it do not exist%0A    array: A 1d sorted array%0A    value : the value meant to be searched%0A    %3E%3E%3E matrix = %5B1, 4, 7, 11, 15%5D%0A    %3E%3E%3E binary_search(matrix, 0, len(matrix) - 1, 1)%0A    0%0A    %3E%3E%3E binary_search(matrix, 0, len(matrix) - 1, 23)%0A    -1%0A    %22%22%22%0A%0A    r = int((lower_bound + upper_bound) // 2)%0A    if array%5Br%5D == value:%0A        return r%0A    if lower_bound %3E= upper_bound:%0A        return -1%0A    if array%5Br%5D %3C value:%0A        return binary_search(array, r + 1, upper_bound, value)%0A    else:%0A        return binary_search(array, lower_bound, r - 1, value)%0A%0A%0Adef mat_bin_search(value: int, matrix: list) -%3E list:%0A    %22%22%22%0A    This function loops over a 2d matrix and calls binarySearch on%0A    the selected 1d array and returns %5B-1, -1%5D is it do not exist%0A    value : value meant to be searched%0A    matrix = a sorted 2d matrix%0A    %3E%3E%3E matrix = %5B%5B1, 4, 7, 11, 15%5D,%0A    ...           %5B2, 5, 8, 12, 19%5D,%0A    ...           %5B3, 6, 9, 16, 22%5D,%0A    ...           %5B10, 13, 14, 17, 24%5D,%0A    ...           %5B18, 21, 23, 26, 30%5D%5D%0A    %3E%3E%3E target = 1%0A    %3E%3E%3E mat_bin_search(target, matrix)%0A    %5B0, 0%5D%0A    %3E%3E%3E target = 34%0A    %3E%3E%3E mat_bin_search(target, matrix)%0A    %5B-1, -1%5D%0A    %22%22%22%0A    index = 0%0A    if matrix%5Bindex%5D%5B0%5D == value:%0A        return %5Bindex, 0%5D%0A    while index %3C len(matrix) and matrix%5Bindex%5D%5B0%5D %3C value:%0A        r = binary_search(matrix%5Bindex%5D, 0, len(matrix%5Bindex%5D) - 1, value)%0A        if r != -1:%0A            return %5Bindex, r%5D%0A        index += 1%0A    return %5B-1, -1%5D%0A%0A%0Aif __name__ == %22__main__%22:%0A    import doctest%0A%0A    doctest.testmod()%0A

Create binary_search_matrix.py (#6995)