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]
10 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]10 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
How does the text recommend that a company operate if it wants to be successful in the information age?
Kryger [21]

Answer:

The answer is "Departmental interdependence".

Explanation:

In the given question some information is missing, that is an option, which can be described s follows:

A. Work independently across organizations.

B. Departmental interdependence.

C. As an individually small department or as a team.

D. Each organization functions as a separate business entity.

There are separate positions in each organization, but the departments can not actually interact with each other, in the hierarchical paradigm of interdependence and can not rely explicitly on each other, each division presents the same ultimate problem, and other choices were wrong, that is described as follows:

  • In option A, It is wrong because in the organization there are some protocol which will be followed by all.
  • Option C and Option D both are wrong because each organization's function is not separated by the business entity, and it is not small.
6 0
3 years ago
Convert the following numbers. (Please show all steps; no marks will be awarded if no steps are shown) [1.5 x 4 = 6 marks]
katen-ka-za [31]

Answer:

i. 10210212

ii. 100 101 001 in BASE 2

iii. 46.4631

iv. 12.453125

Explanation:

i. Converting to base 10 we get

=  10 x 162 + 13 x 161 + 9 x 160 = 2777

Converting to base 10 we get  =

2777/3 = 925 with remainder 2

925/3 = 308 with remainder 1

308/3 = 102 with remainder 2

102/3 = 34 with remainder 0

34/3 = 11 with remainder 1

11/3 = 3 with remainder 2

3/3 = 1 with remainder 0

1/3 = 0 with remainder 1

Hence the Answer is 10210212

ii. = Octal is taken in pair of 3 bits , Writing binary of each number in 3 bits we get  = 100 101 001 in BASE 2

iii. = 1 x 52 + 2 x 51 + 3 x 50 + 3 x 5-1   = 38.6 in decimal

Converting to Octal we get

38 /8 = 4 with remainder 6

4 /8 = 0 with remainder 4

.6 x 8 =  4.8

.8 x 8 = 6.4

46.4631

iv. = 1x 81 + 4 x 80 + 3 x 8-1 + 5 x 8-2   = 12.453125

Check here for Free courses about IT and Management www.eacademy.lk

4 0
3 years ago
X = 10<br> y = 20<br> x &gt; У<br> print("if statement")<br> print("else statement")
Ksenya-84 [330]

Answer:

n

Explanation:

n

5 0
3 years ago
Who else hates it when Edgenuity has technical problems with international students?
konstantin123 [22]

Answer: ya it sucks

AI used to be a A student until edgenuity had to be used.

Explanation:

7 0
3 years ago
An alternative to increasing the column widths and row heights is to ____ to fit the current width of the column
cupoosta [38]
It seems that you have missed the given options for this statement, but anyway, here is the correct answer. An alternative to increasing the column widths and row heights is to SHRINK THE CHARACTERS IN THE CELL to fit the <span> current width of the column. Hope this answer helps. </span>
4 0
3 years ago
Other questions:
  • Candace opened an email from a person she didn't know and clicked on a pop-up in the email that installed a virus on her compute
    8·2 answers
  • Write a program that uses a 2-D array to store the highest and lowest temperatures for each month of the year. The program shoul
    14·1 answer
  • The trigonometry book says: sin^2(t) + cos^2(t) = 1 Write a Python program that verifies the formula with the help of the Python
    11·1 answer
  • which one of the following word process feature saves you the most time when you keying in a document
    9·1 answer
  • Pleas help 99 points and get brainliest
    9·2 answers
  • What is the difference between a workbook and a worksheet?
    14·2 answers
  • What is keylogging attack?
    13·2 answers
  • Is a collection of information stored under a single nam​
    6·2 answers
  • Which is the purpose of adding B-Roll footage to a sequence?
    10·1 answer
  • I need help so bad it’s the entire test for EdHesive python coding Test 2
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!