All original content is created in Ukrainian. Not all content has been translated yet. Some posts may only be available in Ukrainian.Learn more

What is factorial complexity?

Post cover: What is factorial complexity?
This content has been automatically translated from Ukrainian.
Factorial complexity is a situation where the number of options or combinations grows like the factorial of the number of elements. In other words, for n elements, the possible permutations are n!n!n! (n factorial), which quickly becomes a huge number even for small n.
This phenomenon is often encountered in combinatorics, planning, and exhaustive algorithms. For example, the permutations of 5 elements are 120 options, while for 10 elements, there are already 3,628,800.
Real-life examples:
  • Permutations of tasks or routes – planning delivery routes or tasks in a project.
  • Playing chess or puzzles – the number of possible sequences of moves grows extremely quickly.
  • Cryptography – guessing combinations or passwords through exhaustive search.
A simple Ruby code to demonstrate factorial complexity:
def factorial(n)
  (1..n).reduce(1, :*)
end

(1..10).each do |i|
  puts "n=#{i} - #{factorial(i)} options"
end
Result:
n=1 - 1 options
n=2 - 2 options
n=3 - 6 options
n=4 - 24 options
n=5 - 120 options
n=6 - 720 options
n=7 - 5040 options
n=8 - 40320 options
n=9 - 362880 options
n=10 - 3628800 options
=> 1..10
This example shows why factorial complexity quickly complicates the task and makes direct enumeration of options practically impossible.

This post doesn't have any additions from the author yet.

What is combinatorial explosion?
28 Jul 11:50

What is combinatorial explosion?

meme code
meme code@memecode
What is a brain stack?
28 Jul 19:37

What is a brain stack?

meme code
meme code@memecode
What is integer overflow?
15 Aug 08:28

What is integer overflow?

meme code
meme code@memecode
What is a HAR file (HTTP Archive)?
25 Aug 18:23

What is a HAR file (HTTP Archive)?

meme code
meme code@memecode
What is Bubble Sort (algorithm explanation)?
16 Sep 18:42

What is Bubble Sort (algorithm explanation)?

meme code
meme code@memecode
What is exponential growth?
16 Sep 18:57

What is exponential growth?

meme code
meme code@memecode
What is NP-complexity?
16 Sep 19:31

What is NP-complexity?

meme code
meme code@memecode
Offset vs Cursor Pagination in Rails: what to choose and why
24 Sep 15:22

Offset vs Cursor Pagination in Rails: what to choose and why

meme code
meme code@memecode
What is Row Security in PostgreSQL and why is it important for Rails developers
04 Oct 19:06

What is Row Security in PostgreSQL and why is it important for Rails developers

meme code
meme code@memecode
What is ivar in Ruby / Rails?
19 Oct 20:12

What is ivar in Ruby / Rails?

meme code
meme code@memecode
Main methods of authentication in API
19 Oct 20:26

Main methods of authentication in API

meme code
meme code@memecode
What are the differences between OAuth 1 and OAuth 2
19 Oct 20:34

What are the differences between OAuth 1 and OAuth 2

meme code
meme code@memecode