Traverse the matrix in Diagonally Bottum | Java implementation to traverse the matrix in the bottom - up fashion using recursion ; 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 ; Driver Code ; Initialize the 5 x 5 matrix ; Function call for traversing matrix
class GFG { static int k1 = 0 , k2 = 0 ; static boolean flag = true ; static boolean traverseMatrixDiagonally ( int m [ ] [ ] , int i , int j , int row , int col ) { if ( i >= row j >= col ) { if ( flag ) { int a = k1 ; k1 = k2 ; k2 = a ; flag = ! flag ; k1 ++ ; } else { int a = k1 ; k1 = k2 ; k2 = a ; flag = ! flag ; } System . out . println ( ) ; return false ; } System . out . print ( m [ i ] [ j ] + " ▁ " ) ; if ( traverseMatrixDiagonally ( m , i + 1 , j + 1 , row , col ) ) { return true ; } if ( traverseMatrixDiagonally ( m , k1 , k2 , row , col ) ) { return true ; } return true ; } public static void main ( String [ ] args ) { int 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 } } ; traverseMatrixDiagonally ( mtrx , 0 , 0 , 5 , 5 ) ; } }