Sparse matrix triplet representation

Matrix is defined with a 2-dimensional array that has row and column. An array which has 'm' rows and 'n' columns represent an mXn matrix. Sometimes it happens when a matrix has zero values is more than NON-ZERO values. The matrix which has a greater number of ZERO values in comparison to the non-zero values is known as a Sparse Matrix.

Sparse Matrix Representations

A sparse matrix can be represented in two way:

  1. Triplet Representation
  2. Linked Representation

Triplet Representation

In Triplet Representation of a sparse matrix, we consider only non-zero values along with their row and column index values. The 0th row of the matrix stores the total number of rows, total number of columns, and total non-zero values. sparse matrix  triplet representation of sparse matrix

In the above example of the matrix, there are only five non-zero elements, those are 3, 8, 1, 3, 7, and matrix size is 4 X 4. We represent this matrix in triplet representation (row, column, value), as shown in the above image.

Program using C