In linear algebra, a matrix is said to be symmetric, if the square matrix is equal to its transpose. The symmetric matrix is only possible to check if it is a square matrix. Otherwise, the number of rows and columns in the original matrix will differ from the number of rows and columns in the transpose matrix.
The transpose of a matrix can be defined as a new matrix whose rows are the columns of the original matrix and the columns are the rows of the original matrix. If A is a matrix then it's transpose is denoted as .
EXAMPLE OF THE SYMMETRIC MATRIX:
Let the matrix be:
Now the transpose matrix will be:
Now, if we compare each element of matrix A with each element of matrix AT index wise, we will get that A =
Therefore, matrix A is said to be a symmetric matrix.
INPUT: A matrix A
OUTPUT: whether it is symmetric or not
PROCESS:
Step 1: [Taking the inputs]
Read m, n [The number of rows and columns of the matrix]
Step 2: [Checking for a symmetric matrix]
If m=n then
[taking the elements of the matrix]
For i=0 to m-1 repeat
For j=0 to n-1 repeat
Read a[i][j]
[End of ‘for’ loop]
[End of ‘for’ loop]
[finding the transpose of a matrix]
for i = 0 to m-1 repeat
for j = 0 to n-1 repeat
Set t[j][i]<-a[i][j]
[End of ‘for’ loop]
[End of ‘for’ loop]
[printing the transpose matrix]
Print "The transpose of the matrix is:"
For i=0 to n-1 repeat
For j=0 to m-1 repeat
Print t[i][j]
If j=m-1 then
Move to the next line
[End of ‘if’]
[End of ‘for’ loop]
[End of ‘for’ loop]
[checking if the matrix is symmetric]
For i= 0 to m-1 repeat
For j= 0 to n-1 repeat
If a[i][j] ≠ t[i][j] then
Print "The Matrix is not Symmetric"
exit
[End of ‘if’]
[End of ‘for’ loop]
[End of ‘for’ loop]
Print "The matrix is symmetric”
else
print "The matrix is not a square matrix"
[End of ‘if’]
Step 3: Stop.
TIME COMPLEXITY:
for(i= 0;i < n; i++)----------------- O(n)
{for(j= 0; j< n; j++)-------------- O(n)
{ if(a[i][j] != t[i][j]) ----------- O(c1)
{ printf("\nThe Matrix is not Symmetric\n");
exit(0);
}
}
}
Here c1 is constant, so, the time complexity is: O(n*n*c1)= O().
Related
Contributed by