Function to perform the DFS Traversal
def DFS ( mat , N , M , i , j , visited ) : NEW_LINE INDENT if ( visited [ i ] [ j ] == True ) : NEW_LINE INDENT return NEW_LINE DEDENT visited [ i ] [ j ] = True NEW_LINE DEDENT