Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the following program structure, how many page faults for Program 1 and Prog

ID: 3830022 • Letter: F

Question

For the following program structure, how many page faults for Program 1 and Program 2 respectively? Explain your calculation and results.

int A [ ][ ] = newint [1024] [1024];

Each row is stored in one page. The toal memory space for this process is 4 frames.

Prgram 1

for(j=0;j< A.length;j++)

   for (i=0;i<A.length;i++)

   A[ i,j] = 0;

Program 2

for(i=0;i< A.length;i++)

   for (j=0;j<A.length;j++)

   A[ i,j] = 0;

Answer for program 1 is 1024*1024, for program 2 is 1024

I need full explanation!! Please help!!

Explanation / Answer

Please find the below calculations for each of the programs.

program 01:

int A [ ][ ] = newint [1024] [1024];

for(j=0;j< A.length;j++)

   for (i=0;i<A.length;i++)

   A[ i,j] = 0;

Output: 1024*1024

Calculations stats: The above program starts with the [j] array and its a column again and this loop continues untill it increments the row of [1024].

So two page will constitute of [1024] - row 1 and column 1[1024].

Program 02:

for(i=0;i< A.length;i++)

   for (j=0;j<A.length;j++)

   A[ i,j] = 0;

Output: [1024] - row1

Calculation stats: if we observe for loop the looping starts from row[1024] and it does not go to the second the loop and it terminates so the outer loop output is printed since the calculation does not match from row to column and remember if we want to have a calculation then the j column has to be decremented.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote