liveBook · Manning

Permutation

As explained in Statistics Every Programmer Needs

A permutation without replacement is an ordered arrangement in which each item may be selected at most once.

A permutation is an arrangement in which order matters. A briefcase lock set to 3-7-4 does not open for a different ordering of those digits. Without replacement, each item can appear at most once; with replacement, repetitions such as 3-3-4 are allowed. section 2.2.3

To count ordered selections of r distinct items from n available items without replacement, multiply the choices remaining at each position: n × (n − 1) × … × (n − r + 1) = n! / (n − r)!. This requires r ≤ n. Each selection reduces the choices for the next position by one. section 2.2.3

Five items, three positions

With n = 5 and r = 3, there are 5 × 4 × 3 = 60 permutations without replacement. Python’s math.perm(5, 3) returns 60. Check the counting assumptions before using that result: allowing repeats instead gives 5³ = 125 ordered sequences, while ignoring order gives 10 combinations without replacement. section 2.2.3

>>> permutations = math.perm(n, r)
>>> print(f'Number of permutations without replacement: '
>>>       f'{permutations}')
Number of permutations without replacement: 60

The Python listing computes the without-replacement count directly with math.perm(n, r). section 2.2.3

How Statistics Every Programmer Needs covers it

How deep it goes
Defines order and replacement, derives the factorial count through shrinking choices, and computes an example in Python.
Examples
Uses briefcase-lock sequences and a five-item, three-position calculation yielding 60 arrangements.
What it assumes
Builds from basic probability and counting while introducing the distinction between ordered and unordered selections.
What you can do after
Apply it via Python’s math.perm to count ordered selections without replacement and check whether repetition is allowed.
How it connects
Contrasts combinations with permutations and distinguishes selection with replacement from selection without replacement.

Also explained in

Compare how 9 books explain permutation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.