Unit-2: Linear Data Structure Array
Unit-2: Linear Data Structure Array
Unit-2: Linear Data Structure Array
GTU # 3130702
Unit-2
Linear Data Structure
Array
Dr. Pradyumansinh U. Jadeja #3130702 (DS) Unit 2 – Linear Data Structure (Array) 4
Column major order matrix
Col-1 Col-2 Col-3 Col-4
Row 1 [1,1] [1,2] [1,3] [1,4]
Dr. Pradyumansinh U. Jadeja #3130702 (DS) Unit 2 – Linear Data Structure (Array) 5
Row major order matrix
Row major order matrix: Two dimensional array in which elements are stored row by row is
called as row major matrix
b2 u2 n = no of rows, m = no of columns
b1 [1,1] [1,2] [1,3] [1,m]
b1 = lower bound subscript of row
[2,1] [2,2] [2,3] [2,m] u1 = upper bound subscript of row
n = u1 – b1 + 1
Dr. Pradyumansinh U. Jadeja #3130702 (DS) Unit 2 – Linear Data Structure (Array) 7
Representation of Polynomial equation
Y Y2 Y3 Y4
X XY XY2 XY3 XY4
X2 X3Y X2Y2 X2Y3 X2Y4
X3 X3Y X3Y2 X3Y3 X3Y4
X4 X4Y X4Y2 X4Y3 X4Y4
Dr. Pradyumansinh U. Jadeja #3130702 (DS) Unit 2 – Linear Data Structure (Array) 8
Sparse matrix
An m x n matrix is said to be sparse if “many” of its elements are zero.
A matrix that is not sparse is called a dense matrix.
We can device a simple representation scheme whose space requirement equals the size of the
non-zero elements.
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
Row - 2 Row 1 1 2 2 2 3 3 4 4
0 6 0 0 7 0 0 3
Column 4 7 2 5 8 4 6 2 3
Row - 3 0 0 0 9 0 8 0 0 2 1 6 7 3 9 8 4 5
Value
Row - 4
0 4 5 0 0 0 0 0
Linear Representation of given matrix
4x8
Dr. Pradyumansinh U. Jadeja #3130702 (DS) Unit 2 – Linear Data Structure (Array) 9
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
Dr. Pradyumansinh U. Jadeja #3130702 (DS) Unit 2 – Linear Data Structure (Array) 10
Sparse matrix Cont…
1 2 3 4 5 6 7
Linear representation of Matrix
0 0 6 0 9 0 0 Row Column A
2 0 0 7 8 0 4 1 3 6
A= 10 0 0 0 0 0 0
1 5 9
0 0 12 0 0 0 0
2 1 2
0 0 0 0 0 0 0
2 4 7
0 0 0 3 0 0 5 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
Dr. Pradyumansinh U. Jadeja #3130702 (DS) Unit 2 – Linear Data Structure (Array) 11
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
Dr. Pradyumansinh U. Jadeja #3130702 (DS) Unit 2 – Linear Data Structure (Array) 12
Data Structures (DS)
GTU # 3130702
Thank
You