Double the cabbages and kimchi takes twice the work, with the same number of leaves per cabbage. Here, the work quadruples when both inputs double.
Salting kimchi is O(n × m): n cabbages, m leaves each. Count the work, double one input, then divide by the original count. Compare that with two sequential loops for lasagne and a loop of binary searches for biryani.
The biryani loop counts worst-case shelf probes; it doesn't search a real shelf. Save this as kitchen-counts.mjs and run node kitchen-counts.mjs:
const lasagne = (n, m) => {
let work = 0
for (let i = 0; i < n; i++) work++ // brown n batches of meat
for (let j = 0; j < m; j++) work++ // then whisk m ladles of milk
return work
}
const biryani = (n, m) => {
let work = 0
for (let i = 0; i < n; i++)
// each of n spices
for (let left = m; left > 0; left = Math.floor(left / 2)) work++ // halve a shelf of m jars
return work
}
const kimchi = (n, m) => {
let work = 0
for (let i = 0; i < n; i++)
// each of n cabbages
for (let j = 0; j < m; j++) work++ // salt each of m leaves
return work
}
function compareInputs(name, work, n, m) {
const base = work(n, m)
const times = (next) => `×${(next / base).toFixed(2)}`
console.log(
name,
base,
'n only',
times(work(2 * n, m)),
'm only',
times(work(n, 2 * m)),
'both',
times(work(2 * n, 2 * m))
)
}
compareInputs('lasagne', lasagne, 10, 10)
compareInputs('biryani', biryani, 10, 100)
compareInputs('kimchi', kimchi, 10, 20)
Output:
lasagne 20 n only ×1.50 m only ×1.50 both ×2.00
biryani 70 n only ×2.00 m only ×1.14 both ×2.29
kimchi 200 n only ×2.00 m only ×2.00 both ×4.00
Swap in your own loops. Orders and line items behave like cabbages and leaves. So ask which input actually grows before you rewrite anything.
Sedgewick and Wayne's DoublingRatio doubles the input and compares running times. Counting operations keeps the machine out of it. Big O can't tell a slow pleat from a fast one.
The ten dishes
| Dish | Big O | Pattern | Count | Double the input | Multiplier |
|---|---|---|---|---|---|
| Stir-fry | O(1) |
Direct lookup | 1 reach, 5 bowls | 1 reach, 10 bowls | ×1 |
| Hand-pulled noodles | O(log n) |
Doubling loop | 8 folds, 256 strands | 9 folds, 512 strands | +1 fold |
| Dumplings | O(n) |
Single loop | 10 | 20 | ×2 |
| Lasagne | O(n + m) |
Sequential loops | 20 | 40 (both) | ×2 |
| Biryani | O(n log m) |
Loop + binary search | 70 looks | 160 looks (both) | ×2.29 |
| Cheese board | O(n log n) |
Divide and conquer | 17 comparisons, 8 cheeses | 49 comparisons, 16 cheeses | ×2.9 |
| Kimchi | O(n × m) |
Nested loop | 200 | 800 (both) | ×4 |
| Pizza | O(n²) |
Triangular loop | 45 pairs, 10 toppings | 190 pairs, 20 toppings | ×4.2 |
| Burger | O(2ⁿ) |
Branching recursion | 1,024, 10 extras | 1,048,576, 20 extras | ×1,024 |
| Sushi | O(n!) |
Permutations | 3,628,800, 10 pieces | 2,432,902,008,176,640,000, 20 pieces | ×670 billion |
Cheese board counts worst-case merge sort comparisons (MIT). Biryani counts worst-case probes on a sorted shelf with random access and constant-cost comparisons: 10 spices, 100 jars initially. The GIF's ×2.3 uses the n log₂ m formula; whole probes give ×2.29. Stir-fry uses a known spot; hash lookup is only expected O(1) (MIT 6.006). Sushi counts orders of distinct pieces.
If you count sushi in JavaScript, use BigInt. From 19 pieces, the count passes Number.MAX_SAFE_INTEGER (factorials). Past that, large numbers can round with no error.
The noodles have prior art. Luisa Mich and Daniel Berry taught complexity through noodle making in 2018.
What doubling doesn't tell you
- One ratio isn't a class. Merge sort gives ×2.9 from 8 to 16 items, and ×2.22 from 1,024 to 2,048. Pizza gives ×4.2 at 10 toppings and ×4.002 at 1,000. Big O is an upper bound on growth, not a fixed multiplier. Compare a few doublings.
- Explosions need a smaller step. Burgers give ×1,024 from 10 to 20 extras, and ×1,048,576 from 20 to 40. The multiplier grows with the input. So add one instead. An 11th extra gives ×2. An 11th sushi piece gives ×11.
- The kitchen is a model. Every fold counts the same here, however hard the real stretch is. If leaves per cabbage vary, sum the leaves. Dishes are teaching devices, not timed recipes.
- Options aren't work until someone tries them. Printing all 1,024 burgers as ten-bit masks takes 10,240 characters. That's more work than the count suggests. Serving one sushi order is the opposite. Trying all 3,628,800 is factorial. The chef serves one, from experience.
The maintained version, with every dish in full and the sources: Big O in ten dishes.

Top comments (0)