Tuesday, February 11, 2014

Program to find element in a sorted matrix

__author__ = 'nitin'

def find_elem_sorted_matrix(mat,M,N,elem):
    row=0
    col=N-1
    while row=0:
        if mat[row][col]==elem:
            return True
        elif mat[row][col]>elem:
            col=col-1
        else:
            row=row+1
    return False

amatrix=[[3,5,8],[6,7,10],[9,11,12]]
rows=len(amatrix)
cols=len(amatrix[0])
print find_elem_sorted_matrix(amatrix,rows,cols,8)

No comments:

My Profile

My photo
can be reached at 09916017317