Matrix in Programming YASH PAL, October 8, 2022May 28, 2024 Two-dimensional array(Marix) – A two-dimensional array is a list of finite numbers m*n homogeneous data elements such thatthe element of the array is referenced by two index sets consisting of m and n consecutive integer numbers.the elements of the array are stored in consecutive The size of two – a dimensional array is denoted by m*n.[br][br]Types of MATRIX[br]Diagonal Matrix1000020000300004[br]Tri Diagonal Matrix1400224002320034[br]Lower Triangular Matrix1000120023303424[br]Upper Triangular Matrix1321024200330004[br]Sparse Matrix1000000002000004[br]Dense Matrix1091068442300304[br]Unit Matrix1000010000100001[br]Symmetric Matrix1234212332124324[br]NOTE:-we assume that all the matrices (except Sparse and Dense) are square matrices. MATRIX OPERATIONSumMultiplyTransposeSorting[br]SPARSE MATRIXAn m*n matrix is said to be sparse if many of its elements are zero. A matrix that is not sparse is called a dense matrix. In sparse matrix e.g – diagonal matrix, tri diagonal matrix in array representation, an array of triplets of type- < row, col, the element is used to store nonzero elements where the first field of the triplet is used to record row position, second to record column position and the third one to record the nonzero elements of the sparse matrix this row is a header in sparse matrix[br]Algorithm for Transpose of a sparse matrixTRANSPOSE (SM1, SM2) Here SM1 and SM2 are two sparse matrices. This algorithm computes the transposition of SM1 into SM2. N is no. of nonzero elements. The header row is 01. Set MAXROW := SM1 [0,2], MAXCOL := SM1 [0,3], N := SM1 [0,1] 2. Set SM2 [0,1] := N, SM2 [0,2] :MAXCOL, SM2 [0,3] := MAXROW 3. If N > 0, then [If the number of non-zero elements is more than 0] 4. Set I = 1 [I is a counter for SM2] 5. Repeat Step 6 for COL:= 1 to MAXCOL [Counter for counting columns] 6. Repeat Step (a) for P:= 1 to N [Counter for SM1] (a) If SM1 [P.3] = COL, then (i) SM2 [I,1] := SM1 [P,1] (ii) SM2 [I,2] := SM1 [P,3] (iii) SM2 [I,3] := SM1 [P,2] (iv) Set I :I +I [End of If structure.] [End of Step 6 loop] [End of Step 5] [End of If structure] 7. Exit. algorithms data structures matrix DSAmatrix