Welcome back, this article isn't a review on hollywood blockbuster si-fi "The Matrix", but this is all about fun with the basic math element Matrices. During your grade school you might have played around with matrices, by applying basic operations, using different formulae, proving well defined theorems etc..
But this time we will keep all those things aside and take it to a different level wherein we explore different possible way to read a matrix and try out some interesting tweaks. Let's stimulate all those lakhs of unused neurons in our brains for the first time ( and this is a true fact) .
Here is the collection of few programming problems on matrices which I found on web, books and from friends. try to solve these using minimum number of loops, use recursion and achieve the best, worst case running time.
The problems are arranged on the basis of difficulty, moving from easier ones to difficult.
1) Given a M*N matrix of integers, convert all the integers in a row or column to zero, which already has a "Zero" in the input matrix.
2) Given a M*N matrix of integers, write a program to read the matrix in a circular way, starting from inside-out.
3) Given a M*N matrix of integers, write a program to read the matrix in a zig-zag way.
Note : This way of reading the matrix is used in Run Length Coding of JPEG image compression technique.
4) Given a M*N matrix of integers having both +ve and -ve numbers, write a program to find a sub-matrix with the maximum sum
5) Given a matrix from Sudoku puzzle, write a program to check whether the given matrix is a valid Sudoku puzzle or not by without solving the puzzle. Here we assume that there could be invalid input matrices.
That's all for now. Sharpen your pencil, take a sheet of paper ... Happy coding :-)
But this time we will keep all those things aside and take it to a different level wherein we explore different possible way to read a matrix and try out some interesting tweaks. Let's stimulate all those lakhs of unused neurons in our brains for the first time ( and this is a true fact) .
Here is the collection of few programming problems on matrices which I found on web, books and from friends. try to solve these using minimum number of loops, use recursion and achieve the best, worst case running time.
The problems are arranged on the basis of difficulty, moving from easier ones to difficult.
1) Given a M*N matrix of integers, convert all the integers in a row or column to zero, which already has a "Zero" in the input matrix.
2) Given a M*N matrix of integers, write a program to read the matrix in a circular way, starting from inside-out.
3) Given a M*N matrix of integers, write a program to read the matrix in a zig-zag way.
Note : This way of reading the matrix is used in Run Length Coding of JPEG image compression technique.
4) Given a M*N matrix of integers having both +ve and -ve numbers, write a program to find a sub-matrix with the maximum sum
5) Given a matrix from Sudoku puzzle, write a program to check whether the given matrix is a valid Sudoku puzzle or not by without solving the puzzle. Here we assume that there could be invalid input matrices.
That's all for now. Sharpen your pencil, take a sheet of paper ... Happy coding :-)