More Counting
More Counting
A B
… f …
• Bijection rule
• Division rule
• More mapping
Counting Rule: Bijection
If f is a bijection from A to B,
then |A| = |B|
A B
… f …
Power Set
string: 1 0 1 1 0 … 1
Bijection: Power Set and Binary Strings
(7,6,2,5,5,2)
00 (none) 000000 00 00
Chocolate Lemon Sugar Glazed Plain
0011000000100100
00 1 1 000000 1 00 1 00
00 (none) 000000 00 00
Chocolate Lemon Sugar Glazed Plain
0c10l10s10g10p
A ::= all selections of a dozen doughnuts
A B
Choosing Non-Adjacent Books
Map each zero to a non-chosen book, each of the first five 1’s to a chosen
book followed by a non-chosen book, and the last 1 to a chosen book.
A B
In-Class Exercise
for i=1 to n do
for j=1 to i do
for k=1 to j do
printf(“hello world\n”);
for i=1 to n do
for j=1 to i do
for k=1 to j do
printf(“hello world\n”);
1 2 3 4 5 … n
If i=4, j=2, k=2, then there are two balls in 2 and one ball in 4.
In-Class Exercise
for i=1 to n do
for j=1 to i do
for k=1 to j do
printf(“hello world\n”);
1 2 3 4 5 … n
x1 x2 x3 x4
0 0 0 0 0 0 0 0 0 0
x1 x2 x3 x4
0 0 0 0 0 0 0 0 0 0
• Bijection rule
• Division rule
• More mapping
Division Rule
Double
Count!
and thus conclude that 2|A| = |B|. Then we compute |B| and then |A|. 25
Another Chess Problem
A ::= all sequences (r(1),c(1),r(2),c(2)) with r(1) ≠ r(2) and c(1) ≠ c(2)
A ::= all sequences (r(1),c(1),r(2),c(2)) with r(1) ≠ r(2) and c(1) ≠ c(2)
equivalent
Round Table
4! 9!
13! A 4 !9! B
13 13!
So number of 4 element subsets is
::
4 4!9!
n n!
::
m m !(n m)!
MISSISSIPPI
There is a bijection between such walks and sequences with 5 N’s, 5 E’s, 5
S’s, and 5 W’s.
There are 12 people. How many ways to divide them into 3 teams, each
team with 4 people?
37
This Lecture
• Bijection rule
• Division rule
• More mapping
Parenthesis
How many possible lower right monotone paths from (0,0) to (n,n)?
41
Monotone Path
How many possible lower right monotone paths from (0,0) to (n,n)?
We can still map a “right” move to an “x” and a “up” move to a “y”.
There is a bijection between (A) lower right monotone paths and
(B) words with n x’s and n y’s, with the additional constraint that
no initial segment of the string has more Y's than X's.
There is a bijection, but both sets look difficult to count.
42
Mountain Ranges
/\
/\ /\ /\/\ / \
/\/\/\, /\/ \, / \/\, / \, / \
(()()()) ()()()()
xxyxyxyy xyxyxyxy
(()()()) ()()()()
By “rotating” the images, we see that a path not crossing the diagonal
is just the same as a mountain not crossing the horizontal line.
So there is a bijection between them by mapping “right” to “up” and “up” to “down”
Parenthesis, Monotone Paths and Mountain Ranges
The basic examples usually map a set into a properly defined binary strings.