{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm2sols

# midterm2sols - UC Berkeley-CS 170 Lecturer Satish Rao...

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

UC Berkeley—CS 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

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

View Full Document
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 D edges. Since the min cut equals the max flow, the min cut is m/D . Therefore, we are guaranteed to find a cut with at most m/D edges.

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern