• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
August 21, 2024 |1.6K Views

Python Program to check Involutory Matrix

  Share  2 Likes
Description
Discussion

A matrix that if multiplied with itself results in the Identity matrix of the same order are termed an Involutory matrices. In this video, we are going to learn how can we implement a Python Program to check whether a matrix is Involutary or not. 

Mathematically this matrix can be defined as: 
M^2 = I 

We will be multiplying the same matrix with itself here as well iteratively and assigning it to the corresponding position in a new matrix. For that, we will have to use three nested loops first two loops is to address each of the indexes and the third one will get the sum of multiplication. 

The approach we are following here will need three nested loops running from 0 to n. 
Hence, the time complexity of this algorithm will be O(N^3). 

And to store the results obtained from each multiplication we are using another temp matrix to store the results for the final comparison hence we are using extra space of the same size. 
Hence space complexity of the algorithm will be O(N^2). 

Time Complexity - O(N^3) 
Space COmplexity - O(N^2) 

Finally, we just need to check if the diagonal elements are equal to one and if non-diagonal elements must be equal to zero if the above two conditions are satisfied then we can say that the matrix is involuntary. 
 

Program to check Involutory Matrix:
https://www.geeksforgeeks.org/python-program-to-check-involutory-matrix/