diff --git a/Sorting_Searching/matrix_in_search.py b/Sorting_Searching/matrix_in_search.py new file mode 100644 index 0000000..feffb80 --- /dev/null +++ b/Sorting_Searching/matrix_in_search.py @@ -0,0 +1,29 @@ +def search(mat, n, x): + + i = 0 + j = n - 1 + while (i < n and j >= 0): + + if (mat[i][j] == x): + + print("Element found at row: ", i, ", column: ", j) + return 1 + + if (mat[i][j] > x): + j -= 1 + + # if mat[i][j] < x + else: + i += 1 + + print("Element not found") + return 0 + +if __name__ == "__main__": + mat = [[10, 20, 30, 40], + [15, 25, 35, 45], + [27, 29, 37, 48], + [32, 33, 39, 50]] + + # Function call + search(mat, 4, 29) \ No newline at end of file