Sparse Matrix Implementation with Python
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. 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.
Imagine that you are asked to represent the connections between 1000 components on an electronic circuit board in a program. Perhaps there are conductive wires between some of the components, and we are storing the distance of each…