In this we are going to see a basic program to Search in a Row-wise and Column-wise Sorted Matrix in Python Programming Language.
column-wise sorted matrix
def search(mat, n, x):
if (n == 0):
return -1
for i in range(n):
for j in range(n):
if mat[i][j] == x:
print("Element found at (",i+1,j+1, ")")
return 1
print(" Element not found")
return 0
mat = [[10, 20, 30, 40], [15, 25, 35, 45], [27, 29, 37, 48], [32, 33, 39, 50]]
ele = int(input("Enter element to search: "))
search(mat, 4, ele)
#Coded by Saahil
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP