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 variants or combinations increases as a factorial of the number of elements. In other words, for n elements of possible permutations n!n!n! (n factorial), which quickly becomes a huge number even with small n.
This phenomenon is often found in combinatorics, planning, and full-sorting algorithms. For example, permutations of 5 elements – are 120 options, and for 10 elements there are already 3,628,800 of them.
Real-life examples:
  • Permutation of tasks or routes <TAG1> planning delivery routes or tasks in the project.
  • A game of chess or puzzles <TAG1> the number of possible move sequences grows extremely fast.
  • Cryptography <TAG1> selection of combinations or passwords when completely searched.
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 variants
n=2 - 2 variants
n=3 - 6 variants
n=4 - 24 variants
n=5 - 120 variants
n=6 - 720 variants
n=7 - 5040 variants
n=8 - 40320 variants
n=9 - 362880 variants
n=10 - 3628800 variants
=> 1..10
This example shows why factorial complexity quickly complicates the problem and makes direct selection of options practically impossible.

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

What is a combinatorial explosion?
28 Jul 11:50

What is a 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 HAR file (HTTP Archive)?
25 Aug 18:23

What is 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 Rails developers
04 Oct 19:06

What is Row Security in PostgreSQL and why is it 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
Basic methods of authentication in the API
19 Oct 20:26

Basic methods of authentication in the API

meme code
meme code@memecode
How do OAuth 1 differ from OAuth 2
19 Oct 20:34

How do OAuth 1 differ from OAuth 2

meme code
meme code@memecode