Comp301: "Repetition Lecture"
Transcript of Comp301: "Repetition Lecture"
Computer Science Division: CS301
Course CS301, Part:“ALGORITHMIC COMBINATORICS I”
( 3rd Year Students )
Prepared by:
Dr. Ahmed AshryAhmed AshryAhmed Ashryhttp://www.researchgate.net/profile/Ahmed_Abdel-Fattah
Repetition
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 1 (of 35)
Computer Science Division: CS301
The ZEROTH Laws of Counting:The 1st 0th law of counting: The Sum Principle
Disjunction leads to addition: add exclusive options.
If there are ri different objects in the i th set, for 1 ≤ i ≤ m, and if thedifferent m sets are disjoint, then the number of ways to select an object
from (one of) the m sets is
m∑
i=1
ri .
The 2nd 0th law of counting: The Product PrincipleConjunction leads to multiplication: multiply successive choices or actions.
For a counting procedure that is decomposable into m successive(ordered) stages, with distinct ri outcomes in the i th stage, for
1 ≤ i ≤ m, then the total procedure has
m∏
i=1
ri different composite
outcomes, provided that the composite outcomes are all distinct.
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 2 (of 35)
Computer Science Division: CS301
Permutations of Non-Distinct Objects:
Theorem (The Mississippi Rule:)
The number of permutations of n objects that consist of qi objects of the i th type,
for 1 ≤ i ≤ t, i.e. n =t∑
i=1
qi , is given by:
P(n; q1, q2, . . . , qt ) :=n!
q1!× q2!× · · · × qt !
In how many ways can we arrange 3 dashes and 2 dots?
(Ans.) In P(5; 3, 2) =(3 + 2)!
3!× 2!= 10 ways (N.B. n = 5, q1 = 3, and q2 = 2).
What is the number of distinct permutations of “MISSISSIPPI”?
(Ans.) In P(11; 1, 4, 4, 2) =11!
4! × 4!× 2!= 34, 650 ways (N.B. n = 11, qM = 1, qI = 4, qS = 4,
and qP = 2).
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 3 (of 35)
Computer Science Division: CS301
Example:
We have 5 English books, 7 French, and 6 German books.
1 How many ways are there to choose two books?
2 How many ways are there to choose two books of differentlanguages?
Hints:
Here, n = 5 + 7 + 6 = 18.
1 C (n, r) = C (18, 2) = 18!2!×16! =
18×172 = 9× 17 ways.
2 We may want to divide the problem, depending on the language ofthe two selected different books, to the following subproblems:
1 The 2 books are English and French: 5× 7 = 35 ways2 The 2 books are English and German: 5× 6 = 30 ways3 The 2 books are French and German: 7× 6 = 42 ways
Using the “sum principle”, we have a total of 35 + 30 + 42 ways.
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 4 (of 35)
Computer Science Division: CS301
Group Formation: Lecture 2, Slide 9
Given 7 women and 4 men, how many ways to form a committee:
(a) of 5 people, which has 3 women and 2 men?
(b) of any size, which has equal numbers of women and men?
(c) of 4 people, which has at least 2 women?
(d) of 4 people, one of them must be Mr. Abdou?
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 5 (of 35)
Computer Science Division: CS301
Theorem (Selections with Unlimited Repetitions:)
The number of selections with repetition of r objects chosen fromn (distinct) types of objects is C (r + n − 1, r).
Example: Constrained Collections
How many ways are there to pick a collection of exactly 10 balls from apile of red balls, blue balls, and green balls if there must be:
1 at least 5 red balls?
2 at most 5 green balls?
Solutions:
See Lecture 3, Slide 6.
REMEMBER:
You can prove the same result using Generating Functions!
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 6 (of 35)
Computer Science Division: CS301
Distinct Objects → Distinct Containers
We have r distinct objects and n distinct cells
∴ Each object can go in n places
∴ Product rule: n × n× · · · × n︸ ︷︷ ︸
r−times
= nr distributions
Identical Objects → Distinct Containers
We have r identical objects and n distinct cells
∴ We choose r cells from the n in C (n, r) ways
If repetition is allowed, ∴ there are
(r + n − 1
r
)
distributions
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 7 (of 35)
Computer Science Division: CS301
Application: Solving (Integer) Equations
1 How many integer solutions are there to the equationx1 + x2 + x3 + x4 = 12, with xi ≥ 0.
2 How many solutions with xi > 0?
3 How many solutions with x1 ≥ 2, x2 ≥ 2, x3 ≥ 4, x4 ≥ 0?
Integer solution means (ordered) integer values for the x ’s.This kind of problems is modeled as “selection with repetition”:
each xi represents the number of (identical) 1’s in box i
(or represents the number of chosen objects of type i)
1 Here, we have r = 12 ones, and n = 4 boxes.
∴ The number of solutions is C (12 + 4− 1, 12) =
(15
12
)
= 455.
2 Here, we first put an object in each box =⇒ r= 12− 4 = 8, n = 4.∴ The number of solutions is C (8 + 4− 1, 8) = C (11, 3) = 165.3 Here, we first put objects in box i (as constrained):
i.e. Put 2 in x1, 2 in x2, 4 in x3
∴ The number of solutions is C ((12− 2− 2− 4) + 4− 1, 4) = 35.
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 8 (of 35)
Computer Science Division: CS301
BINOMIAL COEFFICIENTS:
Generally:
The number of n-letter sequences formed by k x ’s and n − k a’s isC (n, k); the coefficient of an−kxk in the expansion:
(x + a)n =
n∑
k=0
(n
k
)
an−k
xk
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 9 (of 35)
Computer Science Division: CS301
Basic Properties of Binomial Coefficients:
The “Binomial Theorem”:
(1 + x)n =
(n
0
)
+
(n
1
)
x +
(n
2
)
x2 + · · ·+
(n
k
)
xk + · · ·+
(n
n
)
xn
“Pascal’s Triangle”:(n
k
)
is the sum of the two neighboring numbers in the preceding row.
Interpretation using “Block Walking”:
A “grid of blocks” with Binomial Coefficients as “block coordinates”:
Each street corner is labeled with a pair 〈n, k〉.
n indicates how far down the “network of streets” you are.
The k ’s are how many “rights” (of the page) you have taken.
The number of “block walks” from 〈0, 0〉 to 〈n, k〉 is C (n, k).
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 10 (of 35)
Computer Science Division: CS301
Pascal’s Triangle:
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 11 (of 35)
Computer Science Division: CS301
Block Walking in Pascal’s Triangle:
n’s =⇒ how far down; k ’s =⇒ how many rights taken
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 12 (of 35)
Computer Science Division: CS301
Block Walking in Pascal’s Triangle:
Generally:
(n
k
)
=
(n − 1
k
)
+
(n− 1
k − 1
)
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 12 (of 35)
Computer Science Division: CS301
Block Walking in Pascal’s Triangle:
The number of “block walks” from 〈0, 0〉 to 〈n, k〉 is
(n
k
)
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 12 (of 35)
Computer Science Division: CS301
Block Walking in Pascal’s Triangle:
r∑
k=0
(n + k
k
)
=
(n
0
)
+
(n + 1
1
)
+ · · ·+
(n + r
r
)
=
(n + r + 1
r
)
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 12 (of 35)
Computer Science Division: CS301
Block Walking in Pascal’s Triangle:
n∑
k=1
(k
r
)
=
(1
r
)
+
(2
r
)
+ · · ·+
(n
r
)
=
(n+ 1
r + 1
)
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 12 (of 35)
Computer Science Division: CS301
Other Identities & “Secrets”:
Sum of all k ’s in row n:
(n
0
)
+
(n
1
)
+ · · ·+
(n
n
)
=n∑
k=0
(n
k
)
= 2n
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 13 (of 35)
Computer Science Division: CS301
Other Identities & “Secrets”:
Triangular Numbers: the 3rd diagonal!
(n
2
)
, for n ≥ 2
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 13 (of 35)
Computer Science Division: CS301
Other Identities & “Secrets”:
Fibonacci Numbers: the “Shallow” Diagonals!
n−2∑
k=0
(n − k
k
)
= Fn−1
Modified from the source available at: http://en.wikipedia.org/wiki/File:PascalTriangleFibanacci.svg
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 13 (of 35)
Computer Science Division: CS301
Combinatorial Arguments:
Example: Element-Based Selections (Pascal’s Formula)
Give a combinatorial argument to prove that(n
k
)
=
(n − 1
k
)
+
(n − 1
k − 1
)
.
Solution:
LHS is the number of ways to select k objects of n distinct objects.
This can be done in another way, depending on whether a specificobject (say the 1st) is included in the selection:
if it is, the problem is to choose (k − 1) other objects from theremaining (n − 1) objects (in
(
n−1k−1
)
ways).if it is not, the problem is still to choose k objects from theremaining (n − 1) objects (in
(
n−1k
)
ways).
Applying the sum rule:
(n
k
)
=
(n − 1
k
)
+
(n − 1
k − 1
)
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 14 (of 35)
Computer Science Division: CS301
Combinatorial Arguments:
Example: Group-Based Selections
Give a combinatorial argument to prove that(n
k
) (k
m
)
=
(n
m
) (n −m
k −m
)
.
Solution:
We have n people, and want to form a group of k people, then select asubset of m leaders.We can either:
first select the group, then the leaders (LHS),
OR
first select the leaders, then the remaining group members (RHS).
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 15 (of 35)
Computer Science Division: CS301
Combinatorial Arguments:
Example: Group-Based Selections
Give a combinatorial argument to prove that
n
(n − 1
k
)
= (k + 1)
(n
k + 1
)
.
Solution:
We have n people, and want to form a committee of k + 1 people, suchthat one of them is the president.We either:
first select the president then the remaining k people (LHS),
OR
first select the k + 1 people then select the president (RHS).
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 16 (of 35)
Computer Science Division: CS301
Generating Functions (GFs):An easy tool for handling special constraints.The most abstract problem-solving technique in combinatorics.
Suppose 〈ar 〉∞
r=0 gives the number of ways ar to select/arrange r objects
Ordinary Generating Functions (O.G.F.):
The OGF of the sequence of numbers 〈a0, a1, a2, · · · 〉 is given by:
G(x) = a0 + a1x + a2x2 + a3x
3 + · · · =
∞∑
n=0
anxn
Exponential Generating Functions (E.G.F.):
The EGF of the sequence of numbers 〈a0, a1, a2, · · · 〉 is given by:
E (x) = a0 + a1x + a2x2
2!+ a3
x3
3!· · · =
∞∑
n=0
anxn
n!
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 17 (of 35)
Computer Science Division: CS301
Find the number of ways to select k fruit
pieces from 3 bananas, 2 oranges, andan apple.
Answer:
1 ∵ “selection” ∴ represent the situation using an “OGF”
2 A bracket for an object represents the possible ways to select it
3 Let G(x) = (1 + x + x2 + x3)︸ ︷︷ ︸
bananas
(1 + x + x2)︸ ︷︷ ︸
oranges
(1 + x)︸ ︷︷ ︸
the apple
∴ G(x) = 1 + 3x + 5x2 + 6x3 + 5x4 + 3x5 + x6
4 Which is the OGF of the sequence 〈1, 3, 5, 6, 5, 3, 1〉= 〈ak〉6k=0
5 For 〈ak〉6k=0, the coefficient of xk in G(x) is ak for 0 ≤ k ≤ 6
E.g., You can select 5 fruit pieces in 3 ways (because a5 = 3)
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 18 (of 35)
Computer Science Division: CS301
How many ways exist to select k fruits
from apples and oranges, such that atmost one apple, at least one orange, and
at most two oranges must be selected.
Answer:
1 ∵ “selection” ∴ represent the situation using an “OGF”
2 A bracket for an object represents the possible ways to select it
3 Let G(x) = (1 + x)︸ ︷︷ ︸
apples
(x + x2)︸ ︷︷ ︸oranges
∴ G(x) = x + 2x2 + x3, which is the OGF for 〈0, 1, 2, 1〉:
1 no way to select no piece (you must select a piece)2 1 way to select a fruit piece (and it must be an orange!)3 2 ways to select 2 fruit pieces (an apple and an orange OR 2 oranges)4 1 way to select 3 pieces (two oranges and an apple)
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 19 (of 35)
Computer Science Division: CS301
Sample OGFs:
1 〈1, 1, 1, · · · 〉 =⇒ 1 + x + x2 + · · · =
∞∑
n=0
xn =1
1− x
2 〈0, 1, 2, · · · 〉 =⇒ x+2x2+3x3+ · · · =
∞∑
n=0
nxn =
∞∑
n=1
nxn =x
(1− x)2
∵
∞∑
n=0
xn =1
1− x
d/dx=⇒
∞∑
n=1
nxn−1 =1
(1 − x)2mult x=⇒
∞∑
n=1
nxn =x
(1− x)2
3 〈1, 4, 6, 4, 1〉 =⇒ 1 + 4x + 6x2 + 4x3 + x4 = (1 + x)4
4 (1 + x)n is the OGF for C (n, r), that’s:
⟨(n
0
)
,
(n
1
)
,
(n
2
)
, · · ·
⟩
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 20 (of 35)
Computer Science Division: CS301
Manipulation of Identities:
Given (1 + x)n =n∑
k=0
(n
k
)
xk :
put x = 1 to get: 2n =
n∑
k=0
(n
k
)
which we already know (why?)
put x = −1 to get: 0 =
n∑
k=0
(−1)k(n
k
)
, which proves that:
(n
0
)
+
(n
2
)
+ · · ·=
(n
1
)
+
(n
3
)
+ · · ·=2n−1
i.e.: out of n objects, the number of ways to select an even numberof objects equals that of selecting an odd number of objects.
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 21 (of 35)
Computer Science Division: CS301
Manipulation of Identities:
Example:
Show that
n∑
k=0
k
(n
k
)
= n 2n−1.
Answer:
Since (1 + x)n=
n∑
k=0
(n
k
)
xkd/dx=⇒n(1 + x)n−1 =
n∑
k=1
k
(n
k
)
xk−1
put x = 1 to get: n 2n−1 =
n∑
k=1
k
(n
k
)
=
n∑
k=0
k
(n
k
)
Exercise: Calculate the sum
(n
0
)
+ 2
(n
1
)
+ 22(n
2
)
+ · · ·+ 2n(n
n
)
Hint: use the expansion of (1 + x)n with x = 2.
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 22 (of 35)
Computer Science Division: CS301
The Binomial Theorem Revisited:Coefficients in Newton’s Binomial Expansion:
For any exponent z :
(1 + x)z= 1+zx+
z(z − 1)
2!x2+
z(z − 1)(z − 2)
3!x3+· · ·+
z(z − 1) · · · (z − (k − 1))
k!xk+· · ·
That’s:
(1 + x)z=
∞∑
k=0
z(z − 1) · · · (z − (k − 1))
k!xk
(1 + x)z =∞∑
k=0
(z
k
)
xk
where z ∈ R,
(z
0
)
= 1, and
(z
k
)
= 0 if z ∈ N and k > z .
E.g., (1 + x)−1/2 =(−1/20
)+(−1/2
1
)x +
(−1/2
2
)x2 + · · ·
∴ (1 + x)−1/2 = 1− 12x + (−1/2)(−3/2)
2! x2 + · · ·
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 23 (of 35)
Computer Science Division: CS301
Theorem (Selections with Unlimited Repetitions (revisited):)
The number of selections with repetition of r objects chosen fromn (distinct) types of objects is C (n + r − 1, r).
A Proof using OGFs:
We are selecting r objects from n types of objects with repetition
∵ “selection” ∴ represent the situation using an “OGF”
A bracket for an object represents the possible ways to select it
Therefore:
1 Each (type of) object has the bracket (1 + x + x2 + · · · )
2 The OGF is given by G(x) = (1 + x + x2 + · · · )n
3 We need the coefficient of x r in the expansion of:
G(x) =(1 + x + x2 + · · ·
)n=
(1
1− x
)n
= (1− x)−n
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 24 (of 35)
Computer Science Division: CS301
Expanding G(x) = (1− x)−n
:
G(x) =∞∑
k=0
(−n)(−n − 1) · · · (−n − (k − 1))
k!(−x)k
G(x) =
∞∑
k=0
(−1)k
(n(n + 1) · · · (n + (k − 1))
k!
)
(−1)kxk
G(x) =
∞∑
k=0
n(n + 1) · · · (n + k − 1)
k!xk
G(x) =
∞∑
k=0
(n + k − 1) · · · (n + 1)n
k!·
(n − 1)!
((n+ k − 1)− k)!· xk
G(x) =
∞∑
k=0
(n+ k − 1
k
)
xk
∴ the coefficient of x r in the expansion of G(x) is C (n + r − 1, r).
Generally, (1− x)−n
=
∞∑
r=0
(n + r − 1
r
)
x r
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 24 (of 35)
Computer Science Division: CS301
Famous Polynomial Expansions:
Some Polynomial Expansions: IMPORTANT for OGFs!
1
n∑
k=0
xk = 1 + x + x2 + · · ·+ xn =1− xn+1
1− x
2
∞∑
k=0
xk = 1 + x + x2 + · · · =1
1− x
3
n∑
k=0
(n
k
)
xk = 1 +
(n
1
)
x + · · · = (1 + x)n
4
∞∑
k=0
(k + n − 1
k
)
xk = 1 +
(1 + n − 1
1
)
x + · · · =1
(1− x)n
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 25 (of 35)
Computer Science Division: CS301
Calculating Coefficients:
Example:
Find the coefficient of x16 in the expansion of (x2 + x3 + · · · )5
Let G(x) = (x2 + x3 + · · · )5 =[x2
(1 + x + x2 + · · ·
)]5=
(x2
1− x
)5
We use1
(1− x)n= (1 − x)−n =
∞∑
k=0
(k + n − 1
k
)
xk
∴ G(x) = x101
(1− x)5 = x10
∞∑
k=0
(n+ k − 1
k
)
xk = x10 F (x)
∴ The coefficient of x16 in the expansion of G(x) is the coefficient of x6
in F (x) =
∞∑
k=0
(5 + k − 1
k
)
xk which is
(5 + 6− 1
6
)
=
(10
4
)
Exercise: What is the coefficient of xm in (x2 + x3 + · · · )5?
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 26 (of 35)
Computer Science Division: CS301
Example:
How many ways are there to select 25 toys from 7 types of toys withbetween 2 and 6 of each type?
We need the coefficient of x25 in G(x) = (x2 + x3 + x4 + x5 + x6)7
G(x) = x14(1 + x + x2 + x3 + x4)7 = x14(1− x5
1− x
)7
G(x) = x14 ·(1− x5
)7·
1
(1 − x)7= x14 · F1(x) · F2(x)
F1(x) =(1− x5
)7=
7∑
k1=0
(7
k1
)
(−x5)k1
F2(x) = (1− x)−7
=
∞∑
k2=0
(7 + k2 − 1
k2
)
xk2
The coefficient of x25 in G(x) is that of x11 in F1(x) · F2(x):
1 ·
(7 + 11− 1
11
)
+
(
−
(7
1
))
·
(7 + 6− 1
6
)
+
(7
2
)
·
(7 + 1− 1
1
)
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 27 (of 35)
Computer Science Division: CS301
Find the number of ways to arrange k fruit pieces,given 2 oranges and 3 bananas.
Answer:
1 ∵ “arrangement” ∴ represent the situation using an “EGF”
2 Let H(x) = (1 + x +x2
2!)
︸ ︷︷ ︸oranges
(1 + x +x2
2!+
x3
3!)
︸ ︷︷ ︸
bananas
H(x) = 1+2x+( 12!+
12!+1)x2+( 1
2!+12!+
13! )x
3+( 12!2!+
13! )x
4+ 12!3!x
5
by no=⇒magic
H(x) = 1 + 2x + 4 x2
2! + 7 x3
3! + 10 x4
4! + 10 x5
5!
E.g., You can arrange 2 fruit pieces in 4 ways.OO, BB, OB, and BO.
E.g., You can arrange 5 fruit pieces in 10 ways.OOOBB, OOBOB, OBOOB, BOOOB, BOOBO, BOBOO, BBOOO, OBBOO, OOBBO, and OOOBB.
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 28 (of 35)
Computer Science Division: CS301
Use EGFs to show that P(n, r) =n!
(n − r)!.
For r -arrangements (without repetition) of n objects, the EGF isH(x) = (1 + x)n (why?)a
∴ H(x) =
n∑
r=0
(n
r
)
x r (why?)b
∴ H(x) =n∑
r=0
n!
r ! (n − r)!x r =
n∑
r=0
n!
(n − r)!
x r
r !
Thus, the number of r -arrangements (without repetition) of n objects is
the coefficient ofx r
r !in H(x), which is
n!
(n − r)!.
aAs no repetition is allowed, an object will either be considered or not (i.e. x + 1).bThis is the binomial theorem.
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 29 (of 35)
Computer Science Division: CS301
Use EGFs to find the number of r arrangements ofobjects chosen from unlimited supplies of n typesof objects.
The EGF is H(x) =
(
1 + x +x2
2!+
x3
3!+ · · ·
)n
= (ex)n= enx
∴ H(x) =∞∑
r=0
(nx)r
r !=
∞∑
r=0
nrx r
r !
Thus, the required number is the coefficient ofx r
r !in H(x), which is nr .
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 30 (of 35)
Computer Science Division: CS301
The “EGF”
Find the EGF for the number of ways to place r (distinct) people into n
different rooms with at least one person in each room. Repeat with aneven number of people in each room, then with an odd number in eachroom.
Recall that distributions of distinct objects are equivalent toarrangements with repetition, where each room/container has abracket to represent its constraints.
Therefore:1 The first EGF is
(
x + x2
2!+ x3
3!+ · · ·
)n
= (ex − 1)n.
2 The second EGF is(
1 + x2
2!+ x4
4!+ · · ·
)n
= 12
(
ex + e
−x)
.
3 The third EGF is(
x + x3
3!+ x5
5!+ · · ·
)n
= 12
(
ex− e
−x)
.
4 The required number is the coefficient ofxr
r !.
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 31 (of 35)
Computer Science Division: CS301
The “Number”
Find the number of ways to place 25 (distinct) people into 3 differentrooms with at least one person in each room.
The required EGF is
G(x) =
(
x +x2
2!+
x3
3!+ · · ·
)3
= (ex − 1)3=
3∑
r=0
(3
r
)
(−1)r (ex)3−r
The required number is the coefficient ofx25
25!.
G(x) =
3∑
r=0
(3
r
)
(−1)r (ex)3−r = e3x − 3e2x + 3ex − 1
G(x) =
∞∑
r=0
(3x)r
r !− 3
∞∑
r=0
(2x)r
r !+ 3
∞∑
r=0
x r
r !− 1
∴ The coefficient ofx25
25!in G(x) is 325 − 3× 225 + 3
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 32 (of 35)
Computer Science Division: CS301
Other Markers for the Final/Oral Exam:
VIP Homework & Exercises
Homework#2: Apply the Mississippi Rule to prove that something isdivisible by something else (because the rule gives an integer value).
Homework#4: Items 3 and 4.
Homework#5: Item 1.
Homework#5: The last given solved example.
Homework#6: Example 4 in [Tucker, 2007, Page 249 and 250].
Exercise: Calculate the sumn∑
k=0
2kC(n, k).
Exercise: What’s the coeff. of xm in some G(x)?
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 33 (of 35)
Computer Science Division: CS301
Hints for (Answering) the Final/Oral Exam: Secrets for not “Losing” Marks
Quickly review EVERYTHING you have in written forms!
if it’s not in the final, it can be in the oral (which will be held the same day). . .
when you’re given what looks like answers, you should expect questions!
Read the questions VERY CAREFULLY!
understand what EXACTLY is required, and write ONLY what is asked for. . .
(and, btw, it’s not me who should answer questions in exam halls!)
don’t waste your/my time/efforts. . .
but also pay attention to explanation details that give you “the” marks!
when a table is needed, draw a table!
Clearly show me yourself
start with easier questions. . .
but once you answer a part, answer this part till its end!
clearly frame the question number and part (even if —God forbid— repeated). . .
never expect that I’ll search where your answers are!
Insist on proving that you’ve made efforts!
if you want to cancel something, do cancel it!
never give me an opportunity to see nonsense!
Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Repetition 34 (of 35)