This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 373: Combinatorial Algorithms, Fall 2000 Homework 1 (due September 12, 2000 at midnight) Name: Net ID: Alias: U 3 / 4 1 Name: Net ID: Alias: U 3 / 4 1 Name: Net ID: Alias: U 3 / 4 1 Starting with Homework 1, homeworks may be done in teams of up to three people. Each team turns in just one solution, and every member of a team gets the same grade. Since 1unit graduate students are required to solve problems that are worth extra credit for other students, 1unit grad students may not be on the same team as 3/4unit grad students or undergraduates. Neatly print your name(s), NetID(s), and the alias(es) you used for Homework 0 in the boxes above. Please also tell us whether you are an undergraduate, 3/4unit grad student, or 1unit grad student by circling U, 3 / 4 , or 1, respectively. Staple this sheet to the top of your homework. Required Problems 1. Suppose we want to display a paragraph of text on a computer screen. The text consists of n words, where the i th word is p i pixels wide. We want to break the paragraph into several lines, each exactly P pixels long. Depending on which words we put on each line, we will need to insert different amounts of white space between the words. The paragraph should be fully justified, meaning that the first word on each line starts at its leftmost pixel, and except for the last line , the last character on each line ends at its rightmost pixel. There must be at least one pixel of whitespace between any two words on the same line. Define the slop of a paragraph layout as the sum over all lines, except the last , of the cube of the number of extra whitespace pixels in each line (not counting the one pixel required between every adjacent pair of words). Specifically, if a line contains words i through j , then the amount of extra white space on that line is P j + i j k = i p k . Describe a dynamic programming algorithm to print the paragraph with minimum slop. CS 373 Homework 1 (due 9/12/00) Fall 2000 2. Consider the following sorting algorithm: STUPIDSORT ( A [0 .. n 1]) : if n = 2 and A [0] > A [1] swap A [0] A [1] else if n > 2 m 2 n/ 3 STUPIDSORT ( A [0 .. m 1]) STUPIDSORT ( A [ n m .. n 1]) STUPIDSORT ( A [0 .. m 1]) (a) Prove that STUPIDSORT actually sorts its input. (b) Would the algorithm still sort correctly if we replaced the line m 2 n/ 3 with m 2 n/ 3 ? Justify your answer. (c) State a recurrence (including the base case(s)) for the number of comparisons executed by STUPIDSORT. (d) Solve the recurrence, and prove that your solution is correct. [Hint: Ignore the ceiling.] Does the algorithm deserve its name? (e) Show that the number of swaps executed by STUPIDSORT is at most ( n 2 ) ....
View
Full
Document
This note was uploaded on 12/15/2009 for the course 942 cs taught by Professor A during the Spring '09 term at University of Illinois at Urbana–Champaign.
 Spring '09
 A

Click to edit the document details