سوال ۶۸ کنکور ارشد علوم کامپیوتر ۱۳۹۷
اگر در ذخیرهسازی یک ماتریس آدرس خانهی برابر و آدرس خانهی برابر باشد (در مبنای ۱۶)، آنگاه ذخیرهسازی ماتریس به چه صورتی است؟
پاسخ صحیح: گزینهٔ D — row major
We are given two cell addresses that share the same column index () and differ in the row index ( vs ):
The step taken when the row index increases by one (column fixed) is
Two storage orders for a 2-D matrix. Let the element size be and the number of columns be .
| Order | stride to move one row down (fixed ) | |
|---|---|---|
| row-major (C) | (a whole row) | |
| column-major (Fortran) | (one element) |
Moving from to advances by a full row width of bytes — i.e. one entire row ( elements of a small word size, e.g. ) is jumped over to reach the next row. Crossing one whole row when the first index changes is exactly the signature of row-major storage, where rows are laid out one after another and the first (row) index is the slow / outer index.
The round -byte boundaries () confirm that one row occupies bytes, so the matrix is stored row by row — i.e. row major.
Options 1 (hash) and 2 (random) are not contiguous addressing schemes for matrices and are ruled out immediately.
Correct answer: option 4, row major.
Pitfall: With only two cells sharing the column index, the -byte step is the row stride. A large stride when the first (row) index changes signals row-major; a one-element stride would have signaled column-major. Always ask which index moved before deciding the order.