Given two matrices A and B. The task is to multiply matrix A and matrix B recursively. If matrix A and matrix B are not multiplicative compatible, then generate output “Not Possible”.
Input: A = 12 56 45 78 B = 2 6 5 8 Output: 304 520 480 894 Input: A = 1 2 3 4 5 6 7 8 9 B = 1 2 3 4 5 6 7 8 9 Output: 30 36 42 66 81 96 102 126 150
It is recommended to first refer Iterative Matrix Multiplication.
First check if multiplication between matrices is possible or not. For this, check if number of columns of first matrix is equal to number of rows of second matrix or not. If both are equal than proceed further otherwise generate output “Not Possible”.
In Recursive Matrix Multiplication, we implement three loops of Iteration through recursive calls. The inner most Recursive call of multiplyMatrix() is to iterate k (col1 or row2). The second recursive call of multiplyMatrix() is to change the columns and the outermost recursive call is to change rows.
Below is Recursive Matrix Multiplication code.
30 36 42 66 81 96 102 126 150
This article is contributed by Anuj Chauhan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Divide and Conquer | Set 5 (Strassen's Matrix Multiplication)
- Multiplication of Matrix using threads
- Program for scalar multiplication of a matrix
- Strassen’s Matrix Multiplication Algorithm | Implementation
- Matrix Chain Multiplication (A O(N^2) Solution)
- Printing brackets in Matrix Chain Multiplication Problem
- Matrix Chain Multiplication | DP-8
- Multiplication of two Matrices in Single line using Numpy in Python
- Maximize sum of N X N upper left sub-matrix from given 2N X 2N matrix
- Circular Matrix (Construct a matrix with numbers 1 to m*n in spiral way)
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Count frequency of k in a matrix of size n where matrix(i, j) = i+j
- Program to check diagonal matrix and scalar matrix
- Check if it is possible to make the given matrix increasing matrix or not
- Program to check if a matrix is Binary matrix or not
- Program to convert given Matrix to a Diagonal Matrix
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Maximum trace possible for any sub-matrix of the given matrix
- Minimum number of steps to convert a given matrix into Upper Hessenberg matrix
- Minimum steps required to convert the matrix into lower hessenberg matrix