A matrix is said to be a null matrix if all the elements of a matrix is 0. If any one of the matrix elements is not zero then it will not be called a null matrix.
For example:
INPUT: A matrix
OUTPUT: Whether it is an upper triangular matrix or nor
PROCESS:
Step 1: [taking the input]
Read m, n [the rows and columns 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]
Step 2: [Checking and printing]
for i = 0 to m-1 repeat
for j = 0 to n-1 repeat
if a[i][j] ≠ 0 then
Set f <- 1
[End of ‘if’]
[End of ‘for’ loop]
[End of ‘for’ loop]
if f = 0 then
print "Null matrix"
else
print "Not a null Matrix"
[End of ‘if’]
Step 3: Stop.
TIME COMPLEXITY:
for (i = 0; i < m; i++)------------------ O(m)
for (j = 0; j < n; j++)------------- O(n)
{
if (a[i][j] != 0)------------------ O(c1)
f = 1;
}
if (f == 0)--------------------- O(c2)
printf("\nNull matrix");
else---------------------------- O(c3)
printf("\nNot a null Matrix");
the time complexity is O(m*n). if the number of rows and columns are same then the time complexity will be O().
Related
Contributed by