2008 spring prelim 2 solutions

# 2008 spring prelim 2 solutions - Preliminary Examination II...

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

Preliminary Examination II Computer Science 312, Cornell University 15 April 2008 Solutions This exam seems to have been tougher than the ﬁrst one. The smoothed histogram of scores looked like this: 0 20 40 60 80 100 0 0.2 0.4 0.6 0.8 1 1. Cookie [2 pts] 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
What kind of cookie did you take? 2. True/False [14 pts] (parts a–???) (a) The adjacency matrix representation of a graph with N nodes (vertices) and E edges takes O ( N ) space. False (b) Mutators have observable side effects. True (c) Closed hashing exhibits poor performance when α is close to 1. True (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) . True (e) According to the red-black tree invariant, the smallest number of nodes that will guarantee the tree contains a red node is 4. False: it’s 2 (f) Red-black trees have a representation invariant that is strictly stronger than that of binary search trees. True (g) Amortized worst-case performance cannot be worse than (nonamortized) worst-case performance. True 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 2
Answer: fn lst => case lst of Cons (n1, c1) => case !c1 of Cons(n2, c2) => c2 := !c1 or: fn lst => case lst of Cons(n1, ref(c1 as Cons(n2,c2)) => c2 := !c1 or even: fn Cons(n1, ref(c1 as Cons(n2,c2)) => c2 := !c1 4. Asymptotic complexity [24 pts] (parts a–???) 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 size n takes Θ( n 3 ) time. However, there is an asymptotically more efﬁcient algorithms, and in fact, a tight lower bound on the complexity of matrix multiplication is unknown. In

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 01/22/2010.

### Page1 / 6

2008 spring prelim 2 solutions - Preliminary Examination II...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online