Skip to content

Tight Comparison Bounds for Stable Sorting with Predicted Repetitions and Bounded Lookahead

Shunqi Lu

cs.DS

Abstract

With a strict comparator, verifying x=yx=y takes two comparisons. We study stable sorting under prefix deadlines: the order of the first ii records must be determined before any record beyond position i+Li+L is compared. An untrusted schedule predicts, for each later record, which of the first qq records shares its key. Even with correct predictions, schedules with equal label frequencies can require n+o(n)n+o(n) or 2n−o(n)2n-o(n) comparisons. A packing quantity explains this gap: for each label cc, let PcP_c be the largest number of its predicted positions pairwise more than LL apart. With at most ee wrong predictions and Q=q+eQ=q+e, the optimal worst-case comparison count is n−1+log⁡2(Q!)+∑cPc−1e=0min⁡cPc+O(Q)n-1+\log_2(Q!)+\sum_c P_c-\mathbf{1}_{e=0}\min_c P_c+O(Q) for every schedule and lookahead LL. The lower bound counts deadline-forced cycles in the comparison graph. The algorithm verifies all predicted equalities except for the largest key, whose records it only checks to be nondecreasing; one early new maximum cancels this saving. Without a schedule, a sorter can learn a repeated permutation from the keys; at zero lookahead, one new maximum raises its leading coefficient from 2−1/q2-1/q to 22. If each key's successor is predicted from its previous occurrence with EE mistakes, lookahead ⌈n ⌉\lceil\sqrt n\,\rceil suffices for n+o(n)n+o(n) comparisons when q(E+1)=o(n)q(E+1)=o(n), while o(n)o(\sqrt n) forces 2n−o(n)2n-o(n). On two 32,768-record inputs, our implementation is within 3 and 7 comparisons of the optimum.

Create a lesson

Metadata

Comments
18 pages, 3 figures, 4 tables