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

What is factorial complexity?

Factorial complexity is the rapid increase in the number of options, where for n elements the possible permutations are n!. It is commonly encountered in combinatorics, route planning, exhaustive search algorithms, an...

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?

Brain stack is a model that describes how the brain works in layers: from neurons to self-awarene...

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

What is integer overflow?

Integer overflow is the overflow of an integer when the value exceeds the limit of the variable 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 .har format that stores a log of the browser's interaction with the ...

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

What is exponential growth?

Exponential growth is a rapid increase in magnitude, where each subsequent step multiplies the re...

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

What is NP-complexity?

NP-completeness is a class of problems where finding a solution is extremely difficult, but verif...

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

What is ivar in Ruby / Rails?

ivar in Ruby is an instance variable, denoted by @. In Rails, it passes data from the controller ...

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

Main methods of authentication in API

The main methods of authentication in the API on Ruby on Rails: Basic Auth, Token, JWT, and OAuth...