{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
CS 473: Algorithms, Fall 2010 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.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern