PHP Program to Check for Upper Triangular Matrix Last Updated : 22 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Given a Square Matrix, the task is to check whether the matrix is in upper triangular form or not. A square matrix is called upper triangular matrix if all the entries below the main diagonal are zero. Examples: Input: mat = [ [1, 3, 5, 3], [0, 4, 6, 2], [0, 0, 2, 5], [0, 0, 0, 6]];Output: Matrix is in Upper Triangular formInput: mat = [ [5, 6, 3, 6], [0, 4, 6, 6], [1, 0, 8, 5], [0, 1, 0, 6]];Output: Matrix is not in Upper Triangular formHere is the complete PHP program to check if the matrix is in upper triangular form: PHP <?php // PHP Program to check for // upper triangular matrix $N = 4; // Function to check matrix is in // upper triangular form or not function isUpperTriangularMatrix($mat) { global $N; for ($i = 1; $i < $N; $i++) { for ($j = 0; $j < $i; $j++) { if ($mat[$i][$j] != 0) { return false; } }; } return true; } // Driver Code $mat = [ [1, 3, 5, 3], [0, 4, 6, 2], [0, 0, 2, 5], [0, 0, 0, 6] ]; if (isUpperTriangularMatrix($mat)) { echo "Yes"; } else { echo "No"; } ?> OutputYesTime Complexity: O(n2), where n represents the number of rows and columns of the matrix.Auxiliary Space: O(1), no extra space is required, so it is a constant.Please refer complete article on Program to check if matrix is upper triangular for more details! Comment More infoAdvertise with us Next Article PHP Program to Check for Upper Triangular Matrix kartik Follow Improve Article Tags : Matrix Computer Science Fundamentals Web Technologies PHP PHP Programs DSA +2 More Practice Tags : Matrix Similar Reads PHP Program to Check if Matrix is Lower Triangular Given a square matrix and the task is to check the matrix is in lower triangular form or not. A square matrix is called lower triangular if all the entries above the main diagonal are zero.  Examples:  Input : mat = [[ 1, 0, 0, 0 ], [ 1, 4, 0, 0 ], [ 4, 6, 2, 0 ], [ 0, 4, 7, 6 ]];Output : Matrix is 2 min read PHP Program to Check Involutory Matrix Given a matrix, the task is to check matrix is involutory matrix or not. Involutory Matrix: A matrix is said to be involutory matrix if the matrix multiply by itself return the identity matrix. Involutory matrix is the matrix that is its own inverse. The matrix A is said to be involutory matrix if A 2 min read PHP Program to Check if a Matrix is Symmetric A square matrix is said to be a symmetric matrix if the transpose of the matrix is the same as the given matrix. A Symmetric matrix can be obtain by changing row to column and column to row.Examples: Input : [ [ 1, 2, 3 ], [ 2, 1, 4 ], [ 3, 4, 3 ] ] Output : Yes Input : [ [ 3, 5, 8 ], [ 3, 4, 7 ], [ 2 min read PHP Program to Check horizontal and vertical symmetry in binary matrix Given a 2D binary matrix of N rows and M columns. The task is to check whether the matrix is horizontal symmetric, vertical symmetric, or both. The matrix is said to be horizontal symmetric if the first row is the same as the last row, the second row is the same as the second last row, and so on. An 3 min read PHP Program to Check the Given Matrix is Sparse or Not A matrix is a two-dimensional data object having m rows and n columns, therefore a total of m*n values. If most of the values of a matrix are 0 then we say that the matrix is sparse. Consider a definition of Sparse where a matrix is considered sparse if the number of 0s is more than half of the elem 2 min read PHP Program for Markov matrix Given a m x n 2D matrix, check if it is a Markov Matrix.Markov Matrix: The matrix in which the sum of each row is equal to 1.Example of Markov MatrixExamples: Input :1 0 00.5 0 0.50 0 1Output : yesExplanation :Sum of each row results to 1, therefore it is a Markov Matrix.Input :1 0 00 0 21 0 0Output 2 min read PHP Program for Identity Matrix Introduction to Identity Matrix : The dictionary definition of an Identity Matrix is a square matrix in which all the elements of the principal or main diagonal are 1's and all other elements are zeros. In the below image, every matrix is an Identity Matrix. In linear algebra, this is sometimes call 4 min read PHP Program to Rotate the matrix right by K times Given a matrix of size N*M and a number K. We have to rotate the matrix K times to the right side. Examples: Input : N = 3, M = 3, K = 2 12 23 34 45 56 67 78 89 91 Output : 23 34 12 56 67 45 89 91 78 Input : N = 2, M = 2, K = 2 1 2 3 4 Output : 1 2 3 4A simple yet effective approach is to consider e 2 min read PHP Program for Maximum and Minimum in a Square Matrix Given a square matrix of order n*n, find the maximum and minimum from the matrix given. Examples: Input : Arr = [ [ 5, 4, 9 ], [ 2, 0, 6 ], [ 3, 1, 8 ] ]; Output : Maximum = 9, Minimum = 0 Input : Arr = [[ -5, 3 ], [ 2, 4 ]]; Output : Maximum = 4, Minimum = -5Naive MethodWe find the maximum and mini 2 min read PHP Program to Print a given matrix in reverse spiral form Given a 2D array, print it in reverse spiral form. We have already discussed Print a given matrix in spiral form. This article discusses how to do the reverse printing. Example: Input: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16Output: 10 11 7 6 5 9 13 14 15 16 12 8 4 3 2 1Input: 1 2 3 4 5 6 7 8 9 10 11 3 min read Like