Final Examination
Computer Science 3110, Cornell University
18 December 2008
Solutions
Overall, students did very well on the exam. The smoothed histogram of scores looked like this (vertical axis is
number of students per unit score):
The median was ??.
1.
True/False
[16 pts]
(parts a–h)
(parts a–h; 2 points off for each wrong answer, 1 point off for each blank answer)
(a) In OCaml, when a function is applied to an argument of the wrong type, the compiler may insert implicit
conversions to the right type.
F
(b) On very long lists, rather than use
List.fold
right
, it is more efﬁcient to reverse the list using
List.fold
left
and then to apply
List.fold
left
to the reversed list.
T
(c) The following is valid OCaml code:
let () = () in ()
.
T
(d) Branch coverage is achieved for an algorithm when it is tested on all paths to the leaves of a tree data
structure.
F
(e) When testing a function with a Checks clause, tests should be included that violate the Checks clause.
T
(f) Message passing supports both synchronization of concurrent threads and transfer of data between threads.
T
(g) Hash tables have good locality when properly implemented.
F
(h) In a Btree, every leaf node is at the same depth.
T
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2.
Data structures
[20 pts]
(parts a–f)
(a) [6 pts]
Draw an example of a valid 6node redblack tree that is as high as possible. The tree elements
should be integers.
Answer:
2(B)
1(B)
4(R)
3(B)
5(B)
6(R)
(b) [2 pts]
Give an example of an element which will result in balancing operations if it is added to the tree
you gave in 2(a).
Answer:
7, because its parent (6) is red.
(c) [0 pts]
Karma problem
: As a function of the black height BH, what is the smallest number of nodes a
redblack tree can contain?
Answer:
This problem was easier than intended. The smallest a redblack tree can be is when it’s all black, in
which case it has
2
BH

1
nodes. The more interesting question is the smallest number of nodes a
redblack tree can contain as a function of tree height.
(d) [6 pts]
Suppose a splay tree starts in the conﬁguration shown here, and the element 312 is accessed.
Show the tree that results after each rotation that occurs.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 Computer Science, pts, hash function, Cryptographic hash function

Click to edit the document details