Problem Statement:
A matrix is called as skew symmetric matrix , whose transpose is negative of the original matrix.
i.e if the entry in ith row and jth column of matrix a[i][j] then the skew symmetric matrix will be -a[i][j]
Example:
Input matrix:
A[] [] = { { 0, 2, -3},
{-2, 0, 7},
{ 3, -7, 0} };
Output:
Transpose of the matrix:
A[] [] = { { 0, -2, 3},
{ 2, 0,-7},
{-3, 7, 0} };
Yes
Solution Explanation:
Solution is very simple.
First we need to find the transpose of the input matrix.
Then if the input matrix is equal to the -ve of its transpose matrix, then it is a skew symmetrical matrix.
Time Complexity: O( row * column )
Space Complexity: O( row * column )
Code Solution
#include <iostream>
#include <vector>
using namespace std;
#define row 3
#define col 3
void getTranspose(int transpose_result[row][col],
int matrix[row][col])
{
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
transpose_result[j][i] = matrix[i][j];
}
bool checkIfSkewSymmentric(int transpose_result[row][col],
int matrix[row][col])
{
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
if (matrix[i][j] != -transpose_result[i][j])
return false;
return true;
}
int main()
{
int matrix[row][col] = { { 0, 2, -3},
{-2, 0, 7},
{ 3, -7, 0} };
int transpose_result[row][col];
getTranspose(transpose_result, matrix);
if (checkIfSkewSymmentric(transpose_result, matrix))
cout<<"Matrix is a Skew Symmetric Matrix";
else
cout<<"Matrix is Not a Skew Symmetric Matrix";
return 0;
}
Output
Matrix is a Skew Symmetric Matrix