Factorial
The factorial of a nonnegative integer n, written n!, is the product of all positive integers from 1 through n, with 0! equal to 1.
Statistics Every Programmer Needs
A factorial is the product of all positive integers from a given natural number down to one.
- How it is used
- Uses factorials to count ordered selections when replacement is not allowed.
- How deep it goes
- Defines factorials, works through numerical examples, derives a permutation formula, and implements it in Python.
- Examples
- Uses 5!, 3!, five runners competing for three positions, and Python results for 60 permutations.
- What you can do after
- Apply factorials via Python's math.factorial to calculate permutation counts without replacement.
Read how Statistics Every Programmer Needs explains factorial →
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.
- How it is used
- Uses factorial to quantify the search space of brute-force traveling-salesman permutations.
- 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.
Also covered in
- Functional Programming in Scala, Second Edition
- Geometry for Programmers
- How Computers Make Books
- React Hooks in Action: With Suspense and Concurrent Mode
- Julia as a Second Language
What to know first
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- recursionRecursion is a computational technique in which a definition or procedure refers to or invokes itself, directly or indirectly.
- stack frameA stack frame is a runtime record that holds the local context and execution state for one active function or method invocation.
Related concepts
- sine functionused by · The sine function is a periodic trigonometric function that maps a real number or angle to a value between −1 and 1.
- recursionimplemented by · Recursion is a computational technique in which a definition or procedure refers to or invokes itself, directly or indirectly.
- function typeequivalent to · A function type specifies the types of inputs and result that a callable value accepts and produces.
- conditional logicuses · Conditional logic is a programming technique that evaluates conditions to select among execution paths, actions, or result values.
Questions about factorial
What is factorial?
The factorial of a nonnegative integer n, written n!, is the product of all positive integers from 1 through n, with 0! equal to 1.
Which Manning books explain factorial?
Statistics Every Programmer Needs and Classic Computer Science Problems in Swift: Essential techniques for practicing programmers.
What should I know before learning factorial?
Manning books that teach factorial usually introduce function, recursion and stack frame first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

