matrix.binary_search_matrix

Functions

binary_search(→ int)

This function carries out Binary search on a 1d array and

mat_bin_search(→ list)

This function loops over a 2d matrix and calls binarySearch on

Module Contents

This function carries out Binary search on a 1d array and return -1 if it do not exist array: A 1d sorted array value : the value meant to be searched >>> matrix = [1, 4, 7, 11, 15] >>> binary_search(matrix, 0, len(matrix) - 1, 1) 0 >>> binary_search(matrix, 0, len(matrix) - 1, 23) -1

This function loops over a 2d matrix and calls binarySearch on the selected 1d array and returns [-1, -1] is it do not exist value : value meant to be searched matrix = a sorted 2d matrix >>> matrix = [[1, 4, 7, 11, 15], … [2, 5, 8, 12, 19], … [3, 6, 9, 16, 22], … [10, 13, 14, 17, 24], … [18, 21, 23, 26, 30]] >>> target = 1 >>> mat_bin_search(target, matrix) [0, 0] >>> target = 34 >>> mat_bin_search(target, matrix) [-1, -1]