Sort the two dimension vectors separately into ascending order, and . Then return true exactly when for every . Sorting costs and the coordinate comparisons cost .
Sufficiency follows by matching corresponding ranks and translating that rank matching back to the original axes. For necessity, suppose for some . The dimensions must all be assigned to strictly larger target dimensions. None of the first sorted target dimensions is large enough, leaving at most eligible slots. The pigeonhole principle gives a contradiction. This proves the sorted-coordinate criterion for box containment, including ties: equality fails the required strict fit.
Read “subsequence” in its usual sense: selected indices increase in the given input order. First sort each box's dimension vector, in total time. Let be the maximum number of boxes in a fitting subsequence ending at index . Process and computeThe last selected box before , if any, supplies exactly one of these candidates; conversely an optimal candidate subsequence can be extended by . Induction on proves the box nesting recurrence. Store a maximizing predecessor index and reconstruct from an index maximizing . For , return the empty subsequence.
There are candidate pairs, each requiring coordinate comparisons. Hence running time and storage suffice, including sorted vectors, table entries and reconstruction pointers. It is unnecessary to store every fitting pair.
If “subsequence” was intended to allow arbitrary reordering, build the containment Directed acyclic graph instead: include every fitting ordered pair, then find its longest chain. Strict increase of the smallest sorted dimension gives a topological sorting by that dimension. The same pair-testing bound applies, but the index restriction must then be removed. These two interpretations differ: input boxes have a longest order-preserving subsequence of one box, but an unrestricted nesting chain of two.
Articles by others on the same topic
There are currently no matching articles.