Theoremadvanced
NP-completeness of pagination with figures
Also called Plass pagination hardness.
Pagination with figures that may change order is strongly NP-complete for the total distance from figures to their references, by reduction from 3-partition.
When figures may float to any page after their reference and may change their order, finding a pagination with a small total distance from the figures to their references is NP-complete. The hard part is not the text but the packing of the figures into the space that the pages leave, which is a form of bin packing. The reduction below is from 3-partition, so the problem is NP-complete in the strong sense: it stays hard when all heights are small integers. When the figures must keep their order, optimal pagination solves the problem in polynomial time by dynamic programming.
Statement
Pagination with free figures (decision form). The input is text lines with heights , figures with heights , for each figure the line that refers to it, a page height and a bound , all nonnegative integers. A pagination is a sequence of nonempty pages, where each page holds a block of consecutive lines (possibly empty) and any set of figures, such that:
- the lines appear in their order, each on one page, and each figure is on one page;
- the total height of the lines and figures on each page is at most ;
- figure is on the page of line or on a later page.
Write for the page number of figure and for the page number of line . The question is whether there is a pagination with
Theorem. Pagination with free figures is strongly NP-complete.
In plain words
Suppose a page of text mentions many pictures, and all of them must come after it. Each later page has room for only a few pictures, and a picture costs more the further it is from the text.
To keep the cost low, the first pages after the text must be packed full of pictures with no gap. Deciding whether the pictures can be grouped to fill pages exactly is a hard puzzle, the same as splitting numbers into groups with equal sums. So no fast method is known for the whole problem.
Proof
Membership in NP. A certificate is the page number of every line and every figure. In polynomial time we can check that the pages are nonempty, that the line pages do not decrease, that each page fits, that each figure comes on or after the page of its reference, and that the sum is at most . The number of pages is at most , since each page is nonempty.
Hardness. We reduce from 3-PARTITION: given positive integers and an integer with for every and , can the numbers be split into triples that each sum to ? This problem is NP-complete in the strong sense (Garey and Johnson). Build the instance with:
- one line of height ;
- figures with heights , all referred to by line 1;
- page height and bound .
All numbers are at most , so the instance has size polynomial in the size of the 3-PARTITION instance, and its numbers are bounded by a polynomial in the numbers and the length of that instance.
Facts about any pagination of the instance. Every figure is on the page of line 1 or later, and pages are nonempty, so line 1 is on page 1. Page 1 has the line of height , so it has no room for a figure, as each . Four figures have total height more than , so each page holds at most 3 figures. List the figures in the order of their pages, with ties in any order. The first three figures are on page 2 or later, and in general the -th figure is on page or later, because pages hold at most figures. Since , the cost is
If the numbers have a 3-partition, the pagination instance is a yes instance. Put the line on page 1 and the -th triple on page , for . Each page has height , every figure comes after line 1, and the cost is .
If there is a pagination of cost at most , the numbers have a 3-partition. By the bound above, the cost is exactly , so every inequality holds with equality: the figures with are on page . So pages each hold exactly three figures. Each of these pages has height at most , and their total height is , so each has height exactly . The triples of the pages form a 3-partition.
The reduction is computed in polynomial time and keeps the numbers polynomially bounded. Since 3-PARTITION is NP-complete in the strong sense, pagination with free figures is strongly NP-complete.
Consequences
- No polynomial algorithm solves pagination with free figures unless P = NP, and since the hardness is strong, no pseudo-polynomial algorithm does either, so even small integer heights do not help.
- The hardness holds with a single line of text, so it comes from packing the figures, not from breaking the text. Rules that keep the figures in a fixed order, as LaTeX does for floats of one kind, remove it.
- Practical systems use heuristics for floats, for example the rules of LaTeX on top of the best-fit page builder.
Tightness
- Figures in order. If the figures must appear in the order of their references, the optimal pagination dynamic program finds the optimum in time; drop its white-space term to get exactly the cost of this page. So the freedom to reorder figures is what makes the problem hard.
- Few figures. For a fixed number of figures, the in-order dynamic program, with the check that every figure on a page is referred to on that page or before, can be run on each of the orders. Any pagination lists its figures in some order with each page holding a consecutive block, so this finds the optimum in time , which is polynomial in .
- Strength of the reduction. The bounds are what limit each page to three figures. With the weaker problem partition, the same idea gives only weak NP-hardness, which would leave room for a pseudo-polynomial algorithm.
History
Michael Plass studied optimal pagination in his Stanford PhD thesis of 1981, which shows that pagination with figures is NP-complete for two simple badness functions. The proof on this page is a short one in a simple model, with the total distance to references as the cost; it follows the pattern of the proof that bin packing is strongly NP-hard, and it is not the proof of the thesis.
References
- Michael F. Plass, Optimal Pagination Techniques for Automatic Typesetting Systems, PhD thesis, Stanford University, 1981, the abstract (two simple badness functions for which optimal pagination is NP-complete)
- Michael R. Garey and David S. Johnson, Computers and Intractability, A Guide to the Theory of NP-Completeness, W. H. Freeman, 1979, 3-PARTITION and strong NP-completeness
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 56PSG7 Edit this page History Report an error Markdown