BRAGA

02 Writing02-02 Notes02-02-345

Permutations (Ordered, no repeats)

Published 16 Apr 20263 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
nPr=P(n,r)=n!(n−r)!^nP_r = P(n, r) = \frac{n!}{(n-r)!}
(1)

Deep Breakdown

What it tells me (Situation Awareness): P(n,r)P(n,r) counts the number of ways to select rr objects from nn distinct objects AND arrange them in order. Order matters here: selecting items A, B is different from B, A. Used in ranking problems, slot-filling sequences, and anywhere position matters.

Flowchart

n distinctobjects, pick r inorderFirst slot: nchoicesSecond slot: n-1choices...r-th slot: n-r+1choicesMultiply:n*(n-1)*...*(n-r+1)= n! / (n-r)!

Real-world use

Where it is used

Ranking top-k items from a list: top-3 email subject lines to test sequentially, finalist rankings in a competition, or multi-step recommendation slot filling.

Problem it solves

How many distinct ordered sequences of rr items can I form from nn choices, without repeating an item?

How it solves the problem

By the multiplication principle: first position has nn choices, second has n−1n-1, ..., rr-th has n−r+1n-r+1. The product telescopes to n!/(n−r)!n!/(n-r)!.

Example in a business

Testing which 3 of 10 landing page variants to show in order to different user segments: P(10,3)=720P(10,3) = 720 ordered sequences. Used to assess whether exhaustive testing is feasible.

The formula, piece by piece

P(n,r)=n!(n−r)!P(n, r) = \frac{n!}{(n-r)!}

  • nn: pool size (total distinct objects).
  • rr: number to select and arrange.
  • n!n!: total ways to order all nn objects.
  • (n−r)!(n-r)!: divide out the orderings of the unused n−rn-r objects.

The formula in words

"The number of ordered arrangements of rr objects chosen from nn distinct objects equals nn factorial divided by (n−r)(n-r) factorial." P(5,2)=5!/(5−2)!=120/6=20P(5, 2) = 5!/(5-2)! = 120/6 = 20

Critical Concepts

  • P(n,n)=n!P(n, n) = n! (all objects, ordered = full factorial).
  • P(n,1)=nP(n, 1) = n (pick 1 object, nn choices).
  • Contrast with combinations: C(n,r)=P(n,r)/r!C(n,r) = P(n,r)/r! — dividing by r!r! removes the ordering.
  • Python: math.perm(n, r) (3.8+) or math.factorial(n)/math.factorial(n-r).

Step-by-step calculation (tiny example)

Step 1: Identify n=4, r=2 4 distinct colors, pick 2 to paint the top and bottom of a flag (order matters).

Step 2: Apply formula P(4,2)=4!/(4−2)!=4!/2!=24/2=12P(4, 2) = 4!/(4-2)! = 4!/2! = 24/2 = 12

Step 3: Verify by enumeration Top choices: {R,G,B,Y}. For each top choice, 3 remaining for bottom: 4×3=124 \times 3 = 12. Confirmed.

Code examples

Beginner example (Python)

python
import math   # How many ways to assign top-3 ranks from 8 finalists?
n_finalists = 8
r_ranks = 3
ordered_arrangements = math.perm(n_finalists, r_ranks)
print(f"P({n_finalists}, {r_ranks}) = {ordered_arrangements}")   # 336

Beginner example (R)

r
# P(n, r) in R
n_finalists <- 8
r_ranks <- 3
ordered_arrangements <- factorial(n_finalists) / factorial(n_finalists - r_ranks)
cat("P(", n_finalists, ",", r_ranks, ") =", ordered_arrangements, "\n")  # 336

Professional example (Python)

python
import math
import itertools

def count_ordered_arrangements(pool_size: int, selection_size: int) -> int:
    """Count ordered selections of selection_size from pool_size distinct items. Args: pool_size: n, total distinct items. selection_size: r, items to select and order. Returns: P(n, r) = n! / (n - r)! Raises: ValueError: if selection_size > pool_size. """
    if selection_size > pool_size:
        raise ValueError(f"r={selection_size} cannot exceed n={pool_size}")
    return math.perm(pool_size, selection_size)   # Campaign slot-filling feasibility check
SLOT_SIZES = [2, 3, 4, 5]
POOL_SIZE = 10
print(f"Pool size: {POOL_SIZE} campaigns")
print(f"{'Slots (r)':>10} {'P(10,r)':>12} {'Feasible (< 1M)?':>18}")
for r_slots in SLOT_SIZES:
    arrangements = count_ordered_arrangements(POOL_SIZE, r_slots)
feasible = arrangements < 1_000_000
print(f"{r_slots:>10} {arrangements:>12,} {str(feasible):>18}")

Source: AIO p. 60

#probability-statistics#combinatorics#permutations-and-combinations

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close