Module 2 Part1 ArrayMatrics
Module 2 Part1 ArrayMatrics
a b c d
start
• location(x[i]) = start + i
Space Overhead
Memory
a b c d
start
a b c d
e f g h
i j k l
Row-Major Mapping
• Example 3 x 4 array:
abcd
efgh
i jkl
• Convert into 1D array y by collecting elements by rows.
• Within a row elements are collected from left to right.
• Rows are collected from top to bottom.
• We get y[] = {a, b, c, d, e, f, g, h, i, j, k, l}
row 0 row 1 row 2 … row i
Locating Element x[i][j]
0 c 2c 3c ic
2 3
4 5 6
7 8 9 l0
0 1 3 6
r 1 r2 r3 … row i
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
Node structure.
next
col value
Array Of Row Chains
null
3 3 5 4
00304 null
00570 3 5 4 7
00000
null
02600
null
2 2 3 6
row[]
Orthogonal List Representation
Node structure.
row col value
down next
Row Lists
1 3 3 1 5 4
n
00304
00570 2 3 5 2 4 7
n
00000
02600 null
4 2 2 4 3 6
n
Column Lists
1 3 3 1 5 4
n
00304
00570 2 3 5 2 4 7
00000
02600
4 2 2 4 3 6
n n
Orthogonal Lists
1 3 3 1 5 4
n n
00304
00570 2 3 5 2 4 7
n
00000
02600 null
4 2 2 4 3 6
n n n
row[]