Sparse Matrices

In many applications, we need to manipulate sparse matrices. These are matrices that consist of many zeros and very few non-zero elements.

For example, the word-document matrix for an encyclopedia is extremely sparse. Most words do not appear in most articles.

Instead of taking m n space to represent a matrix A with l non-zero elements, we can represent it using $\Theta(l)$ space using three vectors: for $1 \le i \le l$, Ac[i] is the column of non-zero element i, Ar[i] is its row, and Av[i] is its value. For ease of computation, we require that $A_c[i]\le A_c[j]$ if $i \le j$.Further, if Ac[i]= Ac[j], then $A_r[i]\le A_r[j]$. This means that the non-zero elements are sorted by column, then by row within column.

Given an m by n matrix A, we can convert it to the sparse representation in time $\Theta(m n)$. (Simply read across the rows in order, one at a time, creating an entry in the sparse matrix format for each non-zero encountered.) Given a sparse matrix A with l non-zero elements, we can convert it to a standard (dense) matrix starting from a matrix of all zeros in $\Theta(l)$ time. (Simply assign A[Ar[i], Ac[i]] = Av[i] for each $1 \le i \le l$.)


next up previous
Next: Problems Up: SPARSE MATRICES Previous: Transposition and Matrix-Matrix Products