Traverse the matrix in Diagonally Bottum | Static variable for changing Row and column ; Flag variable for handling Bottum up diagonal traversing ; Recursive function to traverse the matrix Diagonally Bottom - up ; Base Condition ; Condition when to traverse Bottom Diagonal of the matrix ; Print matrix cell value ; Recursive function to traverse The matrix diagonally ; Recursive function to change diagonal ; Initialize the 5 x 5 matrix ; Function call for traversing matrix
k1 = 0 NEW_LINE k2 = 0 NEW_LINE flag = True NEW_LINE def traverseMatrixDiagonally ( m , i , j , row , col ) : NEW_LINE INDENT global k1 NEW_LINE global k2 NEW_LINE global flag NEW_LINE if ( i >= row or j >= col ) : NEW_LINE INDENT if ( flag ) : NEW_LINE INDENT a = k1 NEW_LINE k1 = k2 NEW_LINE k2 = a NEW_LINE if ( flag ) : NEW_LINE INDENT flag = False NEW_LINE DEDENT else : NEW_LINE INDENT flag = True NEW_LINE DEDENT k1 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT a = k1 NEW_LINE k1 = k2 NEW_LINE k2 = a NEW_LINE if ( flag ) : NEW_LINE INDENT flag = False NEW_LINE DEDENT else : NEW_LINE INDENT flag = True NEW_LINE DEDENT DEDENT print ( ) NEW_LINE return False NEW_LINE DEDENT print ( m [ i ] [ j ] , end = " ▁ " ) NEW_LINE if ( traverseMatrixDiagonally ( m , i + 1 , j + 1 , row , col ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( traverseMatrixDiagonally ( m , k1 , k2 , row , col ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT return True NEW_LINE DEDENT mtrx = [ [ 10 , 11 , 12 , 13 , 14 ] , [ 15 , 16 , 17 , 18 , 19 ] , [ 20 , 21 , 22 , 23 , 24 ] , [ 25 , 26 , 27 , 28 , 29 ] , [ 30 , 31 , 32 , 33 , 34 ] ] NEW_LINE traverseMatrixDiagonally ( mtrx , 0 , 0 , 5 , 5 ) NEW_LINE