0% found this document useful (0 votes)
39 views

What Is Sparse Matrix in Data Structure

A sparse matrix is a matrix with mostly zero values, where non-zero elements are stored efficiently using triples of row, column, and value. Sparse matrices can be represented using arrays or linked lists to store only the non-zero elements to save memory and computing time compared to regular matrices.

Uploaded by

tilaksondagar411
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)
39 views

What Is Sparse Matrix in Data Structure

A sparse matrix is a matrix with mostly zero values, where non-zero elements are stored efficiently using triples of row, column, and value. Sparse matrices can be represented using arrays or linked lists to store only the non-zero elements to save memory and computing time compared to regular matrices.

Uploaded by

tilaksondagar411
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/ 2

what is sparse matrix in data structure?

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 elements..

Example:
0 0 3 0 4
0 0 5 7 0
0 0 0 0 0
0 2 6 0 0

Representing a sparse matrix by a 2D array leads to wastage of lots of memory


as zeroes in the matrix are of no use in most of the cases. So, instead of storing
zeroes with non-zero elements, we only store non-zero elements. This means
storing non-zero elements with triples- (Row, Column, value).

Sparse Matrix Representations can be done in many ways following are two
common representations:
1. Array representation
2. Linked list representation
Method 1: Using Arrays:
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)
Method 2: 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

You might also like