CS 202 Fall 2010: Assignment 7

Homework Assignment #7 : Due Friday 11/12 Before Lecture

The purpose of this assignment is to explore the Binary Search algorithm and a page replacement algorithm used by the Operating System.

Part 1: Binary Search

The following script implements a binary search; it is similar (but not identical) to the code that was shown in class. It has access to several variables and one list named Valuable Numbers. The function round x will round the number x to the nearest integer; numbers such as 6.5 are rounded up to 7.0.

  1. One of the advantages of a a binary search over a linear search is that it is generally faster, requiring only O(log N) operations instead of O(N). What does the variable N correspond to in the above script?
  2. Does this Binary Search script make any assumptions about the List of Valuable Numbers? If so, what assumptions? Will the code work for all possible Lists of numbers or won’t it?

  3. What variables (and lists) are used as inputs to the Binary Search script? Briefly describe the purpose of each input variable.

  4. What variables (and lists) are (most likely) outputs from the Binary Search script? Briefly describe the purpose of each output variable.

  5. Imagine the List Valuable Numbers contains the following 16 elements:
    Index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
    Contents 6 10 28 51 88 105 113 166 200 210 211 239 280 316 364 373

    Consider running the script searching for the following values of Key.

    1. Key = 28
    2. Key = 210
    3. Key = 364
    4. Key = 290
    For each of the values of Key create a table like the one below showing the values of the designated variables at the end of each iteraction of the repeat until loop.
    Loop # index item greater? lo hi Key Index
    1            
    2            
    3            
    4           `  
    5            

Part 2: Replacement Algorithms

Imagine you are running on a machine that can fit only 4 items in main memory, but you are running applications that access items A, B, C, D, E, and F. Assume that these 4 pages initially contain pages B, C, A, and D as shown.
  1. Given the following reference stream, if the OS uses the OPTIMAL replacement algorithm, what will be the contents of memory after each access? Indicate whether each request leads to a hit or a miss in main memory.
    Access Page 1 Initial: B Page 2 Initial: C Page 3 Initial: A Page 4 Initial: D Hit or Miss?
    A          
    B          
    C          
    D          
    B          
    C          
    D          
    E          
    B          
    C          
    D          
    E          
    F          
    E          
    F          
    C          
    A          
    D          
    C          
    B          
  2. Given the following reference stream, if the OS uses the Least-Recently-Used (LRU) replacement algorithm, what will be the contents of memory after each access? Indicate whether each request leads to a hit or a miss in main memory.
    Access Page 1 Initial: B Page 2 Initial: C Page 3 Initial: A Page 4 Initial: D Hit or Miss?
    A          
    B          
    C          
    D          
    B          
    C          
    D          
    E          
    B          
    C          
    D          
    E          
    F          
    E          
    F          
    C          
    A          
    D          
    C          
    B          

    Turning in Your Work

    You may either turn in a written version of your homework before lecture on Friday or upload a copy to Folder Homework 7 through Learn@UW.

Menu

Fall 2010
Time: MWF 9:55-10:45
Room: 105 Psychology
Lab: 1370 CS (1st floor)


Instructor:
Prof Andrea Arpaci-Dusseau
Office Hours Tue 2:30-3:30, Wed 11-12
Office: 7375 Computer Sciences
Email: dusseau "at" cs.wisc.edu

  • CS202 Home
  • TAs and Lab Hours
  • Lecture Schedule w/ Slides
  • Grading
  • Homeworks
  • Projects
  • Exams
  • Scratch Examples
  • Readings
  • Computing Resources
  • Outreach Opportunity

  • Interesting Links
  • Scratch
  • UW Computer Sciences Dept