Ibrahim Ahmed

How Can Anything Beat n log n?

(Updated: Tuesday, Nov 24, 2026), Nov 23, 2026
Section: Home / Post
Categories: Computer Science,
Tags: Algorithms, Entropy, Information Theory,
AI assistance: AI synthesis from notes
Synthesized 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: High
Well-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 $n \log n$ barrier.

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

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

The short answer is that $n \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 $n \log n$ actually measures—and which assumptions those algorithms drop.

What $n \log n$ Actually Looks Like

Think of sorting $n$ 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 $n$ slots, it has to travel down roughly $\log_2 n$ levels.

Send all $n$ items down a tree of depth $\log_2 n$, and you pay $n \log_2 n$ total steps.

The 2-Way Tree

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

8
Click Step Item or Play to route items down the 2-way tree. 0 / 8 routed
Branching factor (k) 2 1 bit / step
Tree depth 3 log₂(8) = 3
Steps (this item) 0 waiting
Total steps 0 / 24 n · log₂ n

The Hidden Assumptions

That intuition feels airtight: if characterizing or placing a single item among $n$ slots takes $\log_2 n$ steps, and there are $n$ items to process, then any task requiring ordering or classification across $n$ items seems forced to pay $n \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!$ (or $n^n$)—meaning each of the $n$ items could end up in one of roughly $n$ distinct roles or positions. Not every task on $n$ items has that many outcomes: finding the maximum has only $n$ possible answers and assigning yes/no labels has $2^n$, compared to $n!$ orderings for sorting.

How Existing Algorithms Break $n \log n$

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

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_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 $n$, 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_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 $n$, escaping $n \log n$ asymptotically requires choosing the branching factor as a function of $n$ 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 routed
Branching factor (k) n = 8 3.00 bits / step
Comparisons made 0 direct address jump
Steps (this item) 0 waiting
Total steps 0 / 8 exact O(n) = 8 (vs 24)

The Information-Theoretic View

Why does widening the branching factor break $n \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 $H$ as the minimum number of binary choices (bits) needed to describe categories of events:

$$ H(\text{outcomes}) = -\sum_i p_i \log_2 p_i $$

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

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

$$ H(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.

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

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

$$ 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
YNYNYNQ1Q2Q2YYABCYNACB / BACsame path!NYBCANNCAB / CBAsame path!

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
Q1Q2Q2Q3Q3Q3Q3ABCYYY—YYNACBYNYBACYNNBCANYY—NYNCABNNYCBANNN

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

Where does the $\log_2 n$ in $n \log_2 n$ come from? Logarithms turn multiplication into addition:

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

$$ k^q \ge N \implies q \ge \frac{H(N)}{\log_2 k} = \log_k N $$

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

To actually escape $n \log n$, $k$ must be a function of $n$ (for example, $k = \sqrt{n}$ or $k = n$). Once $k$ scales with $n$ as $k = n^\alpha$, $\log_2 k = \alpha \log_2 n$ cancels the $\log_2 n$ in $n \log_2 n$, so the total number of steps is only off from a one-shot $n$-way lookup by a constant factor ($1/\alpha$)—that is, linear $O(n)$. Radix Sort achieves this when its base $k$ is chosen relative to the size and range of the numbers (e.g., $k = n$ or $k = \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).

10,000

Entropy Is a Floor, Not a Guarantee

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

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

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

When a step is asymmetric—say, checking “is item $i$ the target?” on an unsorted list, where one branch isolates $1$ outcome and the other leaves $N - 1$—the worst-case branch shrinks by subtraction ($N \to N - 1$) instead of division, so you never reach $\log_k N$. Finding the maximum runs into a related failure: a > b has two equally likely outcomes, yet on the answer space of $N$ candidate maxima it only discards a single loser, leaving $N - 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 $N$ grows, and how much information a single $k$-way step can extract.

ProblemAnswer space ($N$)Entropy floor ($H(N) = \log_2 N$)Black-box 2-way stepsBreaking the black box
Look up a known index $i$$1$$0$$0$ (1 direct read)$O(1)$
Search a sorted list$n$$\log_2 n$$\log_2 n$$O(1)$ (with hash/direct index)
Find max (unsorted)$n$$\log_2 n$$n - 1$$O(n)$ (still must inspect all)
Label each item yes/no$2^n$$n$$n$$O(n)$
Sort $n$ items$n!$$\sim n \log_2 n$$\sim n \log_2 n$$O(n)$ (Radix / Bucket sort)
Recover an $n \times n$ binary grid$2^{n^2}$$n^2$$n^2$$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₂ n
1
≈
O(n log n)
8,530 min steps at n = 1,000
Answer space N n! factorial orderings
Entropy H(N) at n = 1,000 8,530 bits log₂(n!) ≈ n log₂ n − 1.44n
Info per step 1.00 bit/step 2-way fork
2-way baseline
8,530 steps
Selected k
8,530 steps

So whenever you see a headline announcing a sub-$n \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 $n$-bit integers only has $2^{2n}$ possible outputs—an entropy floor of $2n$, never $n!$), or the algorithm found a way to look inside the box and widen the branching factor $k$ with $n$.