[Common Math 1 Part 23] Repeated Permutations and Repeated Combinations (Advanced)

한국어 버전

In the previous post, we studied permutations and combinations without repetition. Now we allow the same object to be chosen more than once.

Note: repeated permutations and repeated combinations are advanced extension topics rather than part of the basic Common Math 1 scope. Read this post as optional enrichment after the core permutation and combination ideas.

Understand what repetition means, and distinguish repeated permutations from repeated combinations depending on whether order matters.

The key ideas are:

  • Allowing repetition means that an object can be chosen again after it is chosen once.
  • A repeated permutation allows repetition and considers order.
  • A repeated combination allows repetition but does not consider order.
  • Repeated combinations can be interpreted as deciding how many of each type to choose.
  • After understanding the formulas and recurrences, we can generate actual arrays with Python.

1. What does repetition mean?

Allowing repetition means that the same object can be chosen multiple times.

For example, suppose we make a three-digit password using 1, 2, 3.

If repetition is allowed,

111,121,333111,\quad 121,\quad 333

are all possible.

If repetition is not allowed, 111111 is impossible because the digit 1 is used three times.

Again, we must ask:

Does order matter?

For a password, order matters. 123123 and 321321 are different passwords. But if we are only choosing a multiset such as "two apples and one banana," order does not matter.


2. Repeated permutations

A repeated permutation is an ordered selection where repetition is allowed.

Suppose we choose 2 letters from A, B, C with repetition allowed, and order matters.

For the first position, there are 3 choices. For the second position, there are again 3 choices, because the first chosen letter can be chosen again.

So the number of arrays is

3×3=93\times3=9

The arrays are:

AA, AB, AC, BA, BB, BC, CA, CB, CCAA,\ AB,\ AC,\ BA,\ BB,\ BC,\ CA,\ CB,\ CC

The notation is

nΠr{}_n\Pi_r

and the formula is

nΠr=nr{}_n\Pi_r=n^r

because each of the rr positions has nn choices.

How arrays are generated

Watch items being picked one by one and appended to the current list.

Array generation
Permutation

Remove the picked item before the next step.

Completed lists: 6

Progress: 1 / 15
0%
Speed
0%
Items
A B C

밝게 표시된 원소가 지금 선택할 수 있는 원소입니다. 번호가 붙은 손가락은 현재 리스트에 들어간 순서를 나타냅니다.

Current list
[]
List being built now
A
[] [🔴 A] [A]
Completed so far

아직 완성된 리스트가 없습니다.


3. A recurrence view of repeated permutations

To build a repeated permutation of length rr, first build a repeated permutation of length r1r-1, then attach one more element at the end.

Since repetition is allowed, every element can be attached to every previous array.

R(n,r)=nR(n,r1)R(n,r)=n\cdot R(n,r-1)

with

R(n,0)=1R(n,0)=1

This recurrence directly describes the generation process.

Recurrence: building next arrays from previous arrays

A recurrence is not only a count; it is a rule that builds larger array lists from smaller ones.

Recurrence
{}_{4}C_{2}={}_{3}C_{1}+{}_{3}C_{2}

Combine arrays that include A and arrays that do not include A.

Progress: 1 / 6
0%
0%
Previous array
A를 뽑는 경우
[ B ] [ C ] [ D ]
Rule
[A] + 선택된 이전 배열
⬇️
New array
A B
Generated so far
[ A,B ]

4. Repeated combinations

A repeated combination is a selection where repetition is allowed but order does not matter.

Suppose we choose 3 fruits from apple, banana, and cherry, and repetition is allowed.

Then these are the same selection:

apple, apple, banana\text{apple, apple, banana}

and

banana, apple, apple\text{banana, apple, apple}

because order does not matter. What matters is how many of each fruit we choose.

So a repeated combination can be written as numbers:

(a,b,c)(a,b,c)

where

  • aa = number of apples
  • bb = number of bananas
  • cc = number of cherries

If we choose 3 fruits total, then

a+b+c=3a+b+c=3

where a,b,ca,b,c are nonnegative integers.


5. Stars and bars

The standard method for repeated combinations is stars and bars.

For example, choosing 3 fruits from 3 types means distributing 3 identical stars into 3 boxes.

Use stars for chosen objects and bars for boundaries between types.

For 3 fruits and 3 types, we need:

  • 3 stars
  • 2 bars

For example,

\star\star|\star|

means:

  • 2 apples
  • 1 banana
  • 0 cherries

Another example,

|\star|\star\star

means:

  • 0 apples
  • 1 banana
  • 2 cherries

There are 5 total positions: 3 stars and 2 bars. Choose where the 2 bars go.

5C2=10{}_5C_2=10

In general, the number of repeated combinations is

nHr=n+r1Cr=n+r1Cn1{}_nH_r={}_{n+r-1}C_r={}_{n+r-1}C_{n-1}

6. Why the formula works

Choosing rr objects from nn types with repetition allowed is the same as solving

x1+x2++xn=rx_1+x_2+\cdots+x_n=r

in nonnegative integers.

Here xix_i is the number of objects of type ii.

We represent the rr objects as stars and use n1n-1 bars to divide them into nn groups.

So there are

r+(n1)=n+r1r+(n-1)=n+r-1

positions, and we choose either the positions of the rr stars or the positions of the n1n-1 bars.

Therefore,

nHr=n+r1Cr=n+r1Cn1{}_nH_r={}_{n+r-1}C_r={}_{n+r-1}C_{n-1}

How arrays are generated

Watch items being picked one by one and appended to the current list.

Array generation
Permutation

Remove the picked item before the next step.

Completed lists: 6

Progress: 1 / 15
0%
Speed
0%
Items
A B C

밝게 표시된 원소가 지금 선택할 수 있는 원소입니다. 번호가 붙은 손가락은 현재 리스트에 들어간 순서를 나타냅니다.

Current list
[]
List being built now
A
[] [🔴 A] [A]
Completed so far

아직 완성된 리스트가 없습니다.


7. A recurrence view of repeated combinations

Repeated combinations can also be generated by deciding whether to use the first type.

For the first type A:

  1. Use at least one A.
  2. Use no A.

If we use at least one A, we put A in the result and still may use A again. So the remaining problem is to choose r1r-1 objects from the same nn types.

If we use no A, we choose rr objects from the remaining n1n-1 types.

Thus,

H(n,r)=H(n,r1)+H(n1,r)H(n,r)=H(n,r-1)+H(n-1,r)

with suitable boundary cases.

Recurrence: building next arrays from previous arrays

A recurrence is not only a count; it is a rule that builds larger array lists from smaller ones.

Recurrence
{}_{4}C_{2}={}_{3}C_{1}+{}_{3}C_{2}

Combine arrays that include A and arrays that do not include A.

Progress: 1 / 6
0%
0%
Previous array
A를 뽑는 경우
[ B ] [ C ] [ D ]
Rule
[A] + 선택된 이전 배열
⬇️
New array
A B
Generated so far
[ A,B ]

8. Comparing the four types

Type Repetition Order Notation Formula
Permutation No Matters nPr{}_nP_r n!(nr)!\dfrac{n!}{(n-r)!}
Combination No Does not matter nCr{}_nC_r n!r!(nr)!\dfrac{n!}{r!(n-r)!}
Repeated permutation Yes Matters nΠr{}_n\Pi_r nrn^r
Repeated combination Yes Does not matter nHr{}_nH_r n+r1Cr{}_{n+r-1}C_r

The most important questions are always:

  1. Is repetition allowed?
  2. Does order matter?

9. Math first, code later

The following code generates actual arrays.

Generate repeated permutation arrays with Python
def repeated_permutations(items, r):
    if r == 0:
        return [[]]

    result = []
    for prev in repeated_permutations(items, r - 1):
        for item in items:
            result.append(prev + [item])
    return result

print(repeated_permutations(['A', 'B', 'C'], 2))
print(len(repeated_permutations(['A', 'B', 'C'], 2)))
Generate repeated combination arrays with Python
def repeated_combinations(items, r):
    if r == 0:
        return [[]]
    if not items:
        return []

    first = items[0]
    rest = items[1:]

    with_first = [[first] + tail for tail in repeated_combinations(items, r - 1)]
    without_first = repeated_combinations(rest, r)
    return with_first + without_first

print(repeated_combinations(['A', 'B', 'C'], 3))
print(len(repeated_combinations(['A', 'B', 'C'], 3)))
Summary: four generation functions
def permutations(items, r):
    if r == 0:
        return [[]]
    result = []
    for i, item in enumerate(items):
        rest = items[:i] + items[i+1:]
        for tail in permutations(rest, r - 1):
            result.append([item] + tail)
    return result


def combinations(items, r):
    if r == 0:
        return [[]]
    if not items:
        return []
    first, rest = items[0], items[1:]
    return [[first] + tail for tail in combinations(rest, r - 1)] + combinations(rest, r)


def repeated_permutations(items, r):
    if r == 0:
        return [[]]
    return [prev + [item] for prev in repeated_permutations(items, r - 1) for item in items]


def repeated_combinations(items, r):
    if r == 0:
        return [[]]
    if not items:
        return []
    first, rest = items[0], items[1:]
    return [[first] + tail for tail in repeated_combinations(items, r - 1)] + repeated_combinations(rest, r)

10. Summary

  • Repetition means an object can be chosen again.
  • nΠr{}_n\Pi_r counts repeated permutations, where order matters.
  • nΠr=nr{}_n\Pi_r=n^r
  • nHr{}_nH_r counts repeated combinations, where order does not matter.
  • nHr=n+r1Cr=n+r1Cn1{}_nH_r={}_{n+r-1}C_r={}_{n+r-1}C_{n-1}
  • Repeated combinations are equivalent to nonnegative integer solutions of x1++xn=rx_1+\cdots+x_n=r.
  • Recurrence relations show how the arrays can actually be generated.

Chapter 23 Check

Repeated permutations and combinations.

QUIZ
Question 1 / 0 Completed 0 / 0
Progress 0 / 0 0%
Current question Correct Incorrect Pending
Question 1 Multiple choice Pending
Score 0pts · Correct 0/0

💬 댓글

이 글에 대한 의견을 남겨주세요