Big-O race: growth beats a head start
Big-O notation says how fast something grows, and this race lets you see what that means. Every complexity class is a team of bouncing balls. Each bounce knocks one point off the floor below, a floor of 1000 points breaks after 1000 bounces, and then the balls fall to the next, ten times stronger floor. There the team grows by its class: O(1) keeps its balls, O(n) has n of them on floor n, O(n²) n², and O(2ⁿ) and O(n!) explode. Give the slow classes thousands of balls at the start and watch who leads first, and who wins. Every complexity class is a team of bouncing balls that has to break through floors. Each bounce takes one point off a floor, and a floor of 100 breaks after 100 bounces. On every new floor n a team grows by its class: O(1) keeps its balls, O(n) gets n, O(n²) n², O(2ⁿ) and O(n!) explode. Press Play to race, Step and Back to jump from one broken floor to the next, and drag along the chart to scrub. The head start gives the slow classes more balls at the start; the fastest-growing class wins in the end anyway.
How it works
- Press Play: every team bounces on its first floor, the floors crack and break, and the balls fall to the next floor, where the team grows by its class.
- Watch the leader: with a head start the slow classes break the first floors fastest, until a fast-growing class catches up and overtakes them on the chart.
- Pick an example or set the head start, the number of floors and how fast the floors get stronger, and switch classes on or off with the chips.
- Use Next floor and Previous floor to jump from one broken floor to the next, drag along the chart to scrub, and switch Sound on to record a video.
The rules of the race
Each team bounces in rounds: in every round all its balls land once, and each landing takes one point off the floor. A floor worth V points therefore breaks after V ÷ B rounds, rounded up, when the team has B balls. Floor n is worth 10ⁿ points by default, so every floor is ten times harder than the one above it. A team whose number of balls grows slower than the floors falls further and further behind, and a team that grows faster than the floors speeds up.
How each class grows
On floor n a team has c · g(n) balls, with g(1) = 1 so that every team starts with its head start c: 1 for O(1), 1 + log₂ n for O(log n), n for O(n), n(1 + log₂ n) for O(n log n), n² and n³ for the polynomials, 2ⁿ⁻¹ for O(2ⁿ) and n! for O(n!). On floor 10 that is 1, 4.3, 10, 43, 100, 1000, 512 and 3,628,800 balls. Only the factorial ends up growing more than ten times per floor, from floor 10 on, so on floors ×10 it is the only team that ends up getting quicker.
A head start does not save you
Big-O ignores constant factors, and the head start is exactly such a factor. With a head start of 2, O(1) begins with 128 balls and O(n!) with one; with 4, O(1) gets 16,384. The slow classes then break the first floors in a single round and lead the race, but a constant is a constant: the factorial passes 16,384 on floor 8, and from then on O(n!) breaks every floor faster than all the others. That is why an algorithm with a better complexity class wins on large inputs, even when it is slower on small ones.
A clock on a logarithmic scale
The slowest team in a race over ten floors of 10ⁿ points needs billions of bounces. The race clock therefore speeds up: every ×10 of bounces takes the same few seconds of playback, as on the chart's axis. At the start you can follow every bounce; later each bounce you see stands for thousands or millions. On this clock a team with a constant number of balls breaks one floor ×10 at a steady pace, and the chart turns the growth into slopes you can compare.
Frequently asked questions
Who wins the Big-O race?
The class that grows fastest: O(n!) when it races, otherwise O(2ⁿ), then O(n³) and so on. Whatever head start the slower classes get, the fastest-growing class has more balls from some floor on, and from there it breaks every floor first. On floors that get ten times stronger, every team slows down at first, the slow classes the most, and only O(n!) speeds up again from floor 10 on.
Why does O(1) lead at the start?
Because of the head start. Big-O hides constant factors, so the app gives the slow classes more balls: with a head start of 2, O(1) gets 2⁷ = 128 balls, O(log n) 64 times 1 + log₂ n and O(n!) 1 times n!. The first floors of 10 and 100 points then fall to O(1) in a single round, while O(n!) with one or two balls needs dozens. Set the head start to 1 for a fair start.
What does a ball stand for?
A unit of work done per step, like a processor that can do one operation at a time. A floor is a job of a given size, and the floors getting stronger is the input getting bigger. In the race the classes are turned around: more balls means more work per round, so the class with the biggest count wins, the opposite of an algorithm, where the class that needs the fewest steps is the fastest.
Why is the time axis logarithmic?
Because the race spans billions of bounces. On a normal clock O(n!) would finish in a blink while O(1) took years. The app's clock covers every ×10 of bounces in the same few seconds, so you can watch the whole race; the chart uses the same scale, which makes a team that keeps a steady pace on floors ×10 a straight staircase.
Can I use the picture?
Yes. Save image gives a PNG at the size you choose, and the pencil opens the race in the PictorX photo editor as layers: the background, the floor values, every team's floors and balls, the labels and the chart, so you can move, hide or recolour each one. The same race is in the editor under Apps ▸ Science ▸ Computing.
Big-O Race: how do I record a video?
Press the red Record button in the playback bar: it films what the stage shows. Press it again to stop, and the video is saved to your device. Recording is free; you only need to sign in. Without a subscription the video carries a small PictorX logo in a corner. The button beside Record opens the video options: the shape (as shown, square, story 9:16 or wide 16:9), the length (until you stop, or 5, 10, 15 or 30 seconds for social media) and the file: MP4, WebM or an animated GIF. For the sound, choose the app's own sounds or one of three music tracks: calm, bright or beat.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Go to Editor