liveBook · Manning

Factorial

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

A factorial is the product of all positive integers from one through a given nonnegative integer.

A factorial multiplies every positive integer from one through a given nonnegative integer. Written n!, it counts the permutations generated from n items. section 8.2

Permutation growth

A brute-force traveling-salesman solver evaluates n! possible city orders. Five cities produce 5! = 120 orders; adding a sixth multiplies the work by 6, and adding a seventh multiplies it by 7 again. section 8.2

Factorial growth matters when:

  • Generating every permutation for a brute-force search. section 8.2
  • Recognizing when exhaustive evaluation becomes infeasible and approximation or other techniques are needed. section 8.2

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines factorial through permutation growth and stops short of deriving its formula or analyzing factorial algorithms.
Examples
Uses five, six, and seven cities to show how factorially many traveling-salesman paths expand.
What you can do after
Evaluate whether exhaustive permutation search is practical and recognize when near-optimal methods are preferable.
How it connects
Connects factorial with permutations, backtracking, brute-force search, the traveling salesman problem, dynamic programming, and genetic algorithms.

Also explained in

Compare how 2 books explain factorial →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.