final-2003sp-sol

# final-2003sp-sol - Final Examination Computer Science 312...

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

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.

Unformatted text preview: Final Examination Computer Science 312, Cornell University 15 May 2003 Solutions 1. True/False [12 pts] (parts a–f; 4 points off for each wrong answer, 2 points off for each blank answer, minimum problem score 0.) (a) With copying garbage collection, half of the heap storage is unused while the program executes. True (b) SML infers that the term (fn(x,y)=>x, fn(x,y)=>y) has a type equivalent to (’a*’b->’a)*(’c*’d->’d) . True (c) The shortest-path algorithm does not work correctly in general if any edges of the graph have zero weight. False (d) A string searching algorithm that looks for a pattern string in a larger text string (for example, the Boyer-Moore algorithm) must examine each character of the text string to avoid missing an occurrence of the pattern string. False (e) The treap data structure simultaneously satisfies both the heap ordering invariant and the binary search tree invariant. True (f) In the environment model an expression of the form (fn x => e ) evaluates to an un- boxed value. False 2. Zardoz [15 pts] (parts a–b) For each of the following expressions, give an expression to replace the box , so that the entire containing expression evaluates to 42. (a) [7 pts] let val zardoz: (’a->’b->’a) * (string * int) = fun g(z: (’a->’b->’a) * (’b*’a)): ’a = let val (f, (m, n)) = z in f n m end in g(zardoz) + String.size (#1 (#2 zardoz)) end 1 Answer: (fn(x:’a) => fn(y:’b) => x, ("312", 39)) (fn(x:’a) => fn(y:’b) => x, ("", 42)) etc. (b) [8 pts] let fun zardoz (m: int -> int) (k: int) = if k > 13 then else m k - zardoz m (k + 1) in zardoz (fn i => i + 3) 12 end Answer: 43 3. Strings [8 pts] (parts a–b) Consider the following finite automaton: a b a c b Recall that a finite automaton accepts any strings consisting of the symbols traversed along the edges from the start state to an accept state. The start state is indicated by an incoming arrow and an accept state is indicated by a double circle. (a) [3 pts] Give three distinct strings that are accepted by this automaton. Answer: b , ac , abac (b) [5 pts] Give a regular expression that matches exactly the strings that the automaton accepts. Answer: b|a(ba)*c 4. Graphs [16 pts] (parts a–b) (a) [8 pts] Suppose that we have a simple priority queue implementation in which the queue is represented as a sorted list. Extracting the minimum element takes O (1) time, but inserting a new element or changing the priority of an existing element both take...
View Full Document

## This note was uploaded on 09/05/2008 for the course CS 312 taught by Professor Myers during the Spring '08 term at Cornell.

### Page1 / 7

final-2003sp-sol - Final Examination Computer Science 312...

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

View Full Document
Ask a homework question - tutors are online