CS 361: Assignments


  • Test #1 will be take-home; I will put it on the web on Tuesday, February 22; it will be due Wednesday, March 1, at the beginning of class. That way, there will be time for you to read the questions before the lab session and use the lab session to make sure that you understand what each question is asking. Material covered: asymptotic notation, recurrences, and the use of recurrences in analyzing programs.
    Get Test #1 now, in Postscript or PDF form.
    Solutions to Test #1 are available in Postscript or PDF form, as is a rough interpretive guide to the grades in Test #1.
  • Test #2 is now available. Solutions will be delayed due to incompletes; scores and a rough interpretive guide are available here.


  • Homework #1, due Wednesday, February 2
    Exercises 2.28, 2.29, 2.30, and 2.31 in the text (p. 48). Note that all four are closely related; thus you may want to write your answer in terms of comparisons between the four statements -- e.g., which one gives you the most information and which one gives you the least?
    Here are the problems: in all cases, you are given the information that the running time of one algorithm is something related to nlogn and that the running time of the other algorithm is something related to n3 and asked what that information implies about the relative performance of the two algorithms. The "related to" is as follows:
  • Homework #2, due Wednesday, February 9
    Exercises 2.23 and 2.24 in the text, plus two more below. Exercise 2.23 asks you to show that n log n is O(n1.5). Exercise 2.24 asks you to show that nk is O(cn) for any choice of constant c > 1. The first additional exercise is to solve exactly the recurrence relation f(n)=3f(n-1)-2f(n-2) with initial conditions f(0)=1 and f(1)=2. The second exercise is to give Theta() solutions for the following three recurrences:
     (i) f(n)=5f(n-1)-6f(n-2);
     (ii) f(n)=3f(n-1)+f(n-2)-3f(n-3); and
     (iii) f(n)=2f(n-1)+f(n-2).
    Solutions in Postscript or PDF format

  • Homework #3, due Monday, February 21
    Exercises 2.42, 2.43, 2.44 in the text; plus solve in Theta() terms the following recurrences:
     (i) f(n)=3f(n/2)+Theta(n);
     (ii) f(n)=4f(n-1)-4f(n-2)+n^2+2^n; and
     (iii) f(n)=2f(n/2)-f(n/4)+Theta(n);

    Solutions in Postscript or PDF format

  • Homework #4, due Monday, April 3
    Turn in a project proposal -- 1-2 pages describing what you want to study and what you expect to learn.

  • Homework #5, due Wednesday, April 12

    Problem 1. Consider the following variation for binary heaps. We want to be able to "age" all items in the heap, by decreasing (or increasing) all priorities by the same amount. Thus new items with "regular" priorities will fall into a different group from items that have been in the queue for quite a while. This kind of operation is particularly useful in scheduling applications. We could trivially do this in linear time by scanning the array from 1 to n and altering each priority field. But we can do it in CONSTANT time! Instead of storing absolute priority values at each node, we store relative priority values, specifically the difference between the node's assigned priority and that of its parent. Only the root, which does not have a parent, retains is absolute priority value. We can then "age" all items currently in the heap by altering the priority of the root.

    Give pseudocode for sift-up, sift-down, insert, and delete to verify that all four operations still run correctly and in logarithmic time.



    Problem 2. Consider the following variation on double hashing for keys that have a total ordering. When attempting to insert an item, x, into the table, we begin by hashing x with our first hash function h1; if location h1(x) is empty, we insert x there. If h1(x) contains some key y, however, instead of automatically bouncing to the next location in the probe sequence for x (which would be location h1(x)+h2(x) as used in double hashing), we first compare keys x and y; if x is the larger key, we bounce x, compute h2(x), and probe location h1(x)+h2(x); on the other hand, if x is the smaller key, we dislodge y, i.e., we insert x in location h1(x) and send y bouncing along its probe sequence, i.e, we next examine location h1(x)+h2(y). At every collision, we repeat the procedure, sending the larger key bouncing.

    Let the size of the table be n, the number of items in the table be k, and the loading factor be alpha=k/n.


    Solutions in Postscript or PDF format


  • Homework #6, due Monday, May 1

    Problem 1 Prove formally that every AVL tree is a red-black tree -- i.e., that every AVL tree can have its nodes colored in red or black such that (i) the root and the leaves are black; (ii) every red node has a black parent; and (iii) the number of black nodes is the same on each path from the root to a leaf. Hint: think of writing a program to do that; you may need to traverse the AVL tree more than once.

    Problem 2. Solve the Dutch national flag problem. You are given an array filled with elements that can take one of only 3 values: red, white, and blue; the goal is to return the array with all red elements on the left, all blue elements on the right, and all white elements in the middle. Your algorithm must run in linear time, can only exchange elements, and has just one additional variable to hold one of the elements -- in particular, it cannot use counters to count the number of elements of each color.
    Solutions are available.

  • Back to CS 361 home page