CS FundamentalsVery hardGATE CS (PYQ pattern)

Arrays A and B are 128 x 128 int matrices stored row-major, 4-byte ints, 512-byte pages (each row occupies exactly one page, A and B page-aligned). The code is: for (i=0;i<128;i++) for (j=0;j<128;j++) B[j][i] = A[i][j]; (read A[i][j] first, then write B[j][i]). Only 3 frames are available for the data (code is elsewhere), managed by LRU, all initially empty. How many data page faults occur?

  1. A. 32768
  2. B. 256
  3. C. 16512
  4. D. 16384

Correct answer: C. 16512

Each i-iteration reads one row of A (page i, 1 fault per i) but writes column i of B: B[j][i] touches page j for j = 0..127, a cycle of 128 pages with only 2 frames left, so every one of the 16384 B-accesses faults. Total = 16384 + 128 = 16512.

More Operating Systems questions

Exams that ask this topic