This document discusses sparse matrix representations. It defines sparse matrices as matrices with mostly zero values and explains their memory and computation benefits over dense matrices. It then describes two common sparse matrix representations: (1) the triplet representation which stores nonzero elements as rows of (row, column, value) tuples, and (2) the linked list representation which stores nonzero elements as nodes linking (row, column, value) and the next node. The document also categorizes sparse matrices into triangular and banded matrices based on the pattern of nonzero values.
This document discusses sparse matrix representations. It defines sparse matrices as matrices with mostly zero values and explains their memory and computation benefits over dense matrices. It then describes two common sparse matrix representations: (1) the triplet representation which stores nonzero elements as rows of (row, column, value) tuples, and (2) the linked list representation which stores nonzero elements as nodes linking (row, column, value) and the next node. The document also categorizes sparse matrices into triangular and banded matrices based on the pattern of nonzero values.
Contents: ➢Introduction ➢Memory Representations of sparse matrix ➢Triplet Representation ➢Linked List Representation ➢Classification of Sparse Matrix ➢Triangular Matrices ➢Band Matrix What are SPARSE MATRICES? ➢ A matrix is a 2-dimensional data object composed of m rows and n columns, therefore having total m x n values. ➢ In computer programming, a matrix can be defined with a 2-dimensional array. ➢ Any array with 'm' rows and 'n' columns represent a m X n matrix. ➢ If most of the elements of the matrix have 0 value, then such a matrix is termed as “Sparse matrix” Consider the following as an example of a sparse matrix A: ┌ ┐ | 10 0 3 0 0 0 | | 21 2 0 4 0 0 | | 0 3 6 0 5 0 | | 0 0 23 24 0 26 | | 81 0 0 94 65 0 | | 71 92 0 0 55 36 | └ ┘ Why to use Sparse Matrix? • Storage: There are lesser non-zero elements than zeros and thus lesser memory can be used to store only those elements. – space calculation: Matrix having m rows and n columns the space required to store the numbers will be m*n*s where s is the number of bytes required to store the value. E.g. 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. • Computing time: Computing time can be saved by logically designing a data structure traversing only non-zero elements. Sparse Matrix Representations ➢ Representing a sparse matrix with a 2D array results in wastage of memory and processing time. E.g. consider a matrix of size 100 X 100 containing only 10 non-zero elements. – In this matrix, only 10 spaces are filled with non-zero values and remaining spaces of the matrix are filled with zero. – Space allocated: 100 X 100 X 2 = 20,000 bytes to store this integer matrix. – Access time of 10 non-zero elements: 10,000 scans.
➢ To avoid such circumstances different techniques are used such as:
1) Triplet Representation (Array 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)
Consider the following as an example of a sparse matrix B:
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 Classification of Sparse Matrix Triangular Matrices Band Matrix • Triangular matrices have the same number • A band matrix is a sparse matrix whose of rows as they have columns; i.e. they non-zero entries are confined to a have n rows and n columns. diagonal band, comprising the main • Thus, triangular matrix is a special kind diagonal and zero or more diagonals on of square matrix. either side. Types of Triangular Matrices Upper Triangular Matrices Lower Triangular Matrices
A matrix A is an upper triangular A matrix A is a lower triangular
matrix if its nonzero elements are matrix if its nonzero elements are found only in the upper triangle of found only in the lower triangle of the matrix, including the main the matrix, including the main diagonal; diagonal; Types of Band Matrices Diagonal Matrix Tri-Diagonal Matrices ➢ Let A b e a square matrix (with entries ➢ A tri-diagonal matrix is a matrix that in any field). If all off- diagonal has nonzero elements only in the main entries of A are zero, then A is a diagonal, the first diagonal below diagonal matrix. this, an d the first diagonal above the Square diagonal matrix: main diagonal.
Rectangular diagonal matrix:
References [1] https://www.geeksforgeeks.org/sparse-matrix-representation/ [2] Lipschutz, S. (1987). Schaum's Outline of Data Structure. McGraw-Hill, Inc. [3] https://en.wikipedia.org/wiki/Sparse_matrix Thank You