final-2005sp-sol

final-2005sp-sol - CS312 Final Exam Cornell University...

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

View Full Document Right Arrow Icon
CS312 Final Exam Cornell University, Spring 2005 May 17, 2005 Solutions 1. True/False [20 pts] (parts a–j) Each correct answer is 2 pts; each wrong answer is -2 pts; and each blank answer is 0 pts. (a) Software testing proves the presence of bugs, but cannot prove their absence. True (b) The type that SML infers for the expression fn (x,y) => fn x => (y,x) is: ’a * ’b -> ’c -> ’b * ’c . True (c) The function f ( n ) = lg( n lg n ) is O (lg n ). True (d) At each collection, a copying collector must traverse all of the data in the program (including data unreachable from the roots). False (e) The implementation of Dijkstra’s shortest-paths algorithm requires a stack data struc- ture. False (f) The function foldl is tail-recursive. True (g) It is possible that a hash table with n elements and a load factor of 2 has a bucket that contains all of the n elements. True (h) When a program exhibits temporal locality, it will access the same memory location in the near future. True (i) Any lookup operation in a splay tree with n nodes is O (lg n ). False (j) Data races can occur during the execution of message-passing concurrent programs. False 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
2. Sets [20 pts] (parts a–c) The following is a standard set interface: signature SET = sig (* A ’a set is a set of items of type ’a. *) type ’a set (* empty is the empty set *) val empty : ’a set (* add(s,e) is s union {e} *) val add: ’a set * ’a -> ’a set (* fold over the elements of the set *) val fold: (’a*’b->’b) -> ’b -> ’a set -> ’b end (a) [5 pts] Extend the interface with a function remove that removes an item from a set. Provide a signature and a speciFcation for remove . DeFne an appropriate exception if necessary. Answer: exception NotFound (* remove (s,e) is the set s - {e} *) * Raises: NotFound if e does not belong to s *) val remove: ’a set * ’a -> ’a set (b) [7 pts] Write an implementation for function remove using the other functions in the signature. Assume that an equality funtion for items equal’:’a*’a->bool is also available ( ’a being the type of the items in the set). Your function remove should not visit any of the items more than once.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

final-2005sp-sol - CS312 Final Exam Cornell University...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online