QuestionQuestion

In this assignment you are required to implement the following page replacement algorithms -
(1) Most Recently Used (MRU), where if memory is full the victim page chosen is the one that was most recently used
(2) Least Frequently Used (LFU), where if memory is full the victim page chosen is the one that was least frequently used
The starter code file is given to you in the file Assignment4_starter_file.py
The Least Recently Used (LRU) algorithm is implemented in this script.
DO NOT modify any function names or function arguments, or any of the fully defined functions. Your task is to write the code for the two functions - run_mru and run_lfu. Currently these functions do not do much - they just return the value 0. You also should not need to modify the tester function test_all_funcs unless there is a good reason to do so.
The three test cases as given below with different maximum number of frames are supposed to produce the following outputs for a given reference string when the two functions are correctly implemented -
********************************************************************************
Reference string: [5, 3, 5, 5, 5, 1, 3, 5, 3, 2, 4, 3, 5, 1]
Maximum number of frames in memory: 2
Number of page faults from LRU: 10
Number of page faults from MRU: 9
Number of page faults from LFU: 8
********************************************************************************

********************************************************************************
Reference string: [5, 3, 5, 5, 5, 1, 3, 5, 3, 2, 4, 3, 5, 1]
Maximum number of frames in memory: 3
Number of page faults from LRU: 7
Number of page faults from MRU: 6
Number of page faults from LFU: 6
********************************************************************************

********************************************************************************
Reference string: [5, 3, 5, 5, 5, 1, 3, 5, 3, 2, 4, 3, 5, 1]
Maximum number of frames in memory: 4
Number of page faults from LRU: 6
Number of page faults from MRU: 5
Number of page faults from LFU: 6
***************************************************************************

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

# runs the least recently used algorithm
def run_lru(rs, mnf): # rs = reference string, mnf = maximum number of frames in memory
    faults = 0         # number of page faults
    pagenums = set(rs) # unique page numbers in reference string
    frames = mnf*[-1] # initialize frames list, -1 means free frame
    page_data = {}    # dictionary to keep data on each resident page
    for t,r in enumerate(rs): # t is time and r is page reference
       if not(r in frames):
            if -1 in frames:
                frames[ frames.index(-1) ] = r
            else:
                victim_page = min(page_data, key=page_data.get)
                frames[ frames.index(victim_page) ] = r
                del page_data[victim_page]
            faults += 1
       page_data[r] = t

    return faults

# runs the most recently used algorithm
def run_mru(rs, mnf):
    faults = 0...

By purchasing this solution you'll be able to access the following files:
assignment4_starter_file.py.

$25.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats