Review Sheet for the Midterm Exam


This review sheet is intended to help you study for the midterm exam. It is not intended to be an exhaustive list of everything we've covered, but it should help you identify the "big ideas". You should also review your lecture notes and the solutions to your homework problems.  The lecture "quizzes" are especially useful in helping you study for the exam.

You may bring to the exam a 8.5 by 11 sheet with your own writing (only) on both sides.

Study Topics

Foundations of functional programming with Racket!

Parsing and Evaluating a Language

Program Design

Data Structures and Algorithms

Digital Logic and Computer Architecture

Assembly Language Programming

Some Practice Problems

WARNING: This list of practice problems does not nearly cover the entire space of material you will be asked to know for the exam.  We provide it simply as an additional source in  your preparations (under the "something is better than nothing" principle).  THE BEST WAY TO PREPARE FOR THE EXAM IS TO REDO IN CLASS "QUIZ" PROBLEMS AND HOMEWORK PROBLEMS.  You should go on to the problems below only once you are sure you can do all the problems from classes and homeworks.
  1. Writing reduce in Racket! Recall the the foldr function in Racket takes as input three arguments: A function f of two variables, a unit (such that (f X unit) => X), and a list L. The foldr function returns the result of repeatedly applying the function f to the elements in L until to reduce them to a single value. For example,
     Scheme> (foldr (lambda (X, Y) (+ X Y)) 0 '(1, 2, 3, 4))
    10
    You should assume that foldr "associates" (orders operations) like this: 1 + 2 + 3 + 4 = 1 + (2 + (3 + (4 + 0))). (Notice that the 0 at the end is the unit for addition.) Write the foldr function from scratch. That is, your implementation my use Scheme's list notation and recursion, but no built-in functions. Notice that foldr should not be written exclusively to handle addition! It's first argument can be any function of two variables, its second argument is the unit for that function, and its third argument is a list of elements of the type operated on by the given function.

  2. Graph algorithms in Racket!

    You have been hired by Napquest, a company specializing in finding shortest paths between given cities. (It's called Napquest, because their algorithms tend to be inefficient, causing the users to nap while they wait for the answer!)

    A map is a list of "triplets", where each triplet is a list of the form [City1, City2, Distance]. City1 and City2 are just names of cities (e.g. they might be numbers or strings) and Distance is a positive real number indicating the length of the one-way road from City1 to City2. For example, here is a valid map: [ ["Claremont", "Spamville", 1], ["Spamville", "Claremont", 2], ["Spamville", "Foobarsburg", 2], ["Foobarsburg", "Claremont", 4] ]. Notice that the map may contain cycles and that there may be funny things like a one-way road from Claremont to Spamville which is shorter than the one-way road from Spamville to Claremont.

    Your job is write a program called tour which takes as input two things: The name of the start city, and an entire map. The function returns a boolean that indicates whether there is a path starting in the start city that tours all of the cities (it does not need to return to the start city).  

    The program need not be fast, but it must compute the right answer. For full credit, keep your code very short.  However you may find it easier to write a helper function.

  3. BTrees

    A BTree is a generalized form of a binary search tree that, similar to BSTs, allows fast (logarithmic time) access to data. In a BTree, each node stores a variable number of values--at least 1 and at most m-1, where m is said to be the "order" of the BTree, and the number of children that node has is determined by the number of values stored in that node.   The elements in each node have the following properties: 
    1. The items in each node are sorted.
    2. The items in each non-leaf node act as separators for the subtrees that originate at that node.  If a non-leaf node holds k items, it will have k+1 subtrees, all of which contain at least one non-empty node.
    3. All items in each subtree lie between the values of their separators.  E.g., if a subtree originates between the values 3 and 15, all values in that subtree will be greater than 3 and less than 15.  Subtrees to the far left (right) (separated only by a value on the right (left)) will contain values strictly less than (greater than) their separator.  

    See the Wikipedia page on BTrees for an example of a BTree with order 3.   http://en.wikipedia.org/wiki/B-tree.

    Your jobs here is to: (1) Devise a method of reprsenting BTrees of order m in Racket.  Be sure to clearly describe your representation and give an example of how your representation would represent the tree given in the example on Wikipedia and (2) using your representation, write a function in Racket for finding an element in a BTree of some order m.  Your function find(item, tree) should return #t if the element is in the BTree and #f if it is not.

    As a bonus challenge, consider implementing a function to insert an item into the tree.  Note, this is fairly difficult and much harder than what we would ask you  to do on an exam.  You'll find the algorithm for inserting into a BTree on the Wikipedia page above.

  4. Hmmmm

    Write a Hmmm program that faithfully implements the following Racket function.  (Note that we would provide you with a complete Hmmm instruction set if we were to ask you this problem).  


    (define (main)
    (let* ((x (get input from user))
    (y (get input from user))
    (result (foo x y)))
    (display result)))

    (define (foo x y)
    (let* (
    (z 2)
    (a (smallestfactor x z))
    (b (smallestfactor y z)))
    (if (> a b)
    x
    y)))

    (define (smallestfactor n f)
    (if (= 0 (mod n f))
    f
    (smallestfactor n (+ f 1))))
    In addition to being able to translate into Hmmm, make sure you can also answer questions about provided Hmmm code such as:
    1. Values in the registers as the code runs
    2. The maximum (minimum) value of the stack pointer
    3. The function of specific lines of code
    4. etc.