Professional Documents
Culture Documents
Data Structure L 4
Data Structure L 4
Lecture 4
In the above image, we have shown the memory allocation of an array arr of size 5. The array follows
a 0-based indexing approach. The base address of the array is 100 bytes. It is the address of arr[0].
Here, the size of the data type used is 4 bytes; therefore, each element will take 4 bytes in the
memory.
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.
Data Structure
Lecture 4
Solution:
So, LOC(A[-1])=999+2(-1-(-10))=1017
Solution:
LOC(AUTO[1965])=200+4(1965-1932)=200+4*33=200+132=332
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.
Data Structure
Lecture 4
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.
Data Structure
Lecture 4
In row major ordering, all the rows of the 2D array are stored into the memory
contiguously. Considering the array shown in the above image, its memory allocation
according to row major order is shown as follows.
first, the 1st row of the array is stored into the memory completely, then the 2 nd row
of the array is stored into the memory completely and so on till the last row.
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.
Data Structure
Lecture 4
Solution: Here,
LOC(A[12,3])=200+4*[4(12-1)+(3-1)]=200+4[44+2]=200+4*46=384
First, the 1st column of the array is stored into the memory completely, then the
2nd row of the array is stored into the memory completely and so on till the last
column of the array.
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.
Data Structure
Lecture 4
Solution: Here,
LOC(A[12,3])=200+4*[(12-1)+25(3-1)]=200+4[11+50]=200+4*61=200+244=444
The element of B with subscripts K1, K2, K3, --------, Kn will be denoted by
BK1,K2,--------Kn or B[K1, K2, K3, --------, Kn]
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.
Data Structure
Lecture 4
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.
Data Structure
Lecture 4
Solution:
Li=UB-LB+1
L1=8-2+1=7
L2=1-(-4)+1=6
L3=10-6+1=5
NOE=L1*L2*L3=7*6*5=210
E1=K1-LB=5-2=3
E2=K2-LB=-1-(-4)=3
E3=K3-LB=8-6=2
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.
Data Structure
Lecture 4
Solution:
Li=UB-LB+1
L1=8-2+1=7
L2=1-(-4)+1=6
L3=10-6+1=5
NOE=L1*L2*L3=7*6*5=210
E1=K1-LB=5-2=3
E2=K2-LB=-1-(-4)=3
E3=K3-LB=8-6=2
References:
1. DATA STRUCTURES WITH C by Seymour Lipschutz, 2010.
2. https://www.javatpoint.com/data-structure-2d-array
3. https://www.youtube.com/watch?v=NrhuLHp2vRw
4. https://www.youtube.com/watch?v=djidEjstwRM
5. https://www.youtube.com/watch?v=r-QlbzVJLT4&t=200s
Prepared By Abdullah Rajib, Assistant Professor, RTM Al-Kabir Technical University, Sylhet,
Bangladesh.