Try   HackMD

2 - Combinatorics, The Product Rule

Combinatorics

Combinatorics - a fancy word for counting

For us, determining the size of some set. We define the things we want to count as the elemtns of some set

S and we want to determine the size of that set.

The product rule

If a procedure

P has
m
steps (step 1, step 2, step
m
), we define the number of ways to execute the
i
th step as
Ni
. Then the number of ways to execute
P
is
N1N2...Nm

The number of ways of doing

Ni does not depend on the previous steps.

Ex: Ordering fast food meals

2 steps when ordering fast food

  1. Drink: Coke/Beer
  2. Food: Burger/Club sandwhich/Chicken burger

Step 1: Choose Coke or Beer

N1=2
Step 2: Choose a meal
N2=3

N1N2=23=6 Different ways we can do this procedure

If

P generates elements from some set
S
and

  • (Onto) For each
    xS
    , there is an execution of
    P
    that generates
    x
    and
  • (One-to-one) Any two different executions of
    P
    generate distinct elements of
    S

Then

|S|=N1N2Nm

Ex:

Our set

S is the set of meals
S={(C,B),(C,CB),(C,CS),(B,B),(B,CB),(B,CS)}

|S|=23=6

Less trivial example

Bitstrings

A bitstring is a sequence of 0's and 1's

Sn is equal to the set of all bitstrings of length
n
(integers
n0
)

S3={000,001,010,011,100,101,110,111}
|S|=8

We can count the number of bit strings for any given

n using the product rule

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

# of ways to execute this prodcedure

N1N2...Nn=22...2=2n

This procedure is both onto and one-to-one so the cardinality of the set of every bitstring of length

n
Sn
=
|Sn|=2n

Example with functions

Let

A and
B
be two sets.
|A|=m,|B|=n

Question: How many functions

f:AB are there?

Example of one function mapping from

AB
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Procedure

Let

x1...xm be the elements of
A
in some order

    for i = 1 to m:
        choose the value f(x_i) from B
  • m
    steps
  • N1=n=N2=N3=...=Nm

# of executions is
nm

Injective functions

A function

f:AB is one-to-one (injective) if for each
x,yA,xy,f(x)f(y)

Not this

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Question: How many one-to-one functions

f:AB are there?

Answer is 0 if

|A|>|B|

What if

|A||B|?

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

The procedure is similar

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Answer =

n(n1)(n2)...(nm+1)=n!/(nm)!

Unconventional example

We have

m books
B1...Bm

We have a bookcase with
n
shelves

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

We want to know how many ways can we place the books

B1...Bm onto the shelves

  • Which books go on which shelves
  • What order the books are on within each shelf

Procedure

for i = 1 to m:
    -Take B_i and either:
        - Choose a shelf j and make B_i on shelf j
        - Choose one of the previous placed books and place B_i immediately to the right

One possible ordering

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

As can be seen, the first book can go on any of the 4 shelves. The second book can go on any of the 4 shelves or to the right of the first book. The third book can go on any of the 4 shelves or to the right of the first or second book and this pattern continues.

Answer =

(n+m1)×(n+m2)×...×(n)=(n+m1)!/(n1)!

tags: COMP2804 Combinatorics