2008 fall final solutions - Final Examination Computer...

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

View Full Document Right Arrow Icon
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 efficient 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 B-tree, every leaf node is at the same depth. T 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. Data structures [20 pts] (parts a–f) (a) [6 pts] Draw an example of a valid 6-node red-black 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 red-black tree can contain? Answer: This problem was easier than intended. The smallest a red-black 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 red-black tree can contain as a function of tree height. (d) [6 pts] Suppose a splay tree starts in the configuration shown here, and the element 312 is accessed. Show the tree that results after each rotation that occurs.
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 / 5

2008 fall final solutions - Final Examination Computer...

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