midterm2sols - UC BerkeleyCS 170 Midterm 2 Lecturer: Satish...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: UC BerkeleyCS 170 Midterm 2 Lecturer: Satish Rao April 21, 2008 Midterm 2 for CS 170 Print your name: , (last) (first) Sign your name: Write your section number (e.g., 101): Write your SID: One page of notes is permitted. No electronic devices, e.g. cell phones and calculators, are permitted. Do all your work on the pages of this examination. If you need more space, you may use the reverse side of the page, but try to use the reverse of the same page where the problem is stated. You have 80 minutes. The questions are of varying difficulty, so avoid spending too long on any one question. In all algorithm design problems, you may use high-level pseudocode. DO NOT TURN THE PAGE UNTIL YOU ARE TOLD TO DO SO. Problem Score/Points Name/Section/etc. /2 1 /14 2 /20 3 /40 4 /24 Total /100 Date: April 21, 2008 2 Figure 1: Counter example for 1(c). Greedy set cover algorithm would choose { 9, 1, 3, 5, 7 } . However, the optimal set cover is { 2, 4, 6, 8 } . 1. True or false (2 points each, 14 points total). No negative points for wrong answers. If it is true give a short justification. If it is false give a counterexample. (a) (TRUE or FALSE) In a Huffman encoding scheme, if all characters occur with fre- quency less than 1/3, then there is guaranteed to be no codeword of length 1. Answer: True Justification: Suppose this is not the case. Let x be a node corresponding to a single character with p ( x ) < 1 / 3 such that the encoding of x is of length 1. Then x must not merge with any other node until the end. Consider the stage when there are only three leaves - x,y and z left in the tree. At the last stage y,z must merge to form another node so that x still corresponds to a codeword of length 1. But, p ( x )+ p ( y )+ p ( z ) = 1 and p ( x ) < 1 / 3 implies p ( y ) + p ( z ) > 2 / 3. Hence, at least one of p ( y ) or p ( z ), say p ( z ), must be greater than 1 / 3. But then these two cannot merge since p ( x ) and p ( y ) would be the minimum. This leads to a contradiction. (b) (TRUE or FALSE) In a Huffman encoding scheme, if all characters occur with fre- quency less than 2/5, then there is guaranteed to be no codeword of length 1. Answer: False Counter exmaple: (0.39, 0.39, 0.22), the corresponding huffman coding length is (1, 2, 2). (c) (TRUE or FALSE) The greedy set cover algorithm (which repeatedly chooses the largest set) gives the optimal set cover. Answer: False Counter example: In Figure 1, greedy set cover algorithm would choose { 9, 1, 3, 5, 7 } . However, the optimal set cover is { 2, 4, 6, 8 } . (d) (TRUE or FALSE) If s and t are at least D hops apart (i.e. every path from s to t has at least D edges), then there is an s t cut with at most m/D edges, where m is the number of edges. Date: April 21, 2008 3 Answer: True Justification: Let each edge have a capacity of 1 and consider the max flow from s to t . The max flow is equal to the number of DISJOINT paths from s to t (since all paths have capacity 1), which is at most m/D since all paths must have at least...
View Full Document

Page1 / 9

midterm2sols - UC BerkeleyCS 170 Midterm 2 Lecturer: Satish...

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

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