0% found this document useful (0 votes)
87 views

Sparse Matrices: Sparse Many Elements Are Zero Dense Few Elements Are Zero

Sparse matrices have many zero elements, while dense matrices have few zero elements. There are structured sparse matrices like diagonal, tridiagonal, and lower triangular matrices that can be mapped to a 1D array. Unstructured sparse matrices, like airline flight or web page matrices, represent relationships between sets of objects and need specialized storage. They are commonly represented using a single linear list of nonzero element triples (row, column, value) or separate lists per row for improved performance in sparse matrix operations.

Uploaded by

Seema Mongia
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Sparse Matrices: Sparse Many Elements Are Zero Dense Few Elements Are Zero

Sparse matrices have many zero elements, while dense matrices have few zero elements. There are structured sparse matrices like diagonal, tridiagonal, and lower triangular matrices that can be mapped to a 1D array. Unstructured sparse matrices, like airline flight or web page matrices, represent relationships between sets of objects and need specialized storage. They are commonly represented using a single linear list of nonzero element triples (row, column, value) or separate lists per row for improved performance in sparse matrix operations.

Uploaded by

Seema Mongia
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Sparse Matrices

sparse … many elements are zero


dense … few elements are zero
Example Of Sparse Matrices
diagonal
tridiagonal
lower triangular (?)

These are structured sparse matrices.


May be mapped into a 1D array so that a
mapping function can be used to locate an
element.
Unstructured Sparse Matrices
Airline flight matrix.
 airports are numbered 1 through n
 flight(i,j) = list of nonstop flights from airport i
to airport j
 n = 1000 (say)
 n x n array of list references => 4 million bytes
 total number of flights = 20,000 (say)
 need at most 20,000 list references => at most
80,000 bytes
Unstructured Sparse Matrices
Web page matrix.
web pages are numbered 1 through n
web(i,j) = number of links from page i to page j

Web analysis.
authority page … page that has many links to it
hub page … links to many authority pages
Web Page Matrix
 n = 2 billion (and growing by 1 million a day)
 n x n array of ints => 16 * 1018 bytes (16 * 109
GB)
 each page links to 10 (say) other pages on
average
 on average there are 10 nonzero entries per
row
 space needed for nonzero elements is
approximately 20 billion x 4 bytes = 80 billion
bytes (80 GB)
Representation Of Unstructured
Sparse Matrices
Single linear list in row-major order.
scan the nonzero elements of the sparse matrix in row-
major order
each nonzero element is represented by a triple
(row, column, value)
the list of triples may be an array list or a linked list
(chain)
Single Linear List Example

00304 list =
00570 row 1 1 2 2 4 4
00000 column 3 5 3 4 2 3
02600 value 3 4 5 7 2 6
Array Linear List Representation

row 1 1 2 2 4 4
list = column 3 5 3 4 2 3
value 3 4 5 7 2 6

element 0 1 2 3 4 5
row 1 1 2 2 4 4
column 3 5 3 4 2 3
value 3 4 5 7 2 6
Chain Representation

Node structure.

row col
value next
Single Chain

row 1 1 2 2 4 4
list = column 3 5 3 4 2 3
value 3 4 5 7 2 6

1 3 1 5 2 3 2 4 4 2 4 3
3 4 5 7 2 6 null

firstNode
One Linear List Per Row

row1 = [(3, 3), (5,4)]


row2 = [(3,5), (4,7)]
00304 row3 = []
row4 = [(2,2), (3,6)]

00570
00000
Array Of Row Chains

Node structure.

next
col value
Array Of Row Chains

null
3 3 5 4

00304 null
3 5 4 7

null
00570
00000 null
2 2 3 6
02600
row[]
Orthogonal List Representation

Both row and column lists.

Node structure.
row col value
down next
Row Lists

1 3 3 1 5 4
n
00304
2 3 5 2 4 7
n

00570
null
00000
02600 4 2 2 4 3 6
n
Column Lists

1 3 3 1 5 4
n
00304
2 3 5 2 4 7
00570
00000
02600
4 2 2 4 3 6
n n
Orthogonal Lists

1 3 3 1 5 4
n n
00304
2 3 5 2 4 7
n

00570
null
00000
02600 4 2 2 4 3 6
n n n

row[]
Variations

May use circular lists instead of chains.


Approximate Memory Requirements

500 x 500 matrix with 1994 nonzero elements

2D array 500 x 500 x 4 = 1million bytes


Single Array List 3 x 1994 x 4 = 23,928 bytes
One Chain Per Row 23928 + 500 x 4 = 25,928
Runtime Performance
Matrix Transpose
500 x 500 matrix with 1994 nonzero elements

2D array 210 ms
Single Array List 6 ms
One Chain Per Row 12 ms
Performance
Matrix Addition.
500 x 500 matrices with 1994 and 999 nonzero
elements

2D array 880 ms
Single Array List 18 ms
One Chain Per Row 29 ms

You might also like