0% found this document useful (0 votes)
38 views

Computer Science Address Calculation of Array

The document discusses the calculation of memory addresses of elements in two-dimensional arrays stored in row-major and column-major order. It provides the formulas to calculate the address of an element and includes examples solving for addresses of elements in given arrays.

Uploaded by

freetension03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Computer Science Address Calculation of Array

The document discusses the calculation of memory addresses of elements in two-dimensional arrays stored in row-major and column-major order. It provides the formulas to calculate the address of an element and includes examples solving for addresses of elements in given arrays.

Uploaded by

freetension03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Page 1 of 2

Computer Science
Class XII
ADDRESS CALCULATION OF ARRAY

Let A is a two dimensional array with M rows and N columns. LR and LC are lowest limit of row and column.
W is the size of each element in the memory. Loc(A[i][j]) means the address of the ith row and jth column in the
memory.
Row Major Order:
Loc(A[i][j]) = Base Address of (A) + W × [ N × (i – LR) + (j –LC)]

Column Major Order:


Loc(A[i][j]) = Base Address of (A) + W × [ M × (j – LC) + (i –LR)]

Q1. An array T[15][10] is stored along the row in the memory with each element requiring 8 bytes of storage.
If the base address of array T is 14000, find out the location of T[10][7].
All India 2013
Ans: Loc(A[i][j]) = Base Address of (A) + W × [ N × (i – LR) + (j –LC)]
Loc(T[10][7]) = 14000 + 8 × [ 10 × (10 – 0) + (7 –0)]
= 14000 + 8 × [ 10 ×10 + 7 ]
= 14000 + 8 × [107]
= 14000 + 856
= 14856

Q2. An array S[10][30] is stored in the memory along the column with each of the elements occupying 2
bytes. Find out the memory location of S[5][10], if the element S[2][15] is stored at the location 8200.
Delhi 2012
Ans: Loc(S[i][j]) = Base Address of (S) + W × [ M × (j – LC) + (i –LR)]
Loc(S[2][15]) = Base Address of (S) + 2 × [ 10 × (15 – 0) + (2 –0)]
8200 = Base Address of (S) + 2 × [150 + 2]
Base Address of (S) = 8200 - 2 × 152
= 8200 – 304
= 7896

Loc(S[5][10]) = Base Address of (S) + 2 × [ 10 × (10 – 0) + (5 –0)]


= 7896 + 2 × [100 + 5]
= 7896 + 2 × 105
= 7896 + 210
= 8106

Q3. An array P[20][50] is stored in the memory along the column with each of the element occupying 4
bytes, find out the memory location for the element P[15][10], if P[0][0] is stored at 5200.
Delhi 2011
Ans: Loc(P[i][j]) = Base Address of (P) + W × [ M × (j – LC) + (i –LR)]
Loc(P[15][10]) = 5200 + 4 × [ 20 × (10 – 0) + (15 – 0)
= 5200 + 4 × [200 + 15]
= 5200 + 4 × 215
= 5200 + 860
= 6060
Page 2 of 2

Q4. An array P[50][60] is stored in the memory along the column with each of the element occupying 2
bytes, find out the memory location for the element P[10][20], if the base address of the array is stored at
6800. Delhi 2011
Ans: Loc(P[i][j]) = Base Address of (P) + W × [ M × (j – LC) + (i –LR)]
Loc(P[10][20]) = 6800 + 2 × [ 50 × (20 – 0) + (10 – 0)]
= 6800 + 2 × [1000 + 10]
= 6800 + 2 × 1010
= 6800 + 2020
= 8820

Q5. An array Arr[15][20] is stored in the memory along the row with each of the elements occupying 4 bytes.
Find out the base address and address of element Arr[3][2], if an element Array[5][2] is stored at location
1500. Delhi 2007
Ans: Loc(Arr[i][j]) = Base Address of (Arr) + W × [ N × (i – LR) + (j –LC)]
Loc(Arr[5][2]) = Base Address of (Arr) + 4 × [20 × (5 – 0) + (2 – 0)]
1500 = Base Address of (Arr) + 4 × [20 × (5 – 0) + (2 – 0)]
Base Address of (Arr) = 1500 – 4 × [100 + 2]
= 1500 – 4 × 102
= 1500 – 408
= 1092

Loc(Arr[i][j]) = Base Address of (Arr) + W × [ N × (i – LR) + (j –LC)]


Loc(Arr[3][2]) = 1092 + 4 × [20 × (3 – 0) + (2 – 0)
= 1092 + 4 × 62
= 1092 + 248
= 1340

You might also like