0% found this document useful (0 votes)
25 views12 pages

DS Unit2 Sparse

Uploaded by

namansehgal3006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views12 pages

DS Unit2 Sparse

Uploaded by

namansehgal3006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Sparse Matrix

Data Structures
Dr. Nivedita Palia
A matrix is a two-dimensional data object made of m rows and n columns, therefore having
total m x n values. If most of the elements of the matrix have 0 value, then it is called a
sparse matrix.
Why to use Sparse Matrix instead of simple matrix ?
Storage: There are lesser non-zero elements than zeros and thus lesser memory can be used
to store only those elements.
Computing time: Computing time can be saved by logically designing a data structure
traversing only non-zero element
Example
Memory Representation
Sparse Matrix Representations can be done in two representations:
1.Array representation 2.Linked list representation
Using Arrays: named as 3 tuple form
2D array is used to represent a sparse matrix in which there are three rows named as
Row: Index of row, where non-zero element is located
Column: Index of column, where non-zero element is located
Value: Value of the non zero element located at index – (row, column)

Time Complexity: O(NM), where N is the number of rows in the sparse matrix, and
M is the number of columns in the sparse matrix.
Using Linked Lists
In linked list, each node has four fields. These four fields are defined as:
Row: Index of row, where non-zero element is located
Column: Index of column, where non-zero element is located
Value: Value of the non zero element located at index – (row, column)
Next node: Address of the next node

Time Complexity: O(N*M), where N is the number of rows in the sparse matrix,
and M is the number of columns in the sparse matrix.
Types of Sparse Matrix
•Lower triangular regular sparse matrices : A 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.
•Upper triangular regular sparse matrices: The 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.
•Tri-diagonal regular sparse matrices : The tridiagonal regular sparse matrix where all
non-zero elements lie on one of the three diagonals, the main diagonal above and below.
Representing lower and upper
triangular in 1-D array

K= [(i-1)*i/2]+j (B[k] = A[i][j] )


Representation of tri-diagonal in 1-D
array

K= [3(i-2)+2] +[j-i+1]+1=2i+j+2 where D[k]=A[i][j]


Operations

1) Addition
2) Subtraction
3) Multiplication
4) Transpose
Addition of 2 sparse matrix
END

You might also like