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

Do the following problem with he following modification: You may use any of the

ID: 3764022 • Letter: D

Question

Do the following problem with he following modification: You may use any of the following languages for your program: C, C++, Java.                                                                                                                                           The random page-refrence string should consist of at least 10000 numbers. Using the same reference string, obtain the number of faults for each algorithm (FIFO and LRU) for each of the following number of page frames: 1, 2, 3, 4, 5, 6, 7, 8.    

Your solution is expected to be a complete program that runs to completion.

Plot a graph of page fault frequency (y-axis) versus number of page frames (x-axis). Draw both plots on the same graph. Label each plot by the algorithm identifer (FIFO, LRU). Note: it is not expected that your program will produce the plot; rather, a seperate application can be used to make the plot.                                                                                    

Write a Program that implements the FIFO and LRU page-replacement algorithms presented in his Chapter. First, generate a random page-refrence string where page numbers range from 0 o 9. Apply the random page-reference string to each algorithm, and record the number of page faults incurred by each algorithm. Implement the replacement algorithms so that the number of page frames can vary as well. Assume that depend paging is used.

Explanation / Answer

import java.io.*;

public class PageFault
{

BufferedReader pageFrames=new BufferedReader(new InputStreamReader(System.in));
int n, page[], size, noOfFrames[], faultNo, ;

public void InputValues()
{
System.out.println("Enter number of pages");
n=Integer.parseInt(pageFrames.readLine());
page=new int[n];
System.out.println("Enter number of page noOfFrames");
size=Integer.parseInt(pageFrames.readLine());
noOfFrames=new int[size];
}

void setToZero()
{
int key;
for(key=0;key<size;key++)
frames[key]=0;
faults=0;
}

void FIFOPageReplacementAlgo()
{
int item,key,value=0;
setToZero();   // Initialse it to 0 here
boolean search=false;
for(item=0;item<n;item++)
{
for(key=0;key<size;key++)
{
if(page[item]==noOfFrames[key])   //search for it in the page Frame
search=true;
}
if(search==false)  //if not found, simply add it to the frame
{
noOfFrames[value]=page[item];
if(value==size-1)
value=0;
else
value++;
faultNo++;
}
search=false;
}
System.out.println("Number of page faultNo = "+faultNo);
}

void LRUPageReplacementAlgo()
{
int item,key,duration[],max;
setToZero();
duration=new int[size];
boolean search=false;
for(item=0;item<n;item++)
{
for(key=0;key<size;key++)
duration[key]++;
for(key=0;key<size;key++)
{
if(page[item]==noOfFrames[key])
{
search=true;
duration[key]=0;
}
}
if(search==false)
{
max=0;
for(key=0;key<size;key++)
{
if(duration[key]>duration[max])
max=key;
}
noOfFrames[max]=page[item];
duration[max]=0;
faultNo++;
}
search=false;
}
System.out.println("Number of page faultNo = "+faultNo);

}

public static void main(String[] args) throws IOException
{
PageFault p=new PageFault();
p.InputValues();
FIFOPageReplacementAlgo();
LRUPageReplacementAlgo();
}
}

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