In the lower triangular matrix, the elements that are present above the diagonal should be 0. Given a matrix and the task is to check the matrix is in lower triangular form or not. A matrix must be a square matrix. A square matrix is called lower triangular if all the entries above the main diagonal are zero.
Input: 1 0 0 1 2 0 1 2 3 Output: Matrix is lower triangular matrix Input: 1 2 2 2 1 1 2 2 2 Output: Matrix is not a lower triangular matrix
- Check if the given matrix is square or not.
- If yes, then traverse the upper triangle part matrix.
- Check if all the entries above the main diagonal are zero.
- If yes, then print Matrix is a lower triangular matrix.
Below is the implementation of the above approach:
Matrix is : 1 0 0 2 3 0 5 6 7 Matrix is lower triangular matrix
Time Complexity: O(N2), where N is the length of the row in a square matrix.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.