Uploaded by Santosh Kumar

Sparse Matrices

advertisement
For University Level Students
Data Structures: Sparse Matrices
What are Sparse Matrices? Explain 3-tuple representation of sparse matrix with the help of a suitable example. Write about
applications.
Answer: - A matrix is said to be Sparse Matrix if most of its elements are zero (near more than 2/3 elements are zero), having a relatively
small number of non-zero elements. A matrix that is not sparse is called Dense Matrix. A sparse matrix is a two-dimensional array in which
most of the elements have a null value or zero. However, for sparse matrices, this invokes wastage of a lot of memory space. In order to
efficiently utilize the memory, specialized algorithms and data structures that take advantage of the sparse structure should be used. If we
apply the operations using standard matrix structures and algorithms to sparse matrices, then the execution will slow down and the matrix
will consume large amount of memory.
For example, when we are using with matrices of size 100  100 and if only 1000 entries are nonzero and remaining locations are filled
with zeros. This leads to huge amounts of memory wastage. The waste memory locations are 10000-1000=9000 i.e., 9000 memory
locations filled with zeros. Hence, a huge amount of memory is wasted.
When matrices are sparse, then much space and computing time could be saved if the non-zero entries were stored explicitly i.e. ignoring
the zero entries the processing time and space can be minimized in sparse matrices.
0 0 0 24 0 0 0
0 0 0 0 0 5 0
0 0 0 0 0 0 0
0 0 0 0 9 0 0
0 0 0 0 18 0 0
0 0 0 0 8 0 0
In the above matrix we have 6 rows and 7 columns. There are 5 nonzero entries out of 42 entries. It requires an alternate form to represent
the matrix without considering the null entries.
Let us represent the above matrix in the following triplet of 6 rows and 7 columns
0
3
24
1
5
5
3
4
9
4
4
18
5
4
18
The above triplet contains only non-zero details by reducing the space for null entries.
The alternate data structure that we consider to represent a sparse matrix is a triplet. The triplet is a two dimensional array having t+1 rows
and 3 columns. Where, t is total number of nonzero entries.
Other sparse matrices may have an irregular or unstructured pattern. Consider the matrix in Below Figure (a). We show two
representations. Figure (b) shows a one-dimensional array of triples, where each triple represents a nonzero element and consists of the
row, column, and value. Figure (c) shows an irregular array representation. Each row is represented by a one-dimensional array of pairs,
where each pair contains the column number and the corresponding nonzero value.
Figure: Matrices with regular structures.
The first row of the triplet contains number of rows, columns and nonzero entries available in the matrix in its 1st, 2nd and 3rd column
respectively. Second row onwards it contains the row subscript, column subscript and the value of the nonzero entry in its 1st, 2nd and 3rd
column respectively.
Now to keep track of non-zero elements in a sparse matrix we have 3-tuple method using an array. Elements of the first row represent the
number of rows, columns and non-zero values in the sparse matrix. Elements of the other rows give information about the location and
value of non-zero elements.
Row
Column
Value
0 0
3
0
0
2
3
0 0 0
8
1
3
8
1 0 3
0
3-Tuple Transformation
2
0
1
0 0 7
0
2
2
3
44 Sparse Matrix
3
2
7
Handouts by – Santosh Kumar, M.Tech, Ph.D (IIT-M) | 7428065834
For University Level Students
Figure: Unstructured matrices.
Applications: - Sparse matrices can be useful for computing large-scale applications that dense matrices cannot handle. One such
application involves solving partial differential equations by using the finite element method. The finite element method is one method of
solving partial differential equations (PDEs).
X-X-X
Handouts by – Santosh Kumar, M.Tech, Ph.D (IIT-M) | 7428065834
Download