hw_5_soln - CS 473: Algorithms, Fall 2010 HW 5 (due...

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

View Full Document Right Arrow Icon
HW 5 (due Tuesday, October 12) This homework contains four problems. Read the instructions for submitting homework on the course webpage . In particular, make sure that you write the solutions for the problems on separate sheets of paper; the sheets for each problem should be stapled together. Write your name and netid on each sheet. Collaboration Policy: For this home work, Problems 1-2 can be worked in groups of up to 3 students each. Problem 0 should be answered in Compass as part of the assessment HW5-Online and should be done individually. 0. (10 pts) HW5-Online. 1. (30 pts) In a word processor the goal of “pretty-printing” is to take text with a ragged right margin, like this, Call me Ishmael. Some year ago, never mind how long precisely, having little or no money in my purse, and nothing particular to interest me on shore, I though I would sail about a little and see the watery part of the world. and turn it into text whose right margin is as “even” as possible, like this Call me Ishmael. Some year ago, never mind how long precisely, having little or no money in my purse, and nothing particular to interest me on shore, I though I would sail about a little and see the watery part of the world. To make this precise enough for us to start thinking about how to write a pretty-printer for text, we need to figure out what it means for the right margins to be “even”. So suppose our text consists of a sequence of words , W = { w 1 , w 2 ,..., w n } , where w i consists of c i characters. We have a maximum line length of L . We will assume we have a fixed-width font and ignore issues of punctuation or hyphenation. A formatting of W consists of a partition of the words in W into lines . In the words assigned to a single line, there should be a space after each word except the last; and so if w j , w j + 1 ,..., w k are assigned to one line, then we should have h k - 1 X i = j ( c i + 1 ) i + c k L . We will call an assignment of words to a line valid if it satisfies this inequality. The difference between the left-hand side and the right-hand side will be called the slack of the line-that is, the number of spaces left at the right margin. 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
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/18/2011 for the course CS 473 taught by Professor Chekuri,c during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 4

hw_5_soln - CS 473: Algorithms, Fall 2010 HW 5 (due...

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

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