Algorithms: Pretty Printing
Posted by Christopher Wojno Fri, 09 Nov 2007 06:21:00 GMT
I’ve been up and down the Internet looking for a good solution to the “Pretty Printing” problem. I was dismayed by the lack of readily indexed solutions. So! If you’re looking to solve this one, I’m here to point you in the right direction.
Problem Description
Given a set of W words, form a list of lines such that the sum of the slack of the characters in a line L (column s- character count = Slack) squared (some implementations cube this, the algorithm is the same), is minimized.
Most problems include that there must be 1 space between every word (except those which do not share the same line) and those spaces must be included in that slack value calculation. Regardless:
The Problem Type
This problem a subset of Dynamic Programming problems known as “Mutli-way Choices.” A similar, but less sophisticated version of this problem is the “Segmented Least Squares” problem.
I’m not going to attempt to solve the problem for fear I will make myself the fool. Maybe I’ll do it later and post it here again when I’m confident in my answer. The important part is you now know how to look for answers. Admittedly, even armed with this information, you’ll still get some pretty shady results. But I found some decent material with this google query . You should be able to construct a cogent answer with a Least Squares example.
Good luck! Happy algorithms!
