← homeProgramming (Програмування)

What is factorial complexity?

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), w...

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.

🔥 More posts

All posts
What is a brain stack?
Jul 28, '25 19:37

What is a brain stack?

The brain is not just a sponge of neurons, but a system of layers, each of which performs its own...

What is integer overflow?
Programming (Програмування)Aug 15, '25 08:28

What is integer overflow?

You have a counter that can only count up to a certain number. For example, a pocket calculator t...

What is a HAR file (HTTP Archive)?
Programming (Програмування)Aug 25, '25 18:23

What is a HAR file (HTTP Archive)?

HAR file (HTTP Archive) is a special file format .har that stores the log of a web browser's inte...

What is exponential growth?
Sep 16, '25 18:57

What is exponential growth?

Exponential growth is the process where a quantity increases in a geometric progression. In other...

What is NP-complexity?
Programming (Програмування)Sep 16, '25 19:31

What is NP-complexity?

NP-completeness is a class of problems for which it is very difficult to find a solution, but eas...

What is ivar in Ruby / Rails?
Programming (Програмування)Oct 19, '25 20:12

What is ivar in Ruby / Rails?

ivar is short for instance variable. In Ruby, it is written with a @ before the name, for example...

Main methods of authentication in API
Programming (Програмування)Oct 19, '25 20:26

Main methods of authentication in API

When we create an API in Ruby on Rails, it is important to control who has access to resources. H...