liveBook · Manning

Permutation with replacement

As explained in Statistics Every Programmer Needs

A permutation with replacement is an ordered selection in which each selected item is returned and may be selected again.

A permutation with replacement counts ordered selections when each chosen item returns to the set before the next selection. Because every position retains the same number of choices, n options selected across r positions produce n^r possible arrangements. section 2.2.3

Use the following distinctions when selecting a counting method:

  • Treat order as significant: 3-7-4 differs from 4-7-3. section 2.2.3
  • Allow repetition: a sequence such as 3-3-4 remains valid because each digit is replaced after selection. section 2.2.3
  • Compare with permutations without replacement, where each selection reduces the number of available choices. section 2.2.3 section 2.5

Counting arrangements in Python

For n = 5 options and r = 3 positions, calculate 5^3 = 125 arrangements. Python expresses the same calculation with either exponentiation or pow(n, r). section 2.2.3

>>> num_permutations = n ** r
>>> print(f'Number of permutations with replacement: {num_permutations}')
Number of permutations with replacement: 125

Inspect the Python listing showing n ** r and its output of 125 for five options selected across three positions. section 2.2.3

How Statistics Every Programmer Needs covers it

How deep it goes
Defines replacement, derives n^r, and demonstrates equivalent Python implementations.
Examples
Uses briefcase lock digits, repeated sequences such as 3-3-4, and a Python calculation producing 125 arrangements.
What it assumes
Distinguishes order from selection and learns replacement behavior before applying the counting formula.
What you can do after
Apply it via Python by calculating n ** r or pow(n, r) for ordered selections with replacement.
How it connects
Contrasts with permutations without replacement and combinations, where order does not determine the selection.

Also explained in

Compare how 2 books explain permutation with replacement →

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.