Sparse matrix and its representation data structure
1. GANDHINAGAR INSTITUTE OF TECHNOLOGY
Computer Engineering Department
Data Structures (2130702)
Sparse matrix and its representation
Prepared By : Vardhil Patel
Enrolment No : ___________
Guided By:
Prof. ___________
2. Sparse matrix and its representation
Matrics play a very important role in solving many
interesting problem in various scientific and
engineering application. It is therefore necessary for us
to design efficient representation for matrices.
Normally matrices are represented in a two
dimensional array. In a matrix, if there are m rows and
n columns and then the space required to store the
numbers will be m*n*s where s is the number of bytes
required to store the value. Suppose there are 10 rows
and 10 columns and we have to store the integer values
then the space complexity will be bytes.
10*10*2=200 bytes.
3. Sparse Matrices
• Sparse matrix … many elements are zero means sparse
matrix has very few non zero elements
• Time complexity of the matrix will be O(n^2),because
the operations that are carried out on matrices need to
sces one row at a time and individual columns in that
row, results in use of two nested loops,
• Example: if the matrix is of size 100*100and only 10
elements are non zero. Then for accessing these 10
elements one has to make 10000 times scan. also only
10 spaces will be with non zero elements remaining
space of matrix will be filled with zeros only. i.e. we
have to allocate the memory of 100*100*2=2000.
4. Representation of sparse matrix:
• The representation of sparse matrix will be a triplet
only.
• In the sense that basically the sparse matrix means
very few non zero elements having in it rest of the
spaces are having the values zero which are
basically useless values or simply empty values.so in
this efficient representation we will consider all the
non zero value along with their positions. in a row
wise representation of spare matrix (sparse matrix
is 2D matrix) the 0th row will store total rows of the
matrix, total column of the matrix and total non
zero value