Types of Sparse Matrices?In this article, we will understand the sparse matrices and their types in detail. What do you mean by Sparse Matrices?A wide range of numerical problems in reallife applications such as engineering, scientific, computing, and economic use huge matrices. These matrices often contain many zero elements, and such matrices with high proportions of zero entries are known as sparse matrices. It is called sparse as it has a relatively low density of nonzero elements. If we store Sparse Matrix as a 2dimension array, a lot of space is wasted to store all those 0's explicit. Moreover, while performing operations on sparse matrices such as addition, subtraction, and multiplication stored as a 2dimension array, many operations are performed on elements with zero values which results in the amount of wastage in time. So, a better strategy is to explicitly store the nonzero elements, which greatly reduces the required storage space and computations needed to perform various operations. Types of Sparse MatricesThere are different variations of sparse matrices, which depend on the nature of the sparsity of the matrices. Based on these properties, sparse matrices can be
Regular sparse matricesA regular sparse matrix is a square matrix with a welldefined sparsity pattern, i.e., nonzero elements occur in a welldefined pattern. The various types of regular sparse matrices are:
Lower triangular regular sparse matricesA Lower regular sparse matrix is the one where all elements above the main diagonal are zero value. The following matrix is a lower triangular regular sparse matrix. Storing Lower triangular regular sparse matrices In a lower triangular regular sparse matrix, the nonzero elements are stored in a 1dimensional array row by row. For example: The 5 by 5 lower triangular regular sparse matrix as shown in the above figure is stored in onedimensional array B is: B = { A_{11}, A_{21}, A_{22}, A_{31}, A_{32}, A_{33}, A_{41}, A_{42}, A_{43}, A_{44}, A_{51}, A_{52}, A_{53}, A_{54}, A_{55}} Here B [1] = A_{11}, B [2] = A_{21}, B [3] = A_{22}, ……………………………………… B [14] = A_{54,} B [15] = A_{55} To calculate the total number of nonzero elements, we need to know the number of nonzero elements in each row and then add them. Since the number of nonzero elements in an ith row so that the total number of nonzero elements in the lower triangular regular sparse matrix of n rows is: 1 + 2 + ………………… + i + ………………….. + (n1) + n = n (n+1)/2 Upper triangular regular sparse matricesThe Upper triangular regular sparse matrix is where all the elements below the main diagonal are zero value. Following matrix is the Upper triangular regular sparse matrix. Storing Upper triangular regular sparse matrices In an upper triangular regular sparse matrix, the nonzero elements are stored in a 1dimensional array column by column. For example, The 5 by 5 lower triangular regular sparse matrix, as shown in the above figure, is stored in onedimensional array B is: B = { A_{11}, A_{21}, A_{22}, A_{31}, A_{32}, A_{33}, A_{41}, A_{42}, A_{43}, A_{44}, A_{51}, A_{52}, A_{53}, A_{54}, A_{55}} Here B [1] = A_{11}, B [2] = A_{21}, B [3] = A_{22}, B [4] = A_{31,}B [5] = A_{32} _{,}B [6] = A_{33, }B [7] = A_{41 ,}B [8] = A_{42} _{,}B [9] = A_{43 ,}B [10] = A_{44 ,}B [11] = A_{51 ,}B [12] = A_{52} _{,}B [13] = A_{53} , B [14] = A_{54,} B [15] = A_{55} In order to calculate the total number of nonzero elements, we need to know the number of nonzero elements in each row and then add them. Since, the number of nonzero elements in ith row so that the total number of nonzero elements in lower triangular regular sparse matrix of n rows is: 1 + 2 + ………………… + i + ………………….. + (n1) + n = n (n+1)/2 Upper triangular regular sparse matrices The Upper triangular regular sparse matrix is where all the elements below the main diagonal are zero value. The following matrix is an Upper triangular regular sparse matrix. Storing Upper triangular regular sparse matrices In an upper triangular regular sparse matrix, the nonzero elements are stored in a 1dimensional array column by column. For example, The 5 by 5 lower triangular regular sparse matrix, as shown in the above figure, is stored in onedimensional array B is: C = { A_{11}, A_{12}, A_{22}, A_{13}, A_{23}, A_{33}, A_{14}, A_{24}, A_{34}, A_{44}, A_{15}, A_{25}, A_{35}, A_{45}, A_{55}} Here C [1] = A_{11}, C [2] = A_{12}, C [3] = A_{22}, C [4] = A_{13,}C [5] = A_{23} _{,}C [6] = A_{33, }C [7] = A_{14 ,}C [8] = A_{24} _{,}C [9] = A_{34}, C [10] = A_{44 ,}C [11] = A_{15 ,}C [12] = A_{25} _{,}C [13] = A_{35} , C [14] = A_{45,} C [15] = A_{55} In order to calculate the total number of nonzero elements, we need to know the number of nonzero elements in each column and then add them. Since, the number of nonzero elements in ith column is i so the total number of nonzero elements in upper triangular regular sparse matrix of n columns is: 1 + 2 + ………………… + i + ………………….. + (n1) + n = n (n+1)/2 Tridiagonal regular sparse matricesThe tridiagonal regular sparse matrix where all nonzero elements lie on one of the three diagonals, the main diagonal above and below. Storing Tridiagonal regular sparse matrices In a tridiagonal regular sparse matrix, all the nonzero elements are stored in a 1dimensional array row by row. For example, The 5 by 5 tridiagonal regular sparse matrix, as shown in the above figure, is stored in onedimensional array D is: D = { A_{11}, A_{12}, A_{21}, A_{22}, A_{23}, A_{32}, A_{33}, A_{34}, A_{43}, A_{44}, A_{45}, A_{54}, A_{55}} Here D [1] = A_{11}, D [2] = A_{12}, D [3] = A_{21}, D [4] = A_{22, }D [5] = A_{23, }D [6] = A_{32} _{,}D [7] = A_{33, }D [8] = A_{34 ,}D [9] = A_{43} _{,}D [10] = A_{44 ,}D [11] = A_{45 ,}D [12] = A_{54,} D [13] = A_{55} In order to calculate the total number of nonzero elements, we need to know the number of nonzero elements along the diagonal, above the diagonal and below the diagonal. The number of elements in a square matrix along the diagonal is 'n' and above the diagonal is (n1). So the total number of nonzero elements in nsquare matrix is: Therefore, the total number of elements for nsqure matrix = 3n2 In our case, n = 5 so the total number of elements = 3 * 5  2 = 13 Irregular sparse matricesThe irregular sparse matrices are the ones that behave an irregular or unstructured pattern of occurrences of nonzero elements. The following matrix is an irregular sparse matrix. In the above diagram, there are several common storage schemes to store sparse matrices. Most of these schemes store all the nonzero elements of the matrix into a 1dimensional array. Storage schemes of Irregular sparse matrices:In this scheme, we store all the nonzero elements of the matrix into a 1dimensional array and use several auxiliary arrays to specify the location of nonzero elements in the sparse matrix. Among the several available storage schemes for storing irregular sparse matrices, the most common storage schemes are:
Storing irregular sparse matrix using storage by Index Method Using storage by the index method, we can store irregular sparse matrices A by constructing three 1Dimensional arrays AN, AI, and AJ, each having elements equal to a total number of nonzero elements.
Let us consider a 4 by 6 sparse matrix A as shown below: Out of 24 elements of this Sparse Matrix, only 10 elements are nonzero. These nonzero elements are: Figure: Representation of three 1  D arrays AI, AJ, AN To store it using the storage by index method. We construct threedimensional arrays AN, SI, AJ, each having 10 elements (i.e., the total number of nonzero elements) as shown in the above diagram. The array AN contains the 10 nonzero elements stored contiguously. The corresponding row number and column number of each nonzero element are stored in arrays AI and AJ, respectively. Storing irregular sparse matrix using the compressed row storage formatAnother spaceefficient and most widely used scheme for representing irregular sparse matrices is compressing row storage. In this scheme, we take three 1Dimensional arrays AN, AI, and AJ. Onedimensional array AN contains all the values of nonzero elements taken in a rowwise fashion from the matrix. The next 1dimensional array AJ of length equal to AN's length is constructed that contains the original column positions of the corresponding elements in AN. A 1dimensional array AI with a length equal to several rows is constructed that stores the location of the first entry of nonzero elements in AN array. For Example: AI [2] = 4 indicates that the first nonzero elements in row 2 are stored in AN[4], which is 2. To store it by compressing row storage format, we construct three 1dimensional arrays AN, AI, and AJ, as shown in the following figure: The array AN contains 10 nonzero elements stored contiguously in a rowwise fashion. The corresponding column numbers are stored in 1dimensional array AJ. The 1dimensional array AI contains elements which is pointer to the first nonzero element of each row in array AJ and AN.
Next TopicApplication of Linked List
