*This preview shows
pages
1–6. Sign up to
view the full content.*

This ** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This ** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This ** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
**Unformatted text preview: **Preliminary Examination II Computer Science 312, Cornell University 15 April 2008 1 1. Cookie [2 pts] What kind of cookie did you take? 2 2. True/False [14 pts] (parts ag) a. The adjacency matrix representation of a graph with N nodes (vertices) and E edges takes O ( N ) space. b. Mutators have observable side effects. c. Closed hashing exhibits poor performance when is close to 1. d. Suppose we resize hash tables by growing the array by a constant amount, rather than by doubling. Then the amortized asymptotic performance of inserting one element into the hash table would be O ( n ) in the number of elements, rather than O (1) . e. According to the red-black tree invariant, the smallest number of nodes that will guarantee the tree contains a red node is 4. f. Red-black trees have a representation invariant that is strictly stronger than that of binary search trees. g. Amortized worst-case performance cannot be worse than (nonamortized) worst-case performance. 3 3. The Zardoz Imperative [10 pts] Give a value that causes the expression to evaluate to 42 if the box is replaced by that value. Your answer may not contain any integer constants. let datatype mlist = Nil | Cons of int * (mlist ref) val cells: mlist = Cons(20, ref(Cons(21, ref(Cons(23, ref Nil))))) (* the value for refrobulate may not contain any integer constants. *) val refrobulate: mlist -> unit = in refrobulate cells; case cells of Cons (n1, c1) => (case !c1 of Cons (n2, c2) => (case !c2 of Cons (n3, c3) => n2 + n3 | Nil => 0) | Nil => 0) | Nil => 0 end 4 4. Asymptotic complexity [24 pts] (parts ac) A matrix is a two-dimensional array of numbers. Two square matrices with n elements on a side each contain n 2 elements. The conventional algorithm for multiplying two square matrices of sizeelements....

View Full
Document