CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ

Pages are 4 KB and a process has 3 frames. It runs `for (i = 0; i < 1024; i++) for (j = 0; j < 1024; j++) A[i][j] = 0;` on an int A[1024][1024] (4-byte ints, row-major, page-aligned), with code in a separate always-resident frame. About how many page faults occur, and how many if the loops are swapped (j outer, i inner)?

  1. A. 1024 and 1024
  2. B. 1024 and 1,048,576
  3. C. 1,048,576 and 1024
  4. D. 512 and 1,048,576

Correct answer: B. 1024 and 1,048,576

Each row is 4 KB, exactly one page. Row-major order faults once per row: 1024. Column order touches a new row (page) on every access, and 3 frames cannot hold 1024 rows, so nearly every one of the 2²⁰ accesses faults.

More Operating Systems questions

Exams that ask this topic