Every web browser and word processor needs a way of breaking English paragraphs into lines at word

Question:

Every web browser and word processor needs a way of breaking English paragraphs into lines at word boundaries that is both fast and looks good. Some systems even have ways of hyphenating words to make good line breaks, but let us ignore that complication here. Say that the width of each line on a computer screen or browser window is M characters, and we are given a list, 

W = (W1, W2,...,Wn), 


of n words forming a paragraph that we wish to display, where the word, Wi, has length, Li. The word wrapping problem is to break W into lines of length at most M in a way that minimizes a total cost penalizing the wasted space. The cost of breaking a single line to hold the words Wi, Wi+1,...,W, has the following cost: 

3 C(i, j) M – (j – i) –ELk k=i


assuming this cost is nonnegative. If this cost is negative, then we instead set C(i, j) = +∞, to show that the set of words from Wto Wdoesn’t fit on a single line. In addition, if this cost is positive, but j = n, then we set C(i, j)=0, to show that there is no wasted space in the last line of the paragraph. Describe an efficient algorithm for solving the word wrapping problem, so as to minimize the total cost of all the lines used to display the paragraph formed by the words W1,...,Wn. What is the running time of your algorithm?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Algorithm Design And Applications

ISBN: 9781118335918

1st Edition

Authors: Michael T. Goodrich, Roberto Tamassia

Question Posted: