Sparse Matrices
Most of the elements of the matrix have zero values, then such a matrix is
termed as sparse matrix
Example:
Sparse Matrix Representations
A sparse matrix can be represented by using two representations-
1. Triplet Representation.
2. Linked List Representation.
Method 1: Triplet Representation (Array Representation)
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)
Triplet as –(row, Column, Value)
Example:
Consider the following example of a sparse matrix
Hence, we can directly access only non-zero values.
Method 2: Linked List Representation.
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.
Example: