Check if a Matrix is Reverse Bitonic or Not | Python3 program to check if a matrix is Reverse Bitonic or not ; Function to check if an array is Reverse Bitonic or not ; Check for decreasing sequence ; Check for increasing sequence ; Function to check whether given matrix is bitonic or not ; Check row - wise ; Check column wise ; Generate an array consisting of elements of the current column ; Driver Code
N = 3 NEW_LINE M = 3 NEW_LINE def checkReverseBitonic ( arr , n ) : NEW_LINE INDENT f = 0 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( arr [ i ] < arr [ i - 1 ] ) : NEW_LINE INDENT continue NEW_LINE DEDENT if ( arr [ i ] == arr [ i - 1 ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT f = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if ( i == n ) : NEW_LINE INDENT return True NEW_LINE DEDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( arr [ j ] > arr [ j - 1 ] ) : NEW_LINE INDENT continue NEW_LINE DEDENT if ( arr [ i ] == arr [ i - 1 ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT if ( f == 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT def check ( arr ) : NEW_LINE INDENT f = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( not checkReverseBitonic ( arr [ i ] , M ) ) : NEW_LINE INDENT print ( " No " ) NEW_LINE return NEW_LINE DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT temp = [ 0 ] * N NEW_LINE for j in range ( N ) : NEW_LINE INDENT temp [ j ] = arr [ j ] [ i ] NEW_LINE DEDENT if ( not checkReverseBitonic ( temp , N ) ) : NEW_LINE INDENT print ( " No " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " Yes " ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT m = [ [ 2 , 3 , 4 ] , [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] NEW_LINE check ( m ) NEW_LINE DEDENT