Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />
LOC(LA[K])=Base(LA) + w (K‐lower bound)<br />
Where w is the number of words per memory cell for the array LA.<br />
Multidimensional arrays<br />
This can be done by the following methods<br />
ROW MAJOR IMPLEMENTATION<br />
Row major implementation is a linearization technique in which elements of<br />
array are reader from the keyboard row wise i.e the complete first row is<br />
stored, then the complete second row is stored and so on.<br />
Address of elements in row major implementation:<br />
The computer does not keep the track of all the elements of the array, rather, it<br />
keeps a base address and calculates the address of required element when<br />
needed. It calculates this by the following relation:<br />
Address of element a[i][j]= B+W (n (i‐L1) + (j‐L2))<br />
Where B is the base address of the array, W is size of each array element, n is<br />
the number of column. L1 the lower bound of row,l2 is lower bound of column.<br />
Let us study an example to get a clear idea of row major implementation.<br />
A two dimensional array defined as a [4.. 7,‐<strong>1.</strong>. 3] requires 2 bytes of storage<br />
space for each element. If the array is stored in row major form, then calculate<br />
the address of element at location a[6,2]. Give that the base address is 100.<br />
Base address B=100<br />
Size of each element in the array W= 2 bytes<br />
Lower bound of row L1=4<br />
Lower bound of column L2=‐1<br />
Upper bound of row U1=7<br />
Upper bound of column U2=3<br />
Row number of the required element i=6<br />
Column number of required element j=2<br />
Now the number of columns n will be:<br />
U2 – L2 + 1= 3 – (‐1) + 1+5<br />
Address of a[6][2] = 100+2(5(6‐4)+(2‐(‐1)))<br />
=100+2(5*2+3)<br />
Prepared By :<br />
Er. Harvinder Singh<br />
Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 37 ‐