Search in a row wise and column wise sorted matrix | Searches the element x in mat [ ] [ ] . If the element is found , then prints its position and returns true , otherwise prints " not ▁ found " and returns false ; Traverse through the matrix ; If the element is found ; Driver code
def search ( mat , n , x ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == x ) : NEW_LINE INDENT print ( " Element ▁ found ▁ at ▁ ( " , i , " , " , j , " ) " ) NEW_LINE return 1 NEW_LINE DEDENT DEDENT DEDENT print ( " ▁ Element ▁ not ▁ found " ) NEW_LINE return 0 NEW_LINE DEDENT mat = [ [ 10 , 20 , 30 , 40 ] , [ 15 , 25 , 35 , 45 ] , [ 27 , 29 , 37 , 48 ] , [ 32 , 33 , 39 , 50 ] ] NEW_LINE search ( mat , 4 , 29 ) NEW_LINE