O(n!)

Factorial Time

Danger

Every possible arrangement. Practical only for n ≤ 10.

Mental model

How many ways can you seat n people at a table? n choices for seat 1, n−1 for seat 2, n−2 for seat 3… multiply them: n! For n=20, that's more arrangements than atoms in the observable universe.

Interactive Visualisation
🪑  How many ways can you seat n people at a table? n choices for seat 1, (n−1) for seat 2, (n−2) for seat 3… Multiply them together: n! It grows so fast that n=20 produces more arrangements than atoms in the observable universe.
n:3! = 6 orders
A
B
C
3! = 6 orderings

n! is terrifyingly steep

n=11
n=22
n=36
n=424
n=5120
n=6720
n=75.0k
n=840k

How it scales

n = 5

120 ops

n = 8

40,320 ops

n = 10

3,628,800 ops

n = 12

479,001,600 ops

Previous

O(2ⁿ)Exponential Time