Big O - How fast it gets bad
As n gets bigger:
O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(n³) < O(2ⁿ) < O(n!)
—> —> —> —> —> —>—> —> —> —> —> —> being the absolute worst
n² vs n³
of course n³ is worse
n² vs 2ⁿ
crossover point is between 4 and 5.
n² | 2ⁿ | |
n=4 | 16 | 16 |
n=5 | 25 | 32 |
n³ vs 2ⁿ
The crossover happens after n=10.
n³ | 2ⁿ | |
n=9 | 729 | 512 |
n=10 | 1000 | 1024 |
n³ vs n!
The crossover happens after n=6.
n³ | n! | |
n=5 | 125 | 120 |
n=6 | 216 | 720 |
2ⁿ vs n!
The crossover happens much earlier, after n=3.
2ⁿ | n! | |
n=3 | 8 | 6 |
n=4 | 16 | 24 |