Java Program to Check Whether a Given Matrix is Lower Triangular Matrix or Not
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.
Auxiliary Space: O(1), no extra space is required, so it is a constant.
My Personal Notes arrow_drop_up
Please Login to comment...