A matrix is said to be a lower triangular matrix if the elements above the principal diagonal is 0. The matrix should be a square matrix.
For example:
This is an example of a lower triangular matrix as all the elements above the principal diagonal are 0.
INPUT: A matrix
OUTPUT: Whether it is a lower triangular matrix or nor
PROCESS:
Step 1: [taking the input]
Read n [order of the square matrix]
For i=0 to n-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 n-1 repeat
for j = i+1 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 "Lower triangular matrix"
else
print "Not a Lower Triangular Matrix"
[End of ‘if’]
Step 3: Stop.
TIME COMPLEXITY:
for (i = 0; i < n; i++)-------------- O(n)
for (j = i+1; j < n; j++)------ O(n-i-1)
{
if (a[i][j] != 0)------------ O(c1)
f = 1;
}
if (f == 0)----------------------- O(c2)
printf("\nLower triangular matrix");
else----------------------------- O(c3)
printf("\nNot a Lower Triangular Matrix");
c1,c2 and c3 is constant here so, the time complexity is O().
Related
Contributed by