I am afraid that Malte Skarupke is not correctly interpreting his plots of sorting time, t, versus the array size, n. The plots are log-log plots, and the slopes approach a constant value as n becomes large (over a thousand). We know that a comparison sort algorithm has complexity n log n.

Admit, for the sake of argument, that radix sort follows t = a.n^b.log n; then,

log t = log a + b log n + log log n.

For large n, log n >> log log n, so the log-log plot of t versus n will tend to a straight line with slope b.

If Malte takes the timing data used for preparing the plot and obtains b by fitting a straight line to the data for n > 1000, I conjecture that the result will be b = 1.

This is consistent with radix sort having a complexity of w.n, where w is the number of bits (or any other unit, such as bytes or words). If we fill the test array with random integers from 0 to n-1, then w = lg n, so w.n = n lg n.

]]>You think you have O(n)? You don’t. The log (n) is there. It’s hidden in the number of bytes needed to represent an object. 1 byte can represent 256 distinct objects. 2 bytes 256^2. 3 bytes 256^3. See the log now? All you did is change the base of the log to 256 instead of 2. So you put a smaller constant, which is beneficial, but didn’t change the asymptotic behavior. ]]>

```
```type Size =
| Large of int
| Medium of int
| Small of int
type Ingredient =
| Butter of float
| WhiteSugar of float
| BrownSugar of float
| Egg of Size
| Banana of Size
let untilFluffy = // Where: Ingredient list -> Async<Result<Ok, Error>>
let mixWith = // Where: Mixture -> Incredient list -> Async<Result<Ok, Error>>
let cake =
asyncResult {
let! fluffyMixture = untilFluffy [
Butter 2.
WhiteSugar 1.25
BrownSugar 1. ]
// This code won't happen unless fluffyMixture succeeds. If error it perpetuates the error
let! withBananas = mixWith fluffyMixture (Banana (Medium 2))
// ...
}

This is a little more complex rendition where you are taking into account asynchronous code and an Ok/Result response. I would say it is actually more understandable than imperative code itself since imperative code would have a bunch of `if (fluffyMixture == null) return Error...``

statements making it quite messy.

But alas. Even with this amazing F# code with units and everything it is still not popular. I think part of the problem is that people attracted to functional languages don’t understand how to explain it very well and enjoy the arcane.

]]>