Sparse Matrices 10062021 v1
Sparse Matrices 10062021 v1
• We can also use the simple matrix to store the elements in the
memory; then why do we need to use the sparse matrix. The
following are the advantages of using a sparse matrix:
Storage: As we know, a sparse matrix that contains lesser non-
zero elements than zero so less memory can be used to store
elements. It evaluates only the non-zero elements.
Computing time: In the case of searching n sparse matrix, we
need to traverse only the non-zero elements rather than
traversing all the sparse matrix elements. It saves computing
time by logically designing a data structure traversing non-zero
elements.
Representation of Sparse matrix
1) Diagonal Matrix
This is the square matrix where the non zero elements are
only where row = col ie at diagonal.
2) Tridiagonal Matrix
Triangular Matrices
Tiangular Matrices is of 2 types:
a) Lower triangular b) Upper triangular
Program to check if given matrix is
sparse or not?
1. Size= rows*columns;
2. for(int i = 0; i < rows; i++){
3. for(int j = 0; j < cols; j++){
4. if(a[i][j] == 0)
5. count++;
6. }
7. }
8.
9. if(count > (size/2))
10. printf("Given matrix is a sparse matrix");
11. else
12. printf("Given matrix is not a sparse matrix");
13.
14.
Program to convert matrix
into triplex/sparse matrix