6
7/29/2019 lec8_4 http://slidepdf.com/reader/full/lec84 1/6 1 COS 341 Discrete Mathematics Exponential Generating Functions and Recurrence Relations 2 Textbook ? 12 students said they needed the textbook, but only one student bought the text from Triangle. If you don’t have the book, please get it from Triangle. We will have to pay for the copies that aren’t taken ! 3 Derangements (or Hatcheck lady revisited) : number of permutations on objects without a fixed n  poi t n d n exponential generating function for number of derang ( e ) m t : en s  D x A permutation on can be constructed by picking a subset of constructing a derangement of K and fixing the elements of . Every permutation of [n] arises ex  act [] [] [ ly on , ce t ]- h  is way. n  K n n 0 EGF for all permutatio ! 1  1 n ! n n n  x n x = = = 0 EGF for permutations with all e 1  lem ! ents fixed x n n  x n e = = = 1 () 1  x  D x e = 4 Derangements 1 () 1  x  D x  x e = 1 () 1  x  D x e = 0 0 ( 1) ! n n n n n  x n = = = 0 ( coefficient o ) ! ! 1 n n n n  x = = = 0 ( 1) ! ! n n d n = = Different proof in Matousek 10.2, problem 17

lec8_4

Embed Size (px)

Citation preview

Page 1: lec8_4

7/29/2019 lec8_4

http://slidepdf.com/reader/full/lec84 1/6

1

COS 341 Discrete Mathematics

Exponential Generating

Functionsand Recurrence Relations

2

Textbook ?

• 12 students said they needed the textbook, but only one

student bought the text from Triangle.

• If you don’t have the book, please get it from Triangle.

• We will have to pay for the copies that aren’t taken !

3

Derangements (or Hatcheck lady revisited)

: number of permutations on objects without a fixed n poi tnd n

exponential generating function for number of derang( e) m t: en s D x

A permutation on can be constructed by picking

a subset of constructing a derangement of K and

fixing the elements of .

Every permutation of [n] arises ex

 

act

[ ]

[ ]

[

ly on

,

ce t

] -

h

 

is way.

n

 K n

n K 

0

EGF for all permutatio! 1

 1

s n!

n

n

n x

n x=

= =−

0

EGF for permutations with all e1

 lem!

ents fixedxn

n

 xn

e=

= =∑

1 ( )1

 x D x e= ⋅− 4

Derangements1

( )1

 x D x x

e= ⋅−

1( )

1

 x D x e−=

0 0( 1) !

nn n

n n

 x

n

= =

∞ = − ∑ ∑

0

(coefficient o

)

! !f 

1nk 

n

nd 

n k  x

=

− = = ∑

0

( 1)!

!

n

n

d nk =

− = ∑

Different proof in Matousek 10.2, problem 17

Page 2: lec8_4

7/29/2019 lec8_4

http://slidepdf.com/reader/full/lec84 2/6

5

ExampleHow many sequences of 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 ?

n

odd

EGF for A's!

n

n

 x

n= ∑

2

 x xe e−−=

EGF for B's2

 x xe e−−=

0

EGF for C'!

s  n

n

 x x

ne

=

== ∑2

required EG2

F x x

 xe ee

− − =

3

4

2 x x xe e e−− +=

6

ExampleHow many sequences of 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 ?

n

3

required EGF4

2 x x xe e e−

=− +

coefficient o1 3 ( 1)

f ! 4

2nn n

 xn

− + − =

required number 3 ( 1)

4

2n n− + −=

7

Recurrence relations

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 relationif its terms satisfy the recurrence relation.

1

2

3

2

0 1

2

3, 5

5 3 2

2 5 3

n n n

a

a a a n

a a

a

− −= −

= − =

= −

= =

= −

Initial conditions

8

Reproducing rabbits

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.

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...

How many rabbits will there be in one year ?

Page 3: lec8_4

7/29/2019 lec8_4

http://slidepdf.com/reader/full/lec84 3/6

9

In the beginning …

10

Enter recurrence relations

Let be the number of rabbits after months.n

 f n

1 2  +

n n n f f  − −=

 Number of pairs

2 months old

 Number of 

existing pairs

Fibonacci sequence

1 21, 1  f f  = =

11

Towers of Hanoi

 N disks are placed on first peg in order of size.

Only one disk can be moved at a time

The goal is to move the disks from the first peg to the second peg

A larger disk cannot be placed on top of a smaller disk 12

Towers of Hanoi

Let be the number of moves required to

solve the problem with disks.

n H 

n

1 1 H  =

12 1

n n H H  −= +

Page 4: lec8_4

7/29/2019 lec8_4

http://slidepdf.com/reader/full/lec84 4/6

13

Towers of Hanoi solution

12 1

n n H H  −= +

22 22(2 1) 1 2 2 1n n H H − −= + + = + +

2 3 2

3 32 (2 1) 2 1 2 2 2 1

n n H H − −= + + + = + + +

#

#1 2 3

12 2 2 2 1n n n H − − −

= + + + + +"1 2 32 2 2 2 1n n n− − −

= + + + + +"

2 1n= −

14

The end of the world ?

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.

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 ?

64

2 1 18,446,744,073,709,551,615−=

It will take more than 500 billion years to solve the puzzle !

15

More recurrence relations

How many bit strings of length n do not have 2 consecutive 0’s ?

Let be the number of such bit strings of length .na n

End with 1:

End with 0:

Any bit string of length n-1with no two consecutive 0’s

1

Any bit string of length n-2

with no two consecutive 0’s1 0

1na −

2na −

1 2 

n n na a a− −= +

16

A familiar sequence ?

How many bit strings of length n do not have 2 consecutive 0’s ?

Let be the number of such bit strings of length .na n

1 2 n n na a a− −= +

1

2

2

3

a

a

=

=

3

4

3 2 5

5 3 8

a

a

= + =

= + =

2n n

a f  +

=

3 f  =

4 f  =

5 f  =

6=

Page 5: lec8_4

7/29/2019 lec8_4

http://slidepdf.com/reader/full/lec84 5/6

17

How many ways can you multiply ?

0 1 2

In how many ways can you parenthesize the

 product of numbers ?1 nn x x x x+ ⋅ ⋅ ⋅"

0 1 2 3

0 1 2 3

0 1 2 3

0 1 2 3

0 1 2 3

(( ) ) ,

( ( ))) ,

( ) ( ),

(( ) ),

( ( )).

e.g. x x x

 x x x x

 x x x x

 x x x x

 x x x x

⋅ ⋅ ⋅

⋅ ⋅ ⋅

⋅ ⋅ ⋅

⋅ ⋅ ⋅

⋅ ⋅ ⋅

3

Let be the number of ways of parenthesizing

a product of numbers.1

5

nC 

n

+

= 18

How many ways can you multiply ?

0 1 2

Let be the number of ways of parenthesizing

the product

n

n

 x x x x⋅ ⋅ ⋅"

1

0 1 1( ) ( )

k  n k 

nk k 

C  C 

 x x x x

− −

+⋅ ⋅ ⋅ ⋅

" "

1

1

0

n

n k n k  

C C C −

− −=

= ⋅∑

nth Catalan number 

0 11, 1C C = =

19

Solving recurrence relations

1 1 2 2

1

A linear homogeneous recurrence relation of degree with

constant coefficients is a recurrence relation of the form

where are real numbers and, 0

n n n k n k  

k k 

a c a c a c a

c c c

− − −= + + +

… ≠

"

5

2

1 2

1

n n

n n n

n n

a a

a a a

a n a

− −

=

= +

= ⋅

20

Solving recurrence relations

1 1 2 2n n n k n k  a c a c a c a− − −= + + +"

Try   n

na r =

1 21 2

1 2

1 2

1 2 1

1 2 1

0

0

n n n n k  k 

n n n n k  

k k k k  

k k 

r c r c r c r  

r c r c r c r  

r c r c r c r c

− − −

− − −

− − −−

= + + +

− − − − =

− − − − − =

"

"

"

Characteristic equation

Page 6: lec8_4

7/29/2019 lec8_4

http://slidepdf.com/reader/full/lec84 6/6

21

Solving recurrence relations

2 1 1 2 2n na c a c a− −= +

1 2

2

1 2

Let be the roots of the characteristic equa, ion

0

tr r 

r c r c− − =

1 1 2 2

Then the solution to the recurrence relation is

of the form n n

na r r = α + α

22

Solving recurrence relations

1 2n n n f f f  − −= +

( )

( )

1 2

2

1

2

Let be the roots of the character ,

1 0

1 5 / 2

1 5

istic equat

/

ion

2

r r 

r r 

− − =

= +

= −

1 2

Then the solution to the recurrence relation is

of th1 5 1 5

2e form

2

n n

n f   + − = α +α

23

Solving recurrence relations

1 2n n n f f f  − −= +

1 1 5 1 1 5

2 25 5 

n n

n f  

+ − =