1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Karolina [17]
7 months ago
12

and assuming main memory is initially unloaded, show the page faulting behavior using the following page replacement policies. h

ow many page faults are generated by each page replacement algorithm?
Computers and Technology
1 answer:
Svet_ta [14]7 months ago
4 0

FIFO

// C++ implementation of FIFO page replacement

// in Operating Systems.

#include<bits/stdc++.h>

using namespace std;

// Function to find page faults using FIFO

int pageFaults(int pages[], int n, int capacity)

{

   // To represent set of current pages. We use

   // an unordered_set so that we quickly check

   // if a page is present in set or not

   unordered_set<int> s;

   // To store the pages in FIFO manner

   queue<int> indexes;

   // Start from initial page

   int page_faults = 0;

   for (int i=0; i<n; i++)

   {

       // Check if the set can hold more pages

       if (s.size() < capacity)

       {

           // Insert it into set if not present

           // already which represents page fault

           if (s.find(pages[i])==s.end())

           {

               // Insert the current page into the set

               s.insert(pages[i]);

               // increment page fault

               page_faults++;

               // Push the current page into the queue

               indexes.push(pages[i]);

           }

       }

       // If the set is full then need to perform FIFO

       // i.e. remove the first page of the queue from

       // set and queue both and insert the current page

       else

       {

           // Check if current page is not already

           // present in the set

           if (s.find(pages[i]) == s.end())

           {

               // Store the first page in the

               // queue to be used to find and

               // erase the page from the set

               int val = indexes.front();

               

               // Pop the first page from the queue

               indexes.pop();

               // Remove the indexes page from the set

               s.erase(val);

               // insert the current page in the set

               s.insert(pages[i]);

               // push the current page into

               // the queue

               indexes.push(pages[i]);

               // Increment page faults

               page_faults++;

           }

       }

   }

   return page_faults;

}

// Driver code

int main()

{

   int pages[] = {7, 0, 1, 2, 0, 3, 0, 4,

               2, 3, 0, 3, 2};

   int n = sizeof(pages)/sizeof(pages[0]);

   int capacity = 4;

   cout << pageFaults(pages, n, capacity);

   return 0;

}

LRU

//C++ implementation of above algorithm

#include<bits/stdc++.h>

using namespace std;

// Function to find page faults using indexes

int pageFaults(int pages[], int n, int capacity)

{

   // To represent set of current pages. We use

   // an unordered_set so that we quickly check

   // if a page is present in set or not

   unordered_set<int> s;

   // To store least recently used indexes

   // of pages.

   unordered_map<int, int> indexes;

   // Start from initial page

   int page_faults = 0;

   for (int i=0; i<n; i++)

   {

       // Check if the set can hold more pages

       if (s.size() < capacity)

       {

           // Insert it into set if not present

           // already which represents page fault

           if (s.find(pages[i])==s.end())

           {

               s.insert(pages[i]);

               // increment page fault

               page_faults++;

           }

           // Store the recently used index of

           // each page

           indexes[pages[i]] = i;

       }

       // If the set is full then need to perform lru

       // i.e. remove the least recently used page

       // and insert the current page

       else

       {

           // Check if current page is not already

           // present in the set

           if (s.find(pages[i]) == s.end())

           {

               // Find the least recently used pages

               // that is present in the set

               int lru = INT_MAX, val;

               for (auto it=s.begin(); it!=s.end(); it++)

               {

                   if (indexes[*it] < lru)

                   {

                       lru = indexes[*it];

                       val = *it;

                   }

               }

               // Remove the indexes page

               s.erase(val);

               // insert the current page

               s.insert(pages[i]);

               // Increment page faults

               page_faults++;

           }

           // Update the current page index

           indexes[pages[i]] = i;

       }

   }

   return page_faults;

}

// Driver code

int main()

{

   int pages[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2};

   int n = sizeof(pages)/sizeof(pages[0]);

   int capacity = 4;

   cout << pageFaults(pages, n, capacity);

   return 0;

}

You can learn more about this at:

brainly.com/question/13013958#SPJ4

You might be interested in
1. row a statement you submit to get paid for a product or service 2. spreadsheet software used by many business professionals t
Ivenika [448]

Answer:

1. row a horizontal set of data in a spreadsheet  

2. spreadsheet software used by many business professionals to work with numbers  

3. data information that is stored  

4. template a file that serves as a starting point for a new document

5. function a built-in formula in a spreadsheet

6. invoice a statement you submit to get paid for a product or service

Explanation:

The correct matches have been mentioned in the answer section. Certainly, a row is the horizontal set of data is a spreadsheet. And other options are self-understood. And hence, it is self-explanatory.

6 0
3 years ago
What symbol do you use to choose a feature for your notes on Notion?
Mandarinka [93]

Answer:

The core element of notions is called blocks from where all the content bring forth. It has around fifty blocks.

Explanation:

Notion is the newest and fastest growing productivity tools for the recent memory. Notions has been reached out to the fight club meme status. When it is plain, it is easy to use and  start. But even after it many of the users have difficulty in using this tools when it comes to the powerful cases.

There are some steps through that one can start to use this tool for their productivity.

To built the blocks

To organize the notions.

To create the habit tracker

To move the pages in notions

Data base and the views.

Type / - type table - select online- full page

4 0
3 years ago
Choose the two main capabilities involved in visual literacy
andreyandreev [35.5K]

The two main capabilities involved in visual literacy are:

<span>1)   </span>Communication through use of visual elements.

<span>2)   </span>Interpret meaning from visual elements.

<span>Visual literacy is the capacity to decipher, arrange, and make significance from data displayed as a picture, broadening the importance of proficiency, which means understanding of a composed or printed content.</span>

7 0
2 years ago
What type of filtering software divides email messages that have been received into two piles, spam and non-spam and then analyz
Hunter-Best [27]

Answer:

Bayesian filtering

Explanation:

This is a type of filtering software that makes use of Bayesian logic to evaluate every incoming email that you receive, analyzing the header and content of the email to determinate if it is spam or not. It uses a preset of common words that are present in most spam emails, and it categorizes all received emails according to their probability to contain spam in trusted, or not trusted email. These categories are usually set by the user.

In short, Bayesian logic uses the knowledge acquired from past events to try to predict future events. Determinate the probability of success (from 0 to 100%) of a certain activity, according to the result of prior tests. It was first suggested in 1763 after the death of its creator Thomas Bayes, and it is widely spread across several different sciences such as programming, artificial intelligence, physics, etc.

6 0
3 years ago
If I have added new headings in my document and wanted to update my table of contents, what would I need to do to ensure the new
g100num [7]
<span>Select Update and choose Entire Table.</span>
4 0
3 years ago
Read 2 more answers
Other questions:
  • To go to a specific cell, press the function key
    9·1 answer
  • What is the purpose of inserting SmartArt in a Microsoft Office program? (1 point)
    11·2 answers
  • 1. How does inertia affect a person who is not wearing a seatbelt during a collision? 
    14·2 answers
  • (Statistics) Write a program that includes two functions named calcavg() and variance(). The calcavg() function should calculate
    10·1 answer
  • Allison’s computer is displaying a strange error message saying that Allison, who is an administrator, does not have access to a
    15·1 answer
  • How would you define the rule of thirds?
    11·1 answer
  • One form of online vandalism is ____ operations, which interfere with or disrupt systems to protest the operations, policies, or
    9·2 answers
  • Which control program flow options runs to the end of the code block and resumes the break mode at the statement that follows?
    12·1 answer
  • A specialized output device for producing charts, maps, and very high-quality drawings is
    5·1 answer
  • Imagine that your parents were starting a small business, and they wanted to upgrade their data storage. Would you recommend a f
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!