CS FundamentalsVery hardWipro · Cognizant technical pattern
int A[256][256] is stored in row-major order, and a page holds 512 ints (two rows). The process has only ONE frame for A, initially empty. How many page faults does this loop cause?
int A[256][256] is stored in row-major order, and a page holds 512 ints (two rows). The process has only ONE frame for A, initially empty. How many page faults does this loop cause?
for (j = 0; j < 256; j++)
for (i = 0; i < 256; i++)
A[i][j] = 0;- A. 32768
- B. 128
- C. 65536
- D. 256
Correct answer: A. 32768
The loop walks down a column. Rows i and i + 1 (for even i) share a page, so each column touches 128 pages, each faulting because the single frame was holding a different page: 128 × 256 = 32768. A row-wise loop would fault only 128 times; 65536 forgets that two rows share a page.
More Operating Systems questions
- Processes (times in ms): A (arrival 0, burst 9), B (arrival 1, burst 4), C (arrival 3, burst 6), D (arrival 5, burst 2), E (arrival 8…
- Processes (times in ms): A (arrival 0, burst 9), B (arrival 1, burst 4), C (arrival 3, burst 6), D (arrival 5, burst 2), E (arrival 8…
- Processes (arrival, burst, priority; a smaller number means higher priority): A (0, 9, 3), B (1, 4, 1), C (3, 6, 4), D (5, 2, 2), E (8, 5…
- Processes (arrival, burst) in ms: P1 (0, 6), P2 (2, 5), P3 (4, 2), P4 (5, 8), P5 (7, 3). They are scheduled by non-preemptive Highest…
- A multilevel feedback queue has Q0 (Round Robin, quantum 2), Q1 (Round Robin, quantum 4) and Q2 (FCFS). New processes enter Q0. A process…
- Three processes each run CPU burst, I/O burst, CPU burst (in ms): P1 arrives at 0 with 5, 4, 3; P2 arrives at 2 with 3, 6, 2; P3 arrives…