jrb47 0 Newbie Poster

Consider the two-dimensional array A:
int A[][] = new int[100][100]; // int is equal to size of the word
where A[0][0] is at location 200, in a paged system with pages of size 200. A small process is in page 0 (locations 0 to 199) for manipulating the matrix; thus, every instruction fetch will be from page 0. For three page frames, how many page faults are generated by the following array initialization loops, using LRU replacement, and assuming page frame 1 has the process in it, and the other two are initially empty:
a. for (int j = 0; j < 100; j++)
for (int i = 0; i < 100; i++)
A[j] = 0;
b. for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
A[j] = 0;
Answer: each page has length 200 bytes. Then one row fits in a page. a) 100, b) 100 * 100 = 10,000

QUESTION What happens if we change the algorithm to
a. for (int j = 0; j < 50: j++)
for (int i = 0; i < 50; i++)
A[j] = 0;
b. for (int i = 0; i < 50; i++)
for (int j = 0; j < 50; j++)
A[j] = 0;
does the answer become:
Answer: each page has length 200 bytes. Then one row fits in a page. a) 50, b) 50 * 50 = 2500

I am having trouble understanding this algorithm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.