02 Array
02 Array
GTU # 3130702
Unit-2
Linear Data Structure
Column - 8
Column - 3
Column - 5
Column - 7
Column - 6
Column - 4
Column - 1
Column - 2
Row - 1 0 0 0 2 0 0 1 0 Terms 0 1 2 3 4 5 6 7 8
0 6 0 0 7 0 0 3 Row 1 1 2 2 2 3 3 4 4
Row - 2
Column 4 7 2 5 8 4 6 2 3
Row - 3 0 0 0 9 0 8 0 0
Value 2 1 6 7 3 9 8 4 5
Row - 4 0 4 5 0 0 0 0 0
Linear Representation of given matrix
4x8
Sparse matrix Cont…
To construct matrix structure from liner representation we need to record.
Original row and columns of each non zero entries.
Number of rows and columns in the matrix.
So each element of the array into which the sparse matrix is mapped need to have three fields:
row, column and value
Sparse matrix Cont…
1 2 3 4 5 6 7
Linear representation of Matrix
1 0 0 6 0 9 0 0
Row Column A
2 2 0 0 7 8 0 4
1 3 6
A= 3 10 0 0 0 0 0 0
4 0 0 12 0 0 0 0 1 5 9
5 0 0 0 0 0 0 0 2 1 2
6 0 0 0 3 0 0 5 2 4 7
6x7
2 5 8
Memory Space required to store 4
2 7
6x7 matrix
3 1 10
42 x 2 = 84 bytes
4 3 12
6 4 3
Memory Space required to store
Linear Representation 6 7 5
30 x 2 = 60 bytes
Space Saved = 84 – 60 = 24 bytes
Sparse matrix Cont…
Linear Representation of Matrix Linear Representation of Matrix
Row Column A Column A
1 3 6 1 3 6
1 5 9 2 5 9
Row
2 1 2 3 1 2
1 1
2 4 7 4 4 7
2 3
2 5 8 5 5 8
3 7
2 7 4 6 7 4
4 8
3 1 10 7 1 10
5 0
4 3 12 8 3 12
6 9
6 4 3 9 4 3
6 7 5 10 7 5
Thank
You