O(n!): Factorial Time
What you'll learn: You'll understand the slowest common complexity class—factorial time—and see where it appears in real algorithms.
What is Factorial Time Complexity?
An algorithm has O(n!) complexity when its number of operations grows as fast as the factorial of the input size. Recall that factorial means n! = n × (n-1) × (n-2) × ... × 2 × 1. For n=5, that's 5! = 120. For n=10, it's 3,628,800. This explodes even faster than exponential time—it's the most impractical complexity you'll commonly encounter.
Where Does O(n!) Appear?
Factorial complexity shows up when you need to examine every possible arrangement of n items. The classic example is generating all permutations of a collection.
If you have 3 letters [A, B, C], there are 3! = 6 permutations: ABC, ACB, BAC, BCA, CAB, CBA. If you need to generate or check all of them, you're doing factorial work.
Another example: The brute-force solution to the Traveling Salesman Problem. If you want to visit n cities and find the shortest route by checking every possible order of cities, you have n! different routes to evaluate.
Why Is This So Slow?
Think of trying on outfits: with 2 shirts and 2 pants, you have 4 combinations. But arranging 10 unique items in order? That's over 3.6 million arrangements. Factorial growth dwarfs everything before it—even exponential O(2ⁿ) is faster for large n.
Practical Reality
Algorithms with O(n!) complexity are only viable for tiny inputs (n ≤ 10 or so). Beyond that, even the fastest computer can't finish in reasonable time.
Key Takeaway: O(n!) factorial time complexity occurs when exploring all permutations or arrangements of n items; it's the slowest common complexity and only feasible for very small inputs.