Download Textbook ? COS 341 Discrete Mathematics

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Fundamental theorem of algebra wikipedia , lookup

Collatz conjecture wikipedia , lookup

Elementary mathematics wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Recurrence relation wikipedia , lookup

Transcript
Textbook ?
• 12 students said they needed the textbook, but only one
student bought the text from Triangle.
COS 341 Discrete Mathematics
• If you don’t have the book, please get it from Triangle.
Exponential Generating
Functions
and Recurrence Relations
• We will have to pay for the copies that aren’t taken !
1
2
Derangements (or Hatcheck lady revisited)
d n : number of permutations on n objects without a fixed point
D ( x) : exponential generating function for number of derangements
A permutation on [n] can be constructed by picking
a subset K of [n], constructing a derangement of K and
fixing the elements of [n] - K .
Every permutation of [n] arises exactly once this way.
EGF for all permutations =
∞
n!
∑ n! x
n =0
n
=
1
1− x
EGF for permutations with all elements fixed =
1
= D( x) ⋅ e x
1− x
∞
1
∑ n! x
n =0
n
=e
3
x
Derangements
1
= D( x) ⋅ e x
1− x
1
D ( x) = e−x
1− x
∞
x n  ∞ 
= ∑ (−1) n ∑ x n 
n !  n=0 
 n=0
 n (−1)k 
dn

= coefficient of x n = ∑
 k =0 k ! 
n!
 n (−1) k 

d n = n ! ∑
 k =0 k ! 
Different proof in Matousek 10.2, problem 17
4
1
Example
Example
How many sequences of n letters can be formed from
How many sequences of n letters can be formed from
A, B, and C such that the number of A's is odd and the
number of B's is odd ?
A, B, and C such that the number of A's is odd and the
number of B's is odd ?
xn
e x − e−x
=
2
n odd n !
e x − e−x
EGF for B's =
2
∞
xn
EGF for C's = ∑ = e x
n= 0 n !
EGF for A's = ∑
required EGF =
e3 x − 2e x + e−x
4
n

−
2 + (−1)n 
1
3

coefficient of x n = 
n !
4

required number =
2
 e x − e− x  x
e3 x − 2e x + e−x
 e =
required EGF = 

4
2

3n − 2 + (−1)n
4
5
Recurrence relations
6
Reproducing rabbits
A recurrence relation for the sequence {an} is an
equation that expressed an in terms of one or more of the
previous terms of the sequence, for all integers n ≥ n0
A sequence is called a solution of a recurrence relation
if its terms satisfy the recurrence relation.
Suppose a newly-born pair of rabbits, one male, one
female, are placed on an island. A pair of rabbits does
not breed until they are 2 months old. After they are
two months old, each pair of rabbits produces another
pair each month.
a2 = 5 − 3 = 2
Suppose that our rabbits never die and that the female
always produces one new pair (one male, one female)
every month from the second month on. The puzzle
that Fibonacci posed was...
a3 = 2 − 5 = −3
How many rabbits will there be in one year ?
an = an−1 − an−2
a0 = 3, a1 = 5
n≥2
Initial conditions
7
8
2
In the beginning …
Enter recurrence relations
Let f n be the number of rabbits after n months.
f1 = 1, f 2 = 1
f n = f n−1 + f n−2
Number of pairs
2 months old
Number of
existing pairs
9
Towers of Hanoi
Fibonacci sequence
10
Towers of Hanoi
Let H n be the number of moves required to
solve the problem with n disks.
H1 = 1
H n = 2 H n−1 + 1
N disks are placed on first peg in order of size.
The goal is to move the disks from the first peg to the second peg
Only one disk can be moved at a time
A larger disk cannot be placed on top of a smaller disk
11
12
3
Towers of Hanoi solution
The end of the world ?
H n = 2 H n−1 + 1
An ancient legend says that there is a tower in Hanoi where
the monks are transferring 64 gold disks from one peg to
another according to the rules of the puzzle.
= 2(2 H n−2 + 1) + 1 = 22 H n−2 + 2 + 1
= 22 (2 H n−3 + 1) + 2 + 1 = 23 H n−3 + 22 + 2 + 1
#
#
=2
The monks work day and night, taking 1 second to transfer
each disk. The myth says that the world will end when they
finish the puzzle.
How long will this take ?
n−1
H1 + 2
n−2
+2
n−3
+" + 2 +1
264 −1 = 18, 446, 744, 073, 709,551, 615
= 2n−1 + 2n−2 + 2n−3 + " + 2 + 1
It will take more than 500 billion years to solve the puzzle !
= 2n −1
13
14
More recurrence relations
A familiar sequence ?
How many bit strings of length n do not have 2 consecutive 0’s ?
How many bit strings of length n do not have 2 consecutive 0’s ?
Let an be the number of such bit strings of length n.
End with 1:
Any bit string of length n-1
with no two consecutive 0’s
End with 0:
Any bit string of length n-2
with no two consecutive 0’s
1
Let an be the number of such bit strings of length n.
an−1
an = an−1 + an−2
a1 = 2 = f 3
a2 = 3 = f 4
1
0
an−2
an = an−1 + an−2
a3 = 3 + 2 = 5 = f 5
a4 = 5 + 3 = 8 = f 6
an = f n + 2
15
16
4
How many ways can you multiply ?
How many ways can you multiply ?
In how many ways can you parenthesize the
Let Cn be the number of ways of parenthesizing
product of n + 1 numbers x0 ⋅ x1 ⋅ x2 ⋅" xn ?
the product x0 ⋅ x1 ⋅ x2 ⋅" xn
e.g. (( x0 ⋅ x1 ) ⋅ x2 ) ⋅ x3 ,
( x0 ⋅ x1 ⋅" xk ) ⋅ ( xk +1 ⋅" xn )
( x0 ⋅ ( x1 ⋅ x2 ))) ⋅ x3 ,
Ck
( x0 ⋅ x1 ) ⋅ ( x2 ⋅ x3 ),
Cn−k−1
n−1
Cn = ∑ Ck ⋅ Cn−k −1
x0 ⋅ (( x1 ⋅ x2 ) ⋅ x3 ),
k =0
x0 ⋅ ( x1 ⋅ ( x2 ⋅ x3 )).
Let Cn be the number of ways of parenthesizing
a product of n + 1 numbers.
C3 = 5
nth Catalan number
17
C0 = 1, C 1= 1
Solving recurrence relations
Solving recurrence relations
A linear homogeneous recurrence relation of degree k with
constant coefficients is a recurrence relation of the form
an = c 1 an−1 + c 2 an−2 + " + c k an−k
an = c 1 an−1 + c 2 an−2 + " + c k an−k
18
Try an = r n
r n = c 1 r n−1 + c 2 r n−2 + " + c k r n−k
where c1 ,… ck are real numbers and ck ≠ 0
r n − c 1 r n−1 − c 2 r n−2 −" − c k r n−k = 0
r k − c 1 r k −1 − c 2 r k −2 −" − c k −1 r k −1 − ck = 0
an = an−5
an = an−1 + an2−2
an = n ⋅ an−1
Characteristic equation
19
20
5
Solving recurrence relations
Solving recurrence relations
a2 = c 1 an−1 + c 2 an−2
f n = f n−1 + f n−2
Let r1 , r2 be the roots of the characteristic equation
r 2 − c 1 r − c2 = 0
Let r1 , r2 be the roots of the characteristic equation
r 2 − r −1 = 0
(
)
r = (1− 5 ) / 2
r1 = 1 + 5 / 2
Then the solution to the recurrence relation is
of the form an = α 1 r1n +α 2 r2n
2
Then the solution to the recurrence relation is
n
21
n
1 + 5 
1− 5 
 +α 

of the form f n = α 

 2 
 2 
1
2
22
Solving recurrence relations
f n = f n−1 + f n−2
n
n
1 1 + 5 
1 1− 5 
 −

fn =


5  2 
5  2 
23
6