Open In App

Algorithms Quiz | Sudo Placement [1.5] | Question 9

A matrix M(3 × 5) is to be stored in column-major order in a computer. If the base address of the matrix is 1000 and the size of each element is 4 bytes, then what will be the address of M(2, 3)?

(A) 1028
(B) 1188
(C) 1204
(D) 1220



(A)

1028



(B)

1188

(C)

1204

(D)

1220


Answer: (C)
Explanation:

To store a 3 × 5 matrix in column-major order, we store all the elements of the first column first, followed by the second column, and so on. Therefore, to find the address of M(2, 3), we need to calculate the number of bytes required to store the elements that come before M(2, 3) in the column-major order.

Since each element is of size 4 bytes, each column will require 3 × 4 = 12 bytes of space. Therefore, the first column will be stored from address 1000 to 1000 + 11 × 4 = 1044, the second column will be stored from 1044 + 4 = 1048 to 1048 + 11 × 4 = 1084, and the third column will be stored from 1084 + 4 = 1088 to 1088 + 11 × 4 = 1124.

Now, to find the address of M(2, 3), we need to calculate the number of bytes required to store the elements that come before M(2, 3) in column-major order. The first two columns together require 2 × 12 = 24 bytes, and the first three rows of the third column require 3 × 4 × 3 = 36 bytes. Therefore, the total number of bytes required to store the elements that come before M(2, 3) is 24 + 36 = 60.

Adding this offset to the base address of 1000 gives us the address of M(2, 3), which is 1000 + 60 = 1060 in decimal or 0x424 in hexadecimal. However, since the elements are stored in column-major order, we need to swap the row and column indices to get the correct index in memory. Therefore, the address of M(2, 3) is actually 1060 + 2 × 4 = 1068 or 0x42C in hexadecimal.

Hence, the correct answer is option (C) 1204, which is incorrect and not supported by the above calculation.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Article Tags :