突破 n log n 排序壁垒的算法新进展

原标题:How Can Anything Beat n log n?
58AI 研判分

近期多项研究声称突破经典 n log n 排序下界,包括 Duan 等人针对有向最短路径的 O(m + n log n) 改进,以及一篇声称实现亚 n log n 排序的预印本。文章从信息论与熵的角度审视这些结果,指出最短路径计算本不需要对每个顶点排序,n 位整数乘法的输出空间熵下限为 2n 而非 n!,并探讨算法是否通过扩大分支因子 k 来绕开传统下界。

报道正文

本文目录11 个章节

(Updated: Tuesday, Nov 24, 2026), Nov 23, 2026 Section: Home / Post Categories: Computer Science, Tags: Algorithms, Entropy, Information Theory,AI assistance: AI synthesis from notesSynthesized and drafted by AI from the author's own notes, ideas, and code, then reviewed by the author.

  • None
  • AI review
  • AI x human co-authors
  • AI synthesis from notes

Epistemic status: HighWell-established best practice or backed by strong empirical testing and production experience.

  • Log
  • Speculative
  • Medium
  • High
  • Certain

Cave painting of a fencer piercing a black box filled with numbers

Piercing the black box to break through the nlog⁡nn \log n barrier.

Recently, headlines have kept making the rounds about sub-nlog⁡nn \log n algorithms—first Duan et al. breaking Dijkstra’s O(m+nlog⁡n)O(m + n \log n) sorting barrier for directed shortest paths, and then a preprint claiming sub-nlog⁡nn \log n integer multiplication.

My first reaction was skepticism. If a problem cares about ordering nn items, don’t you need log⁡n\log n steps to uniquely place each item, repeated nn times? That gives nlog⁡nn \log n. How could you possibly do better?

The short answer is that nlog⁡nn \log n is not a universal speed limit. It is the lower bound of a specific model of computation. To see how algorithms beat it, we need to look at what nlog⁡nn \log n actually measures—and which assumptions those algorithms drop.

Think of sorting nn items as routing each item down a decision tree into its final slot.

If you are only allowed to take 2-way comparison steps (< or >), every fork in the tree has 2 branches. Each step cuts the remaining slots in half. To route one item to its unique leaf among nn slots, it has to travel down roughly log⁡2n\log_2 n levels.

Send all nn items down a tree of depth log⁡2n\log_2 n, and you pay nlog⁡2nn \log_2 n total steps.

The 2-Way Tree

Every item drops through log2 n yes/no forks (< vs. >) to reach its sorted slot.

Items (n): 8Click Step Item or Play to route items down the 2-way tree. 0 / 8 routedBranching factor (k) 2 1 bit / stepTree depth 3 log₂(8) = 3Steps (this item) 0 waitingTotal steps 0 / 24 n · log₂ n

The Hidden Assumptions

That intuition feels airtight: if characterizing or placing a single item among nn slots takes log⁡2n\log_2 n steps, and there are nn items to process, then any task requiring ordering or classification across nn items seems forced to pay nlog⁡2nn \log_2 n. Under two specific conditions, that reasoning is airtight:

  1. Black-box items: You cannot peek inside an item. Your only tool is a 2-way yes/no step (like is a < b?) that yields at most 1 bit of information per step.
  2. Factorial-scale outcomes: The number of possible final answers grows like n!n! (or nnn^n)—meaning each of the nn items could end up in one of roughly nn distinct roles or positions. Not every task on nn items has that many outcomes: finding the maximum has only nn possible answers and assigning yes/no labels has 2n2^n, compared to n!n! orderings for sorting.

How Existing Algorithms Break nlog⁡nn \log n

Counterexamples already exist in every algorithms textbook. Two classic ones—Bucket Sort and Radix Sort—sort nn numbers in O(n)O(n) time when the numbers come from a bounded range or fixed digit width:

  • Bucket Sort computes a bucket address directly from each number’s value, drops the item straight into that bucket in a single step (when numbers map cleanly into nn slots, that is a direct nn-way lookup), and then reads the buckets back in order.
  • Radix Sort processes numbers one digit at a time. In Most-Significant-Digit (MSD) Radix Sort, 3-digit numbers are first routed into 10 buckets (0–9) by their hundreds digit; only buckets holding more than one item are split again by their tens digit, and so on—without ever comparing two numbers against each other.

Neither algorithm breaks mathematics. Both drop the black-box assumption—and flatten the tree.

Imagine lining up 30 kids by birth month. If you treat them as black boxes and only compare pairs of kids (“who was born earlier?”), you are stuck with a 2-way tree of depth log⁡2n\log_2 n. Instead, put 12 labeled boxes on the floor (Jan through Dec). Each kid looks at their own birth month and walks straight to their box in one step.

Computers can do the same thing because numbers aren’t opaque black boxes—they are digits and bit patterns, and hardware can jump directly to a memory address in a single step. Direct indexing widens the branching factor all the way to nn, collapsing the tree to depth 1. MSD Radix Sort makes the intermediate case just as clear: it routes the exact same items down a tree, except each node has 10 branches (0–9) instead of 2, flattening the depth from log⁡2n\log_2 n down to the number of digits—with zero comparisons. (As we will see next, when numbers are allowed to grow arbitrarily large with nn, escaping nlog⁡nn \log n asymptotically requires choosing the branching factor as a function of nn rather than keeping it fixed at 10.)

Flattening the Tree

The exact same 8 items—widening the branching factor k flattens the tree with zero comparisons.

Click Step Item or Play to watch every item jump straight to its slot in 1 step. 0 / 8 routedBranching factor (k) n = 8 3.00 bits / stepComparisons made 0 direct address jumpSteps (this item) 0 waitingTotal steps 0 / 8 exact O(n) = 8 (vs 24)

The Information-Theoretic View

Why does widening the branching factor break nlog⁡nn \log n, and when is a lower bound truly unavoidable? Information theory puts both assumptions into a single equation.

In an earlier post on entropy, I framed entropy HH as the minimum number of binary choices (bits) needed to describe categories of events:

H(outcomes)=−∑ipilog⁡2piH(\text{outcomes}) = -\sum_i p_i \log_2 p_i

That same lens gives us a hard floor for any algorithm.

Let NN be the total number of possible final answers to a problem—a function of the input size nn, not nn itself. When every answer is equally likely (the worst case, pi=1/Np_i = 1/N), the entropy of the answer space simplifies to:

H(N)=−∑i=1N1Nlog⁡21N=log⁡2NH(N) = -\sum_{i=1}^{N} \frac{1}{N} \log_2 \frac{1}{N} = \log_2 N

From Input Size n to Answer Space N

The same n input items produce vastly different numbers of possible final answers N depending on the task.

Input size (n): 3Input (n = 3):Find Max N = nN = 3 · H(N) = 1.58 bitsLabel Yes / No N = 2nN = 8 · H(N) = 3.00 bitsSort All Items N = n!N = 6 · H(N) = 2.58 bits

Why is H(N)=log⁡2NH(N) = \log_2 N a hard floor for 2-way steps? Let qq be the number of 2-way (yes/no) steps an algorithm takes. Those qq steps can produce at most 2q2^q distinct transcripts of answers. If 2q<N2^q < N, at least two different final answers must share the exact same transcript, and no algorithm can tell them apart. Therefore:

2q≥N  ⟹  q≥log⁡2N=H(N)2^q \ge N \implies q \ge \log_2 N = H(N)

Why 2q ≥ N Is a Hard Floor

Sorting n = 3 items (A, B, C) has N = 3! = 6 possible answers. Each leaf is one transcript of Y/N answers.

q = 2 steps → 22 = 4 < 6 Fungible answers

Only 4 transcripts exist for 6 orderings—at least two distinct answers share an identical Y/N history and become fungible.

q = 3 steps → 23 = 8 ≥ 6 All 6 separated

With 3 steps (⌈log2 6⌉ = 3), 8 transcripts give every single ordering its own unambiguous leaf.

Where does the log⁡2n\log_2 n in nlog⁡2nn \log_2 n come from? Logarithms turn multiplication into addition:

  • When each item has 2 outcomes (N=2nN = 2^n), taking the log yields H(2n)=log⁡2(2n)=nH(2^n) = \log_2(2^n) = n—linear, with no log⁡n\log n.
  • When all nn items can be ordered in N=n!N = n! ways, you are multiplying nn factors that grow with nn. Taking H(n!)=log⁡2(n!)H(n!) = \log_2(n!) adds up log⁡21+log⁡22+⋯+log⁡2n\log_2 1 + \log_2 2 + \dots + \log_2 n, which lands at roughly nlog⁡2nn \log_2 n.

Now look at what happens when you widen each step’s branching factor to kk. Remember from the entropy post that the base of the logarithm corresponds to how many outcomes a single step can distinguish, so qq kk-way steps yield kqk^q transcripts:

kq≥N  ⟹  q≥H(N)log⁡2k=log⁡kNk^q \ge N \implies q \ge \frac{H(N)}{\log_2 k} = \log_k N

Notice a crucial distinction here. Any constant kk-way step only differs from a 2-way step by a constant factor (1/log⁡2k1/\log_2 k): a fixed 10-way decimal lookup trims the work by log⁡210≈3.32×\log_2 10 \approx 3.32\times, and a fixed 256-way byte lookup trims it by 8×8\times, yet as nn grows without bound (and distinct numbers need at least log⁡kn\log_k n digits), both stay locked to O(nlog⁡n)O(n \log n) forever.

To actually escape nlog⁡nn \log n, kk must be a function of nn (for example, k=nk = \sqrt{n} or k=nk = n). Once kk scales with nn as k=nαk = n^\alpha, log⁡2k=αlog⁡2n\log_2 k = \alpha \log_2 n cancels the log⁡2n\log_2 n in nlog⁡2nn \log_2 n, so the total number of steps is only off from a one-shot nn-way lookup by a constant factor (1/α1/\alpha)—that is, linear O(n)O(n). Radix Sort achieves this when its base kk is chosen relative to the size and range of the numbers (e.g., k=nk = n or k=nk = \sqrt{n}): we are using the numerical value of the input itself to inform the algorithm’s addressing, piercing the black box.

Constant k vs. n-Dependent k

Any fixed branching factor k stays locked to binary sorting by a constant ratio; letting k grow with n breaks away into linear O(n).

Inspect n: 10,000

Entropy Is a Floor, Not a Guarantee

One important nuance: having H(N)=log⁡2NH(N) = \log_2 N bits of entropy does not guarantee you can solve a problem in log⁡2N\log_2 N steps (or log⁡kN\log_k N steps with a kk-way step).

Compare searching a sorted list against finding the maximum of an unsorted list. Both have N=nN = n possible answers, so both have the exact same entropy: H(n)=log⁡2nH(n) = \log_2 n bits. Yet finding the max takes n−1n - 1 comparisons, because each step only knocks out one loser—it cannot cut the remaining candidates in half.

More generally, to reach q≈log⁡kN=H(N)/log⁡2kq \approx \log_k N = H(N) / \log_2 k steps with a kk-way step over NN possible outcomes, each step must partition the remaining candidates symmetrically (evenly) into kk disjoint buckets of roughly N/kN/k outcomes. That is what lets every step shrink the answer space by division (N→N/kN \to N/k) and extract the full log⁡2k\log_2 k bits toward the answer.

When a step is asymmetric—say, checking “is item ii the target?” on an unsorted list, where one branch isolates $1outcomeandtheotherleavesoutcome and the other leavesN - 1—theworst−casebranchshrinksbysubtraction(—the worst-case branch shrinks by subtraction (N \to N - 1)insteadofdivision,soyouneverreach) instead of division, so you never reach \log_k N.Findingthemaximumrunsintoarelatedfailure:‘a>b‘hastwoequallylikelyoutcomes,yetontheanswerspaceof. Finding the maximum runs into a related failure: `a > b` has two equally likely outcomes, yet on the answer space of Ncandidatemaximaitonlydiscardsasingleloser,leavingcandidate maxima it only discards a single loser, leavingN - 1$ candidates alive either way because the remaining information is spent on relative order we do not need. You only hit the entropy floor when the problem’s structure lets each step carve the remaining answers into roughly equal, disjoint fractions.

Bringing It All Together

Every complexity claim sits on two axes: how fast the answer space NN grows, and how much information a single kk-way step can extract.

ProblemAnswer space (NN)Entropy floor (H(N)=log⁡2NH(N) = \log_2 N)Black-box 2-way stepsBreaking the black box
Look up a known index ii$1$$0$$0$ (1 direct read)O(1)O(1)
Search a sorted listnnlog⁡2n\log_2 nlog⁡2n\log_2 nO(1)O(1) (with hash/direct index)
Find max (unsorted)nnlog⁡2n\log_2 nn−1n - 1O(n)O(n) (still must inspect all)
Label each item yes/no2n2^nnnnnO(n)O(n)
Sort nn itemsn!n!∼nlog⁡2n\sim n \log_2 n∼nlog⁡2n\sim n \log_2 nO(n)O(n) (Radix / Bucket sort)
Recover an n×nn \times n binary grid2n22^{n^2}n2n^2n2n^2O(n2)O(n^2)

The Floor Explorer

Combine how fast the answer space N grows with how many bits one k-way step extracts.

  1. Outcomes per item (sets N and H(N)) 2. Branching factor k (outcomes per step) Floor =log₂(n!) ≈ n · log₂ n1≈O(n log n)8,530 min steps at n = 1,000The log₂ n factors cancel — leaving linear O(n)!Answer space N n! factorial orderingsEntropy H(N) at n = 1,000 8,530 bits log₂(n!) ≈ n log₂ n − 1.44nInfo per step 1.00 bit/step 2-way fork2-way baseline8,530 stepsSelected k8,530 steps

So whenever you see a headline announcing a sub-nlog⁡nn \log n algorithm, there are only two ways it happened: either the problem never actually had a factorial-scale answer space in the first place (computing shortest-path distances doesn’t require sorting every vertex, and multiplying two nn-bit integers only has 22n2^{2n} possible outputs—an entropy floor of 2n2n, never n!n!), or the algorithm found a way to look inside the box and widen the branching factor kk with nn.