Sunday, 8 November 2015

UGC-NET Computer Science Data Structures Questions with Explanation

In this Blog we are providing all the UGC-NET Computer Science previous year Questions with explanation:

Q : 4 Consider an array A[20, 10], assume 4 words per memory cell and the base address of
 array A is 100. What is the address of A[11, 5] ? Assume row major storage.

(A) 560

(B) 565
(C) 570

(D) 575

(UGC-NET Computer Science December 2014)


Answer: (A)

Explanation:

In computers memory the array elements are always stored linearly whether they are 1-Dimensional or 2-Dimensional. Like this is an example of 2-Dimensional array stored in memory linearly:





As we can see element A11 is stored at location '0' in memory and it is known as its offset.
Step 1:
Now to calculate the offset in case of Row major order we will use the formula:
Offset = (Row No. * Total No. of Columns) + Column No.

Now to calculate the offset in case of Column major order we will use the formula:
Offset = (Column No. * Total No. of Rows) + Row No.

'Row No.' is the row number of the location whose address we need to calculate.
'Column No.' is the column number of the location whose address we need to calculate.
'Total No. of Columns' is the total number of columns in the given matrix.
'Total No. of Rows' is the total number of rows in the given matrix.

Step 2:

Multiply the offset calculated with the size of each memory word.

Step 3:

Add the Base address to calculate the effective address.

Given matrix is A[20][10], Size of memory word is 4 bytes, address of the location to find A[11][5], Base address is 100.

Step 1:
Offset = (11 * 10) + 5 = 115.
Step 2:
115 * 4 = 460.
Step 3:
100 + 460 = 560.

So, correct option is (A) 560.

This Question was taken from UGC-NET Computer Science December 2014.

No comments:

Post a Comment