Page 23 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 23
Advanced Data Structure and Algorithms
Notes Programming language stores the array in either of the two way:
1. Row Major Order
2. Column Major Order
In Row Major Order elements of 1st Row are stored first in linear order and then comes elements
of next Row and so on.
In Column Major Order elements of 1st column are stored first linearly and then comes elements
of next column. When Above Matrix is stored in memory using Row Major Order form then the
representation will be as shown in fi gure.
(1, 1)
(1, 2) Row 1
(1, 3)
(2, 1)
(2, 2) Row 2
(2, 3)
(3, 1)
(3, 2) Row 3
(3, 3)
Representation with Column Major form will be:
(1, 1)
(2, 1) Column 1
(3, 1)
(1, 2)
(2, 2) Column 2
(3, 2)
(1, 3)
(2, 3) Column 3
(3, 3)
Number of elements in any two-dimensional Array can be given by:
No. of elements = (UB – LB + 1) * (UB – LB + 1) …(5)
1 1 2 2
where,
UB is upper bound of 1st dimension
1
LB is lower bound of 1st dimension UB and LB
1 2 2
are upper and lower bounds of 2nd dimensions
18 LOVELY PROFESSIONAL UNIVERSITY