Where can I find an efficient algorithm for breaking lines of text for formatted display?
+4
A:
One approach to this very problem is addressed in the book Introduction to Algorithms (Cormen, Leiserson, Rivest, Stein) as problem 15-2.
It takes the approach that a nicely broken block of text has as even spacing at the end as possible, punishing large differences.
This problem is solvable using dynamic programming.
Naturally this is only one approach to the problem, but in my opinion it at least looks better than the greedy algorithm.
I'm not much for putting my solutions to textbook problems on the Internet, so I'll leave it to you to either solve it or Google for a solution, in order to get the exact algorithm needed.
Sebastian P.
2009-08-22 12:18:20