0% found this document useful (0 votes)
286 views88 pages

Combinatorial Mathematics

This three-day course on combinatorial mathematics covers topics including enumerating problems, counting objects like graphs and trees, and asymptotics. The course consists of 15 lectures over the three days, covering topics such as permutations, combinations, generating functions, partitions of integers, and asymptotic approximations. Exercises are included. The objective is to give students the ability to solve enumeration problems and convert complex expressions into simple approximations.

Uploaded by

Richard Mcdaniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
286 views88 pages

Combinatorial Mathematics

This three-day course on combinatorial mathematics covers topics including enumerating problems, counting objects like graphs and trees, and asymptotics. The course consists of 15 lectures over the three days, covering topics such as permutations, combinations, generating functions, partitions of integers, and asymptotic approximations. Exercises are included. The objective is to give students the ability to solve enumeration problems and convert complex expressions into simple approximations.

Uploaded by

Richard Mcdaniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

COMBINATORIAL MATHEMATICS

Instructor:

Jon T. Butler, Naval Postgraduate School, Monterey, CA USA

Time:

Three Day Course

Objective:

To give students the ability to solve enumeration problems, including the


counting of steps in a program (time of execution) and the counting of objects commonly
found in research problems, such as graphs and trees. Asymptotics will be covered,
allowing the student to convert complex expressions (common to many enumeration
problems) into simple approximations.

Time

Day #1

1000-1050 Lecture #1: Introduction,


combinations and permutations, Pascals triangle,
1100-1150 Lecture #2:
Circular
permutations. Choice with
repetition.
1150-1300 Lunch
1300-1450 Exercise #1
1400-1450 Lecture #3: Combinational
identities
1500-1550 Lecture #4: Distribution of
objects to cells ((non)/distinct objects (non)distinct
cells).
1600-1650 Lecture #5:
Pigeonhole
principle.

Day #2

Day #3

Lecture #6:
Ordinary
generating functions. How
to use.
Lecture #7:
Generating
function example - trees

Lecture #11: Recurrence


relations - Using generating
functions to solve.
Lecture #12:
Inclusion
/exclusion. Derrangements.

Lunch
Exercise #2
Lecture #8: Exponential
generating functions.
Lecture #9: Distributing
nondistinct objects into nondistinct cells.
Stirlings
numbers.
Lecture #10: Partitions of
integers.

Lunch
Exercise #3
Lecture #13: Asymptotic
approximations Lecture #14: Asymptotic
approximations - Finding
simple
closed
form
solutions.
Lecture #15: Example of
asymptotic approximations

Notes: Lecture notes will be handed out.


References:
[1] C. L. Liu, Introduction to Combinatorial Mathematics, McGraw-Hill, 1968.
years old, this is a very good textbook.

Although 30

[2] J. Riordan, An Introduction to Combinatorial Analysis, McGraw-Hill, 1958. Classic text,


advanced and formal.
[3] A. Tucker, Applied Combinatorics, John Wiley & Sons, 1984.
examples.

Easy to read - many

[4] E. A. Bender and S. G. Williamson, Foundations of Applied Combinatorics, Addison-Wesley


Publishing Co., 1991. Good text that was not well typeset.
[4] R. P. Grimaldi, Discrete and Combinatorial Mathematics, Addison-Wesley Publishing Co.,
1994. Easy to read and covers other topics - logic, set theory, relations, functions, finite
state machines, graph theory, modern algebra, and switching theory.
[5] N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973. A list of integer
sequences. This is a valuable reference when you have the question Has anyone derived
this sequence before? It contains about 2300 sequences.
[6] N. J. A. Sloane and S. Plouffe, The Encyclopedia of Integer Sequences, Academic Press,
San Diego, 1995. Updated version of the above. It contains 5487 sequences.
[7] N. J. A. Sloane and S. Plouffe, The Encyclopedia of Integer Sequences, online version http://www.research.att.com/~njas/sequences/index.html. This version contains over 25,000
sequences.

Instructor:
Jon T. Butler, Professor
Department of Electrical and Computer Engineering
Naval Postgraduate School, Code EC/Bu
Monterey, CA 93943-5121 U.S.A.
408-656-3299 (O) 408-656-2760 (FAX)
E-mail:
[email protected]
Homepage:
http://dubhe.cc.nps.navy/mil/~butler

Combinations and Permutations #1 - J. T. Butler


Rule of Sum and
Product

Example
Suppose

there are 5 red balls


and 10 green balls. Then,
there are 5+10=15 ways to
choose a ball of any color.

Rule of sum:
If one event can occur in m ways and
another event can occur in n ways,
there are m + n ways in which exactly
one event can occur.
Combs and Permus -1 J. T. Butler

Combs and Permus -1 J. T. Butler

Example

Rule of Product:

Suppose

there are 5 red balls


and 10 green balls. Then,
there are 5 . 10 = 50 ways to
choose a red ball AND a
green ball.

If one event can occur in m


ways and another event can
occur in n ways, then there are
m . n ways the two events can
occur together.
Combs and Permus -1 J. T. Butler

Combs and Permus -1 J. T. Butler

Permutations

Example

How many ways P(n,n) are there to arrange


n of n objects?

The address register in your PC has 24


bits. How many locations can your
PC access?

By the rule of product


P (n,n) = n (n 1) (n 2) ... 2 1

Each bit can be chosen independently


in 2 ways. By the rule of product,
there are 2 . 2 .... . 2=2n = 16,777,216
or 16 megabytes.
Combs and Permus -1 J. T. Butler

n ways to n 1 ways n 2 ways


choose
to choose to choose
1st object 2nd object 3rd object

Combs and Permus -1 J. T. Butler

Combinations and Permutations #1 - J. T. Butler


n (n-1) (n-2) ... 2 1 = n!

P (n,r) = n (n 1) (n 2) ... (n r +1) can be


viewed as a distribution of balls to cells

n factorial

r positions (cells)
6444447444448

Also,
P (n, r ) = n (n 1) (n 2) K (n r + 1)

n!
(n r )!
n ways to n 1 ways to
fill the
fill the
1st position 2nd position

This is called permutation.

Combs and Permus -1 J. T. Butler

Combs and Permus -1 J. T. Butler

Notation:

n r +1 ways
fill the
rth position

Remember

P(n, r ) is the number of permutations of r


objects from a set of n distinct objects

Given a set S of n distinct objects, a


permutation is an arrangement or
ordering of objects from S.

Alternative notation:
Prn = n Pr ( = P (n, r ))

Combs and Permus -1 J. T. Butler

Combs and Permus -1 J. T. Butler

Example

10

Example
How many ways are there to arrange the three
letters in ALL?

How many permutations are there of two


elements of S={a,b,c,d}?

If all letters were distinct,like AL 1 L 2 , there


be 3! = 6. But two of letters are identical.
ALL AL1 L 2 AL 2 L 1

There are 12: ab, ba, ac, ca, ad, da, bc,
cb, bd, db, cd, and dc.

LAL L1AL 2

P(4,2) = 4 . 3 = 12.
Combs and Permus -1 J. T. Butler

L 2 AL1

LLA L1 L 2 A L 2 L 1A

11

Combs and Permus -1 J. T. Butler

12

Combinations and Permutations #1 - J. T. Butler


In general,

We observe that :

If there are n1 objects of the first type, n2

2 ! (the number of arrangements

objects of the second type, ... , nr objects

of ALL) = number of arrange -

of the r - th type, such that the total number

ments of AL1L2 . That is, the

n of objects n = n1 + n2 +...+nr , then the


number of arrangements of the n objects is

number of arrangements of ALL


=

3!
= 3.
2!

Combs and Permus -1 J. T. Butler

n!
.
n1 ! n2 !... nr !
13

Combs and Permus -1 J. T. Butler

14

Example

n!
is called a
n1 ! n2 !... nr !

If six people, A, B, C, D, E, and F are seated about a


round table, how many circular arrangements are
possible?
A

multinomial.

D
C
F

C
B

A
D

D
D

C F
F

C
B

(a)
(b)
(c)
(d)
Here, (a) and (b) are identical whereas (a)=(b), (c), and
(d) are different.
Combs and Permus -1 J. T. Butler

15

Combs and Permus -1 J. T. Butler

Suppose that A, B, and C are females, and


D, E, and F are males. We now want to
arrange them so the sexes alternate. How
many ways are there to place the people?
Choose A, a female to be in top position.
There are 3! ways to arrange the males and 2!
ways to arrange the remaining females or
3! 2! = 12 ways.

We can arbitrarily choose one person,


say A, to be at the top. Then, we
can choose the order of the remaining
ones in 5! ways. Thus, the number of
circular permutations on 6 objects is 5!.

Combs and Permus -1 J. T. Butler

16

17

Combs and Permus -1 J. T. Butler

18

Combinations and Permutations #1 - J. T. Butler


Combinations

Suppose we want the number of ways

How many ways are there to arrange


5 red balls and 10 green balls?

to choose 5 objects from 15 distinct


objects. Notice, there is a one - to - one

There are 15 objects, 5 of the first kind


and 10 of the second. Thus, there are
15!
arrangements.
5! 10!
Combs and Permus -1 J. T. Butler

correspondence between an arrangement


of 5 red balls and 10 green balls and a
selection of 5 objects from 15. Let the
red balls signify which object is selected.

19

Combs and Permus -1 J. T. Butler

Let C (n, r ) be the number of ways to


select r objects from n. Then, we saw
15!
C (15,5) =
. In general, C( n, r ) =
5!10!
n!
P ( n, r )
=
.
r !(n r )!
r!

Combs and Permus -1 J. T. Butler

Alternative words:
C(n,r) is the number of ways to choose r
objects from n distinct objects.
C(n,r) <=> n choose r

Alternative notation:
Crn = n Cr =

21

22

Note

FG nIJ = n! = FG n IJ .
H r K r!(n - r )! H n - rK

Given a set S of n distinct objects, a


combination is a subset S of S.
combination <=> selection

2. When one chooses an object, it cannot

Given a set S of n distinct objects, a


permutation is an arrangement of elements.
permutation <=> arrangement

be chosen again. This is choice without


repetition.

Combs and Permus -1 J. T. Butler

FG nIJ = C(n, r )
H rK

Combs and Permus -1 J. T. Butler

Notes:
1.

20

23

Combs and Permus -1 J. T. Butler

24

Combinations and Permutations #1 - J. T. Butler


Question:
Rule of sum:

Let S = {a,b,c,d}. Then {a,b} and {c,d}


are combinations.
How many
combinations of size 2 are there of S?

C(n,r) = C(n1, r) + C(n1, r1)


Choose r objects
from n 1 objects
not including a
special object.

Answer:
{a,b}, {a,c}, {a,d}, {b,c}, {b,d}, and
{c,d} are all of the combinations of S of
size 2. There are 6. There are 12
permutations, two for each combination
above.
Combs and Permus -1 J. T. Butler

25

Choose the special object


and r 1 other objects
from n 1 objects not
including the special
object.

Combs and Permus -1 J. T. Butler

26

Pascals Triangle

C(4,2) = C(3,2) +C(3,1) = 3+3 = 6

Sum Diff.

1
2
1 2
1
4
1 3 3 1
8
1 4 6 4 1
16
1 5 10 10 5 1
32
1 6 15 20 15 6 1 64

6447448
6447448
{b,c}, {b,d}, {c,d} {a,b}, {a,c}, {a,d}

a is the special object.

Combs and Permus -1 J. T. Butler

27

Combs and Permus -1 J. T. Butler

1
0
0
0
0
0
0

28

How to build Pascals triangle


1.

Write the 1s

1
2.

Brief history

1
1

This was first published in 1653


by Pascal in one of the first
publications on probability.

Fill in the remaining numbers by


adding pairs
1
1
1
1

Combs and Permus -1 J. T. Butler

1
2

1
3

29

Combs and Permus -1 J. T. Butler

30

Combinations and Permutations #1 - J. T. Butler


r
n
0
1
2
3
4
5
6

0
1
2

1 2
1
1 3 3 1
5 1 4 6 4
1
6
1 5 10 10 5
1
7
1 6 15 20 15 6 1
4

Combs and Permus -1 J. T. Butler

Note:

Sum Diff.

1
2
4
8
16
32
64

1
0
0
0
0
0
0

Pascals Rule is used to derive the


entries of this table.
That is,
C(0,0) = 1
and
C (n,r) = C (n 1, r) +C (n 1, r 1).

31

Combs and Permus -1 J. T. Butler

r
n
0
1
2
3
4
5
6

0
1

1 +1
3
1 +2 +1
4
1 +3 +3 +1
5 1 +4 +6 +4 +1
6
1 +5 +10 +10 +5 +1
7
1 +6 +15 +20 +15 +6 +1

Combs and Permus -1 J. T. Butler

32

r
Sum

Diff.

1
2
4
8
16
32
64

1
0
0
0
0
0
0

n
0
1
2
3
4
5
6

33

0
1

Sum Diff.

1 -1
3
1 -2 +1
4
1 -3 +3 -1
5 1 -4 +6 -4 +1
6 1 -5 +10 -10 +5 -1
7
1 -6 +15 -20 +15 -6 +1

Combs and Permus -1 J. T. Butler

34

Naming the Ace


Paradox

Note:
C(n, r) is the number of ways to choose
r objects from n distinct objects.
C(n, r) is called a binomial coefficient.
Binomial coefficients satisfy thousands
of identities.
Combs and Permus -1 J. T. Butler

1
2
4
8
16
32
64

35

Combs and Permus -1 J. T. Butler

36

1
0
0
0
0
0
0

Combinations and Permutations #1 - J. T. Butler


EXAMPLE:

A Deck of Cards is a set of 52 cards

There are four aces

Each card as a value

ace of hearts
ace of diamonds
ace of spades
ace of clubs

2 3 4 5 6 7 8 9 10 J Q K A
where
J = Jack, Q = Queen
K = King, and A = Ace
and a suit

Similarly, there are four kings, four


queens, etc.

Hearts Diamonds Spades Clubs


Combs and Permus -1 J. T. Butler

37

Combs and Permus -1 J. T. Butler

38

Definition:
To deal 52 cards to 4 people
means to randomly give 13 cards to 4
people. Usually, a person knows
only those cards given to him/her.

Clubs
Spades
Diamonds

Definition:

Hearts

A hand is a set of 13 cards given


to one person.

Combs and Permus -1 J. T. Butler

39

Combs and Permus -1 J. T. Butler

40

Question: Naming the ace


52 cards are distributed to 4 people. One
person says I have an ace. What is the
probability he/she has another ace?

Question:
Why should naming the ace change
the probability?

Answer: 5359/14498 < 2 .


However, suppose he/she says, I have an
ace of spades. What is the probability
he/she has another ace?
1

Answer: 11686/20825 > 2 !


Combs and Permus -1 J. T. Butler

41

Combs and Permus -1 J. T. Butler

42

Combinations and Permutations #1 - J. T. Butler


Small Deck

Below are the six different hands with


two cards

Shown below is a much smaller deck.


In this case, we give two cards each
to two people.

Combs and Permus -1 J. T. Butler

43

Boy
Boy
Girl
Girl

Boy
Girl
Boy
Girl (impossible)

Combs and Permus -1 J. T. Butler

44

46

Playing Keno
Question: Keno is a game in which you
choose 6 distinct numbers from 1 to 80.
The casino chooses 20 distinct numbers
from 1 to 80. You enter a choice of
numbers for $0.60 and the casino pays
you an amount of money depending on
how many of the 6 numbers you have
chosen matches the numbers chosen by
the casino.

Since only one of three


possible
outcomes consists of two boys, the
probability is 1/3 !
Combs and Permus -1 J. T. Butler

Mr. Smith has two children. At least


one is a boy. What is the probability
that the other is a boy also?

There are four equally likely outcomes


Younger

Children Paradox

45

Older

Combs and Permus -1 J. T. Butler

There are 6 ways a person can have a


hand of two cards, as shown. If
someone says, I have an ace, the
probability he/she has another ace is
1/5 (there are 5 hands with at least one
ace, only one of which has another
ace). If he/she says, I have an ace of
spades, then the probability he/she
has another ace is 1/3.
Combs and Permus -1 J. T. Butler

47

Combs and Permus -1 J. T. Butler

48

Combinations and Permutations #1 - J. T. Butler


Answer:

For example, you win $1,000 if all


six numbers you have chosen were
also chosen by the casino. What is

Number of
ways k of 80
numbers can
match

Number of
ways casino
can choose
remaining
numbers

FG 80IJ FG 80 k IJ FG 60 IJ
H k K H 20 k K H 6 k K
P( k ) =
FG 80IJ FG 80IJ
H 20K H 6 K

the probability P( k ) that exactly k of


the numbers you have chosen were
chosen by the casino, for 0 k 6?

Total number of
ways casino can
choose numbers
Combs and Permus -1 J. T. Butler

P(k)

0
1
2
3
4
5
6

0.167
0.363
0.308
0.130
0.029
0.003
0.0001

49

50

Playing Keno
Probability of matching k numbers

0.138
0.278
0.305
0.250
0.028
0.000
0.000

Probability
0.4
0.3
0.2
0.1
0

This table shows the exact


probability, as calculated
from (1). Also shown is
the probability as extracted during a class experiment in which 40 students
chose 6 numbers and the
instructor chose 20.

01
2
k 3 4

51

Probability
0.4
0.3
0.2
0.1
0

Experiment
5

Exact

Combs and Permus -1 J. T. Butler

52

Combs and Permus -1 J. T. Butler

54

How to Become Rich


by Playing Keno
You cannot.
Spend your
money somewhere else.

Combs and Permus -1 J. T. Butler

(1)

Total number of
ways player can
choose numbers

Combs and Permus -1 J. T. Butler

Class exp.

Combs and Permus -1 J. T. Butler

Number of
ways player
can choose
remaining
numbers

53

Combinations and Permutations #2 - J. T. Butler


Dollar Paradox

Outcome You receive

Consider the following game:


Mr. Smith flips a coin. If it is
heads, he pays you $1.00. If it is
tails, he flips again. If it is heads,
he pays you $2.00. If it is tails, he
flips again. If it is heads, he pays
you $4.00, etc.

H
TH
TTH
TTTH

$1.00
$2.00
$4.00
$8.00

However, you must pay to play


this game. What should you be
willing to pay?

Combs and Permus -2 J. T. Butler 1

Combs and Permus -2 J. T. Butler 2

Yes, you should be willing to pay any


amount. Why? You can expect to win

Of course, if it costs $1.00, you


should play; you will receive
back at least $1.00. However,
should you pay $10,000, for
example?

1
1
1
$1.00 + $2.00 + $4.00+K
2
4
8
= $0.50 + $0.50 + $0.50+K ,
which, even with inflation, is a large
amount of money.

Combs and Permus -2 J. T. Butler 3

Combs and Permus -2 J. T. Butler 4

Combinations with
Repetition

Example:
If r = 2 and n = 3, then this number is
6. Let S = {a,b,c}. Then, one can
choose {a,b}, {a,c}, {b,c}, {a,a},
{b,b}, and {c,c}. If repetition is not
allowed, this number is 3 - {a,b},
{a,c}, and {b,c}.

Question:
How many ways can one choose r objects
from n distinct objects when repetition is
allowed? That is, one can choose any
object 0, 1, 2, ... etc. times.
Combs and Permus -2 J. T. Butler 5

Combs and Permus -2 J. T. Butler 6

Combinations and Permutations #2 - J. T. Butler


Answer:

The r remaining objects represent the


choice with repetition. For example,
for r = 2 and n = 3, we have

Each object can be chosen 0, 1,


2, ... times.
A choice of r
objects can be represented as
follows. Arrange n + r 1
objects in a row, and choose
n 1 as dividing lines.

0 0 <=> ab
0 0 <=> ac
0 0 <=> bc

0 0 <=> aa
0 0 <=> bb
0 0 <=> cc

are the dividing lines.


them as shown above.

Combs and Permus -2 J. T. Butler 7

Choose

Combs and Permus -2 J. T. Butler 8

Example:

The dividing lines can be chosen in

Out of a large number of 1 , 5 , 10 ,


and 25 coins, in how many ways can
six coins be chosen?

C (n +r 1, n 1) = C (n +r 1, r)
ways. This is the number of ways to
choose r objects from n with
repetition.

This is the same as selecting six


coins from 1, 5, 10, and 25 with
repetition or
C (4 + 6 -1, 6) = C (9, 6) = 84.

Combs and Permus -2 J. T. Butler 9

Combs and Permus -2 J. T. Butler 10

How many outcomes are there if the 3


dice are indistinguishable (we do not
specify that one outcome occurred on
the first roll, second roll, and third roll?

Example:
When three distinct dice are rolled, the
number of outcomes is 6 . 6 . 6 =216.

This is the same as selecting 3


numbers from 6 with repetition or
C (6 +3 -1, 3) = 56.

Here, 1 2 1 2 1 1
Combs and Permus -2 J. T. Butler 11

Combs and Permus -2 J. T. Butler 12

Combinations and Permutations #2 - J. T. Butler


Question:

Answer:

How many ways are there to go from


the southwest corner of a chessboard
to the northeast corner by making only
north and east moves?
B

To go from A to B, make 7 north


and 7 east moves. Once you choose the
north moves, the east moves are
determined. The north moves can be
chosen in

Go here

C (14,7) = 14!/(7! . 7!) = 3432


You are A
here

ways.

Combs and Permus -2 J. T. Butler 13

Combs and Permus -2 J. T. Butler 14

Question:

Answer:

How many of these 3432 ways consist of


four east move segments separated by
three north move segments? A segment is
one, two, etc. moves in the same direction.

The number of ways of choosing a path of


four east move segments is the same as placing seven indistinguishable balls in four
boxes with no box left empty

Go here

East Move
Segments
North Move
Segments

You are
here
Combs and Permus -2 J. T. Butler 15

Combs and Permus -2 J. T. Butler 16

This is the same as distributing


three balls in four boxes with
repetition. There are

Similarly, the number of ways to


choose three north segments is
C (3 + 4 -1, 4) = 6!/(4! . 2!) = 15

C ( 4 + 3 - 1, 3) = 6!/(3! . 3!)
= 20

Therefore, the answer is


20 . 15 = 300.

ways to do this.
Combs and Permus -2 J. T. Butler 17

Combs and Permus -2 J. T. Butler 18

Combinations and Permutations #2 - J. T. Butler


Example

a cell as the value of x i . We can conclude that


the number of solutions is the number of ways
to distribute 7 balls to 4 cells, where each cell
can have 0, 1, 2, ..., 7 balls. This is just the

How many solutions are there to the equation


x1 + x 2 + x 3 + x 4 = 7, where x i 0 for 1 i 4?
Imagine there are four cells representing x1 , x 2 ,
x 3 , and x 4 . Consider some distribution of 7 balls
to these cells. Interpret the number of balls in

number of ways to select 7 objects from 4 with


repetition or C (4 + 7 - 1, 4 - 1) = 120.

Combs and Permus -2 J. T. Butler 19

Combs and Permus -2 J. T. Butler 20

Example:

In general, the following are identical.

How many integer solutions are there to the

a) The number of integer solutions of the equation


x1 + x 2 +...+ x n = r , where x i 0 and 1 i n.
b) The number of ways to select r objects from

1 i 6? How many such solutions are there

n distinct objects with repetition.


c) The number of ways to distribute r nondistinct
objects to n distinct cells.

From our previous discussion, there are C (6 +

equation x 1 + x 2 +...+ x 6 = 10, where xi 0 for


to x1 + x 2 +...+ x 6 < 10 ?

10 - 1, 6 - 1) = 3003 solutions. We can view the


nonnegative solutions of x1 + x 2 +...+ x 6 < 10

Combs and Permus -2 J. T. Butler 21

Combs and Permus -2 J. T. Butler 22

Example

as equivalent to the solutions of x1 + x 2 +...


+ x 6 + x 7 = 9, where x i 0, for 1 i 7 .
In effect, x 7 is a "slack" variable. The
number of solutions to this equation is

Some

problems can be viewed


either as a permutation or as a
selection. Consider
Four volleyball teams A, B, C, and
D, each with 9 players, must be
made from 36 players. In how
many ways can this be done?

C ( 7 + 9 1, 7 - 1) = 5005.

Combs and Permus -2 J. T. Butler 23

Combs and Permus -2 J. T. Butler 24

Combinations and Permutations #2 - J. T. Butler


FG 9IJ ways. By the rule of product, the four
H 9K

Selection: To form Team A, select 9 players from

and

the 36 players in

FG 36IJ FG 27IJ FG18IJ FG 9IJ = FG 26! IJ FG 27! IJ FG 18! IJ FG 9! IJ


H 9 K H 9 K H 9 K H 9K H 9!27!K H 9!18!K H 9!9!K H 9!0!K

FG 36IJ ways. To form Team B,


H 9K

teams can be formed in

select 9 players from the remaining 27 players in

FG 27IJ . Similarly, form Teams C and D in FG18IJ


H 9K
H 9K

Combs and Permus -2 J. T. Butler 25

36!
2.145 1019
9! 9! 9! 9!

Combs and Permus -2 J. T. Butler 26

Permutation: View the 36 players as arranged in


a line. We ask "How many ways can we arrange
9 A' s, 9 B' s, 9 C's, and 9 D' s?, for each arrange ment corresponds to an assignment to the four teams.
This is the problem of counting permutations of
nondistinct objects.
36!
2.145 1019
9!9!9!9!

Combs and Permus -2 J. T. Butler 27

Combs and Permus -2 J. T. Butler 28

The Birthday Problem - J. T. Butler


Birthday Problem

Answer:

Question:

Compute the probability P(n)


that among a group of n people,
no two will have the same
birthday.

In a group of n people, what is the


probability P(n) that two (or more)
will have the same birthday? Assume
that the probability of being born on
any day is the same as any other day.
Birthday problem - J. T. Butler

Birthday problem - J. T. Butler

The number of ways n people can have

Example values of P(n)

birthdays is 365n . . The number of ways


n people can have different birthdays is
P ( 365, n ) = 365 364 ... ( 365 - n + 1)
and the probability we seek is
P (n) = 1 P ' (n) = 1
Birthday problem - J. T. Butler

P(n)

12
0.1670
15
0.2529
18
0.3469
21
0.4437
22
0.4757
23
0.5073
Thus, for a group of only 23 people, P(n) > 0.5!

P (365, n)
.
365n

Birthday problem - J. T. Butler

We assumed that the probability of being


born on any day is the same as on any other
day. That is, we assumed a uniform
probability distribution, as shown here.

Probability P(n) that two people (or more)


among n people have the same birthday
Probability of Coincidence
P(n)

Probability
of
Birthday
1
365

Jan. Mar.
/Feb. /Apr.

Number of People n
Birthday problem - J. T. Butler

Birthday problem - J. T. Butler

May
/Jun.
6

Jul.
/Aug.

Sep. Nov.
/Oct. /Dec.

The Birthday Problem - J. T. Butler


That is, the probability of birthdays is really like
this (from G. C. Berresford, The uniformity
assumption in the birthday problem, Math.
Magazine, vol. 53, no. 5, Nov. 1980).

Question:
If the actual probability distribution
is used instead of the uniform distribution, how does this change P(n),
the probability that two people out
of n have the same birthday?
Birthday problem - J. T. Butler

The data for this comes from 239,762 births in New York State in 1977.
Birthday problem - J. T. Butler
8

Answer #1:

where the sum is over all combinations of


n days from 365 days. Thus, the sum has

If the probability of birth on day i is


pi, then the probability P(n) that n
people will all have different
birthdays is
P ( n) = n ! pi1 pi2 K pin (1)

FG 365IJ
H 23 K

10 36 terms, when n = 23,

which will take an enormous amount of


computer time!

i1 <K< in

Birthday problem - J. T. Butler

Birthday problem - J. T. Butler

How is (1) derived in the case


of a uniform distribution?
We have
n!

FG IJ
H K

Birthday problem - J. T. Butler

FG IJ
H K

11

Here, the sum is over all ways to select n


days out of 365. The probability of being
1
born on each day is
. This is why we
365
365
can replace the sum by the factor
.
n

P (365, n)
n!
365n

P (365, n)
=
365n
365
n!
n
1
=
= n!
n
365
n selections 365

P '(n) =

10

FG IJ
H K

However, if the probability is not the same,


we can substitute the proper value.

from 365

Birthday problem - J. T. Butler

12

The Birthday Problem - J. T. Butler


Proof:

Identify two probabilities, p1 and


p2, such that p1 p2. Expand (1) about p1 and
p2, as follows:

Before showing a way to compute the


probability from an actual distribution,
we can say

P (n) = n! p1 p2

Theorem:

+ ( p1 + p2 )

The probability of two people having


the same birthday is smallest for the
uniform probability distribution.
Birthday problem - J. T. Butler

13

p1 p2 <

IJ
K

Thus,

15

(2)

in

14

Birthday problem - J. T. Butler

Compare p1 p2 with

1
= p1 ( p1 + p2 )
2
1
+ = ( p1 + p2 ) p2
2
2 = p1 p2
p p2
= 1
2

in1

can be shown as

follows. Assume p1 > p2 and define like


so
1
p1 = p2 + = ( p1 + p2 ) = p
(3)
2

Thus, this replacement will increase P(n)


(and decrease P(n)). It follows that the
smallest P(n) occurs with a uniform
probability distribution.

Birthday problem - J. T. Butler

p Kp

p Kp

FG 1 ( p + p )IJ
H2
K
1

in 2

i1
2 < i1 <K<in 1

i1
2 <i1 <K<in

Birthday problem - J. T. Butler

Replace both p1 and p2 by their average


1
( p1 + p2 ). This changes only the first term
2
2
1
of (2). However, p1 p2 < ( p1 + p2 ) . Why?
2

FG
H

p Kp

i1
2 <i1 <K<in 2

16

FG 1 ( p + p )IJ
H2
K
1

= p2

where from (3), we have


p1 = p + and p2 = p
p1 p2 = (p + ) (p ) = p2 2

(4)

FG 1 ( p + p )IJ .
H2
K
2

It follows that p1 p2 < p2 =

Q.E.D.
Birthday problem - J. T. Butler

17

Birthday problem - J. T. Butler

18

The Birthday Problem - J. T. Butler


Divide the range of probabilities into different
values {V1, V2, , Vm}, and approximate any pj
by some Vk. Thus, we replace

Answer #2:
Berresford overcomes the enormous
computer time needed when there are
365 different probabilities by
allowing a smaller number (10) and
rounding the actual probability to the
nearest. He obtains the following.
Birthday problem - J. T. Butler

Probability of
being born on
day d

19

Probability of
being born on
day d

Birthday problem - J. T. Butler

That is,

FG m + n 1IJ
H n K

where

Day d

d p
i

= 365

i =1

= 1. Solving (1) by computer

i =1

for m = 10 yields
Birthday problem - J. T. Butler

Day d

Fd I
i

ni

is over the

(5)

FG m + n 1IJ
H n K

different m-tuples (n1, n2, , nm ) of nonnegative integers satisfying n1+n2+ +nm =n


.
Birthday problem - J. T. Butler
22

selecting m probability values for n objects


(people) with repetition. Such a choice
corresponds to a distinct m tuple (n1, n2, ,
nm), where ni is the number of occurrences of
and

n1 + n2 +K+ nm = n

P(n)
Uniform case

P(n)
Non-uniform
case

12
15
18
21
22
23

0.1670
0.2529
0.3469
0.4437
0.4757
0.5073

0.1683
0.2537
0.3491
0.4463
0.4783
0.5101

is the number of ways of

GH n JK V

n1 + n2 +K+ nm = n i =1

21

probability value Vi. Note that

20

P ( n) = n !

V3

V2

Let di be the number of birthdates that have


a probability value Vi for 1 i m in the
approximate distribution. Then, for the
approximate distribution, we have

V3

Birthday problem - J. T. Butler

by

There is very little difference!


23

Birthday problem - J. T. Butler

24

The Birthday Problem - J. T. Butler

Birthday problem - J. T. Butler

25

Pigeonhole Principle - J. T. Butler


Pigeonhole Principle

3 Pigeonholes
Pigeonholes

4 Pigeons

If 7 pigeons fly into 3 pigeonholes, then 1


pigeonhole has at least 3 pigeons.

If 4 pigeons fly into 3 pigeonholes, then 1


pigeonhole has at least 2 pigeons.
Pigeonhole Principle - J. T. Butler

7 Pigeons

Pigeonhole Principle - J. T. Butler

Example:
No person has more than 300,000 hairs
on his/her head. There are 1,280,000
people on the Monterey Peninsula.
Thus, at least two people on the
Monterey Peninsula have the same
number of hairs on their head.

...
n Pigeonholes

q. n +1 Pigeons

If q.n +1 pigeons fly into n pigeonholes, then


1 pigeonhole has at least q+1 pigeons.

Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler

What is the largest m such that the


following statement is always true:

number of hairs <=> pigeonholes

m people on the Monterey Peninsula

people

<=> pigeons
1,280,000
= 4.26
300,000

have the same number of hairs on their


head.

Thus, at least 5 people have the same number


of hairs on their head.

Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler


Example:

Any number in a1, a2, ... , a101 can


be expressed as ai = 2rq, where q is
odd. That is, q can be 1, 3, 5, ... ,
199 (100 different values for q).

Suppose 101 numbers a1, a2, ... , a101 are


chosen from 1, 2, ... , 200. There will
always be pair ai, aj such that ai divides aj.
divides:

3 divides 9

4 divides 64

4 divides 1

3 divides 7

Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler

Choosing 101 numbers requires choosing


the same q *. That is, the two numbers

Example:

have the form q 2 r1 and q 2 r2 , and, therefore,

A doctor tells his patient to take


48 pills over a 30 day period so
that his patient takes at least one
pill a day.

one divides the other.


* Apply the pigeonhole principle.

Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler

10

Consider the sum of the pills taken


beginning on Day #1

No matter what his patient does,


there will be consecutive days in
which the total number of pills
taken is 11.

0 < p1 < p2 < p3 < ... < p30 = 48 (1)

30 numbers
Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler

11

12

Pigeonhole Principle - J. T. Butler


Add 11 to every number

However, no pair within (1) can be the


same and no pair within (2) can be the
same. Thus, there is a j and an i such
that

11 < p1 +11 < p2 +11 < p3 +11


< ... < p30 +11 = 59

(2)

30 numbers

pj = pi + 11

There are 60 numbers here and the largest is


59. Thus, two numbers must be the same.*

This proves the statement.

*Pigeonhole principle.
Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler

13

Example:

The statement is not only true of 11,


but for all k from 1 to 30 except 16,
17, and 18. These are eliminated by

Triangle ACE is equilateral with AC=2.0 cm.


C

1 1 ... 1 19 1 1 ... 1
123
123
15
14

Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler

Divide the triangle into four disjoint subtriangles,


as shown. Since the side of each subtriangle is
1.0 cm., every point within a subtriangle is within
1.0 cm. of every other point that is in the same
C
subtriangle.

Let m be an odd positive integer. Prove


that there exists a positive integer n such
that m divides 2 n 1.
Consider the m + 1 positive integers 21 1,
2 2 1, 23 1, ..., 2 m 1, 2 m +1 1. There

Therefore, in applying the pigeonhole


principle, choosing five points requires two
points to be on/within the same subtriangle.
Pigeonhole Principle - J. T. Butler

16

Example:

Show that, if five points are selected from the


inside of the triangle, then at least two are a
distance 1.0 cm. or less apart!

15

14

exists integers s, t with 1 s < t m + 1,


where 2 s 1 and 2t 1 that have the same
Pigeonhole Principle - J. T. Butler

17

18

Pigeonhole Principle - J. T. Butler


remainder upon division by m (by the
pigeonhole principle). Hence, 2 s 1 =
q2 m + r and 2t 1 = q1m + r , so that 2t 2 s
= (q2 q1 )m. But, 2 t 2 s = 2 s (2t s 1).
Since m is odd, gcd( 2 s ,1) = 1. Hence,
m | (2t -s 1) (i.e. m divides (2t - s 1) with
0 remainder), and the result follows with
n = t - s.
Pigeonhole Principle - J. T. Butler

Pigeonhole Principle - J. T. Butler

19

20

Ordinary Generating Functions #1 - J. T. Butler


List the choices

Generating
Generating Functions
Functions
Question: How many ways are there to make

change for 50 yen?

Example:
5

is one way to make change

5 10 10 10 10

for 50 yen.

50

50 50

50 50 50

List the choices using + OR and


AND

14243
0 yen

14243
5 yen

50

14243
10 yen

(
(
(
(

14243
1 yen

10

14243
50 yen

14243
6 yen

Generating Func. 1 - J. T. Butler 3

Now substitute
= x0 = 1, 1 = x1,

1 1

= x5 ,

1 1 1

5 5 5

10

50 50

50 50

20

30

10

10 10

10 10 10

50

50 50

50 50 50

)
)
)
)

Generating Func. 1 - J. T. Butler 4

10

= x10,

5 5

50

Multiply this out

= x50

c1 + x + x x + x x x +Kh b1 + x + x x
+ x x x + Kg c1 + x + x x + x x x +Kh
c1 + x + x x + x x x +Kh
= c1 + x + x + x +Khc1 + x + x + x +Kh
c1 + x + x + x +Khc1 + x + x
+ x +K g
10

10 10 10

Generating Func. 1 - J. T. Butler 2

Example:

50

10 10

This list shows all ways to make


change for all values.

Generating Func. 1 - J. T. Butler 1

10

10 10

= 1 + x + x 2 + x 3 + x 4 + 2 x5 + 2 x 6 + 2 x 7 + 2 x8 + 2 x 9
+ 4 x 10 + 4 x 11 + 4 x 12 + 4 x 13 + 4 x 14 + 6 x 15 +K

10 10 10

50

10

50

15

100

150

Generating Func. 1 - J. T. Butler 5

Generating Func. 1 - J. T. Butler 6

Ordinary Generating Functions #1 - J. T. Butler


Observation: In this expression, aixi represents
the following: there are ai ways to make
change for i. For example, we have 4x11,
which means there are 4 ways to make
change for 11 yen.
1

Observation:

1 + x 1 + x 2 + x 3 +K

= (1 x ) 1

1 + x 5 + x 10 + x 15 +K

= (1 x 5 ) 1

1 + x 10 + x 20 + x 30 +K

= (1 x 10 ) 1

1 + x 50 + x 100 + x 150 +K = (1 x 50 ) 1
whenever the power series (on the left)
converges.

10 1

P( x ) = (1 x )1 (1 x 5 ) 1 (1 x 10 )1 (1 x 50 )1
Generating Func. 1 - J. T. Butler 7

Generating Func. 1 - J. T. Butler 8

Evaluate the generating function in steps

Here, P(x) is the ordinary generating


function for the number of ways to
make change using 1 yen, 5 yen, 10
yen, and 50 yen coins. That is, P(x)
generates these numbers.

3)

5 1

= b0 + b1x + b2 x 2 +K bi = ai + bi5

5 1

10 1

= c0 + c1x + c2 x 2 +K ci = bi + ci10

5 1

10 1

50 1

(1 x ) (1 x ) (1 x )
1

4) (1 x ) (1 x ) (1 x ) (1 x ) = d0 + d1x + d2 x 2 +K di = ci + di50

Generating Func. 1 - J. T. Butler 10

Table to compute a50x50

Example:
(a0 + a1 x + a2 x 2 +K )(1 x 5 ) 1 = b0 + b1 x + b2 x 2 +K

ca + a x + a x +Kh = cb + b x + b x +Khc1 x h
2

b1 xg (1 x )
1

2)

Generating Func. 1 - J. T. Butler 9

(1 x )1 = a0 + a1x + a2 x 2 +K

1)

ai = bi bi 5
bi = ai + bi 5

Generating Func. 1 - J. T. Butler 11

i= 0

5 10 15 20 25 30 35 40 45 50

1) 1

1 1

1 1

2) 1

2 3

6 7

9 10 11

3) 1

2 4

9 12 16 20 25 30 36

4) 1

2 4

9 12 16 20 25 30 37

Generating Func. 1 - J. T. Butler 12

Ordinary Generating Functions #1 - J. T. Butler


Question:

Answer:

Instead of 1 + x10 +x20 + ... for


the polynomial associated with 10 yen
coin

How many ways are there to make


change for 50 yen using i 10 yen coin,
where i is 0, 1, 2, 3, 4, or 5?

c1 + yx

10

+ y 2 x 20 + y 3 x 30 +K = (1 yx 10 ) 1

use y tracks the number of 10 yen coin.

Generating Func. 1 - J. T. Butler 13

Generating Func. 1 - J. T. Butler 14

Table to compute d50 x50

So now
1

5 1

10 1

50 1

P ( x , y ) = (1 x ) (1 x ) (1 yx ) (1 x )

The coefficient of x50 is


(d0 +d1 y +d2 y2 +d3 y3 +d4 y4 +d5 y5) x50
0 10 yen 1 10 yen 2 10 yen 3 10 yen 4 10 yen 5 10 yen

From the table, we can obtain


((11+1) +9y +7y2 +5y3 +3y4 +y5) x50
(12 +9y +7y2 +5y3 +3y4 +y5) x50

i= 0

5 10 15 20 25 30 35 40 45 50

1) 1

1 1

2) 1

2 3

3) 1
4) 1

Generating Func. 1 - J. T. Butler 15

y5
y0

2 4

9 12 16 20 25 30 36

2 4

9 12 16 20 25 30 37

y4

1 1
y3

6 7

y2

9 110 11
y

Generating Func. 1 - J. T. Butler 16

Example:

The right-hand side was derived from the


left-hand
side
using
algebraic
manipulation (multiplication distributes
over addition). However, an interesting
interpretation occurs when one views +
as OR and as AND.

Consider
(1 +ax) (1 +bx) (1 +cx) =
1 +(a+b+c) x +(ab+bc+ca) x2 +abc x3

Generating Func. 1 - J. T. Butler 17

Generating Func. 1 - J. T. Butler 18

y0

Ordinary Generating Functions #1 - J. T. Butler


The right-hand side shows an alternative
description:

(1+ax): One can choose a OR not choose a


(1+bx): One can choose b OR not choose b

1: do not choose a AND do not choose b


AND do not choose c.

(1+cx): One can choose c OR not choose c

(a+b+c) x: Choose a only, b only, OR c


only.
Generating Func. 1 - J. T. Butler 19

Generating Func. 1 - J. T. Butler 20

(ab+bc+ca) x2: Choose (a AND b), (b


AND c), OR (c AND a).

Note that the exponent of x shows how


many of a, b, and c are chosen.

abc x3: Choose a AND b AND c.

Suppose we want to see how many


objects are chosen --- not exactly what
is chosen.

Generating Func. 1 - J. T. Butler 21

Generating Func. 1 - J. T. Butler 22

Let a = b = c = 1. Then,
(1+x)3 = 1 +3x +3x2 +1x3
This shows that there are
1. 1 way to choose none,
2. 3 ways to choose one,
3. 3 ways to choose two, and
4. 1 way to choose three of a, b, and c.

In general
(1+x)n = C (n,0) +C (n,1) x +C (n,2) x2
+ ... + C (n,r) xr + ... + C (n,n) xn
(1)

Generating Func. 1 - J. T. Butler 23

Generating Func. 1 - J. T. Butler 24

Ordinary Generating Functions #1 - J. T. Butler


Let C (n, r ) =

FG nIJ .
H rK

Setting x = 1 in (1).

FG nIJ + FG nIJ + FG nIJ +K+FG nIJ +K+FG nIJ = 2


H 0K H 1K H 2K H r K H nK

Example:

FG 3IJ + FG 3IJ + FG 3IJ + FG 3IJ = 2


H 0K H 1K H 2K H 3K

With n = 3

Both sides give the number of ways of


selecting none, or one, or two, ..., or n
objects out of n distinct objects.

1 + 3 + 3 + 1 =8

Generating Func. 1 - J. T. Butler 25

FG 3IJ :
H 0K

Generating Func. 1 - J. T. Butler 26

0 0 0

Recall
+

FG 3IJ :
H 1K

0 0 1
0 1 0
1 0 0

(1 + x ) n = C ( n ,0) + C ( n ,1) x + C ( n ,2 ) x 2 +K+ C ( n , r ) x r +K+ C ( n , n ) x n

Setting x = -1 yields

FG 3IJ :
H 2K

0 1 1
1 0 1
1 1 0

FG 3IJ :
H 3K

0 = C ( n ,0) C ( n ,1) + C ( n ,2 ) K+ ( 1) r C ( n , n ) +K+ ( 1) n C ( n , n )

This was an identity shown before, in which

+
1

1 1 1
a1 a2 a3

222
Generating Func. 1 - J. T. Butler 27

Example:

we assume 00 = 1 so that 0n = n0.

8
Generating Func. 1 - J. T. Butler 28

Prove

Note:

FG nIJ + FG nIJ + FG nIJ +K


H 0K H 1K H 2K
F nI F nI F 2nI
+ G J +K+ G J = G J
H r K H nK H n K
2

FG nIJ = FG n IJ FG Since FG nIJ = n! IJ


H r K H n rK H H r K r !(n r )!K

Therefore,

Generating Func. 1 - J. T. Butler 29

FG nIJ = FG nIJ FG n IJ
H r K H r K H n rK
2

Generating Func. 1 - J. T. Butler 30

Ordinary Generating Functions #1 - J. T. Butler


and

FG nIJ + FG nIJ + FG nIJ +K+FG nIJ +K+FG nIJ =


H 0K H 1K H 2K H r K H nK
FG nIJ FG nIJ + FG nIJ FG n IJ +K+FG nIJ FG n IJ + FG nIJ FG nIJ
H 0K H nK H 1K H n 1K H r K H n rK H nK H 0K

How many ways are there to choose n


objects from 2n?

The right hand side is

Alternatively, divide the set of 2n objects


into two equal subsets. Then, choose the
objects from the two sets so that the total
chosen is 2n.

FG 2nIJ
H nK

FG 2nIJ .
H nK

Why?
Generating Func. 1 - J. T. Butler 31

Set
A 0

B
A
B

1
n 1

L
K

r
nr

Generating Func. 1 - J. T. Butler 32

L
K

n
0

FG nIJ + FG nIJ + K + FG nIJ + K + FG nIJ


H 0K H 1K
H rK
H nK
FG nIJ + FG n IJ + K + FG n IJ + K + FG nIJ
H nK H n 1K H n rK H 0K

UV
W

Example:

No. of
Choices

Prove

FG nIJ + 2FG nIJ + 3FG nIJ +K+r FG nIJ +K+nFG nIJ = n2


H 1K H 2K H 3K H r K H nK

Generating Func. 1 - J. T. Butler 33

Generating Func. 1 - J. T. Butler 34

Differentiate both sides of

FG nIJ + FG nIJ x + FG nIJ x +K+FG nIJ x +K+FG nIJ x


H 0K H 1K H 2K
H rK
H nK
2

FG nIJ + 2FG nIJ x +K+r FG nIJ x


H 1K H 2K
H rK

We obtain

r 1

+K+ n

FG nIJ x
H nK

n 1

= (1 + x ) n

= n(1 + x ) n 1

Now, set x = 1

FG nIJ + 2FG nIJ +K+nFG nIJ = n2


H 1K H 2K H nK

n 1

Generating Func. 1 - J. T. Butler 35

Generating Func. 1 - J. T. Butler 36

n 1

Ordinary Generating Functions #2 - J. T. Butler


Example

r r r

How many ways are there to


select from three red balls, two
green balls, and one blue ball?

Generating Func. 2 - J. T. Butler

(1 +rx

Choose
none

g g

+r2x2 +r3x3)

(1+gx

Choose
one ball

Generating Func. 2 - J. T. Butler

Choose
two balls

(1 +bx)

Choose
three balls

= (1 + x + x 2 + x 3 ) (1 + x + x 2 ) (1 + x )

(1 + rx + r2x2 + r3x3) (1 + gx +g2x2) (1+bx) =

However,

1 + (r + g + b)x + (rg + rb + gb + r2 +g2)x2


+ (r2g + r2b + g2b + rg2 + rgb + r3)x3

1 + x + x 2 +K+ x r +K =

+ (r3g + r3b + r2gb +r2g2 +rg2b)x4

1 + x + x2 + x3 =

+ (r3gb + r3g2 + r2g2b)x5 + (r3g2b)x6 .

1+ x + x2 =

Setting r = g = b = 1, yields
= 1 + 3x + 5x2 + 6x3 + 5x4 + 3x5 + x6 .
Generating Func. 2 - J. T. Butler

+g2x2)

1+ x =

1
1 x

1 x4
1 x

1 x3
1 x

1 x2
1 x

Generating Func. 2 - J. T. Butler

Generating function for choosing r objects out


of n objects with repetition

Thus,

FG 1 IJ
H 1 xK
= b1 x g

1 x4 1 x3 1 x 2 1 x2 x3 x4 + x5 + x6 + x7 x9
=
1 x 1 x 1 x
1 3x + 3x 2 x 3

(1 + x + x 2 +K+ x k +K ) n =

Generating Func. 2 - J. T. Butler

Generating Func. 2 - J. T. Butler

Ordinary Generating Functions #2 - J. T. Butler


But

FG nIJ = (n)! = n(n 1)(n 2)K


H r K r !(n r)! r !(n r)(n r 1)K

From the binomial theorem

(1 + x ) n = 1 +
r =1

So

b1 xg

FG nIJ x
H rK

= 1+
r =1

FG nIJ b xg
HrK

( n)( n 1)K ( n r + 1)
r!
n + r 1
(n + r 1)K (n + 1)( n)
=
( 1) r =
( 1) r
r
r!
=

FG
H

Thus,

(1 x ) n = 1 +
r =1

Generating Func. 2 - J. T. Butler

FG n + r 1IJ x
H r K

Generating Func. 2 - J. T. Butler

=
r =0

FG n + r 1IJ x
H r K

Observation:

FG 1 IJ
H1 xK

= x n (1 x ) n

FG n + r 1IJ x
H r K
F n + r 1IJ x
= G
H r K
F r 1IJ x
= G
H r nK
= xn

r = 0

n + r

r = 0

The answer we seek is the


coefficient of x r or

Generating Func. 2 - J. T. Butler

( x + x 2 + x 3 +K+ x k +K ) n = x n

(1-x)-n is the
generating function for the number
of ways to choose r objects out of n
objects with repetition. If each
object is chosen at least once, then
we have,

IJ
K

FG r - 1IJ .
H r - nK

Generating Func. 2 - J. T. Butler

r =n

r = n + r
10

Question:

Answer:

How many ways are there to


distribute 2t+1 balls among three
distinct cells so that no cell
contains more than t balls?

The generating function for the


number of ways to distribute is

Generating Func. 2 - J. T. Butler

Generating Func. 2 - J. T. Butler

S ( x ) = 1 + x + x 2 +K+ x t

11

12

Ordinary Generating Functions #2 - J. T. Butler


We seek the coefficient of x2t+1
S ( x ) = (1 + x + x 2 +K ) x t +1 (1 + x + x 2 +K )

FG 1 x IJ = FG 1 x IJ
H 1 x 1 xK H 1 x K
= c1 3x + 3x
x hb1 x g
t +1

t +1

The coefficient of x2t+1 in S(x) is the


coefficient of x2t+1 in (1-x)-3 less 3 times the
coefficient of xt in (1-x)-3.

FG 3 + 2t + 1 1IJ 3FG 3 + t 1IJ = FG 2t + 3IJ 3FG t + 2IJ


H 2t + 1 K H t K H 2t + 1K H t K

t +1

2t +2

Generating Func. 2 - J. T. Butler

3t + 3

13

Generating Func. 2 - J. T. Butler

However, some of these correspond to t+1 or more balls per


cell. If there are t+1 or more balls
per cell, only one cell has this
many balls. Given exactly t+1
balls in one cell, there are t other
balls to distribute in the three
cells.

Alternative answer:
Without restriction, there are

FG 3 + 2t + 1 1IJ
H 2t + 1 K

ways to distribute 2t+1 balls into three


cells (choose 2t+1 objects from 3 with
repetition). That is, any number of balls
can go into any cell.

Generating Func. 2 - J. T. Butler

This is done in
answer is

15

FG 3 + t 1IJ
H t K

Generating Func. 2 - J. T. Butler

16

Prove:

ways. Thus the

FG 3 + 2t + 1 1IJ 3FG 3 + t 1IJ = FG 2t + 3IJ 3FG t + 2IJ


H 2t + 1 K H t K H 2t + 1K H t K

Generating Func. 2 - J. T. Butler

14

1 + 2 + 3+K+ m =

17

Generating Func. 2 - J. T. Butler

18

m( m + 1)
2

Ordinary Generating Functions #2 - J. T. Butler

b1 x g

Answer:1 Consider

Note that if
2

= 1 + x + x + x +K

A (x) = a0 +a1 x +a2 x2 +

b g

Differentiate
both sides
2
1 x = 1 + 2 x + 3x 2 +K

Then,
(1 x ) 1 A( x ) = a 0 + ( a 0 + a1 ) x
+ ( a 0 + a1 + a 2 ) x 2 +K

Multiply by x
2
x 1 x = x + 2 x 2 + 3x 3 +K

b g

Generating Func. 2 - J. T. Butler

19

Generating Func. 2 - J. T. Butler

Therefore,

b1 x g

But, this is just the coefficient of


xm-1 in (1-x)-3, which is the
number of ways to choose m-1
objects from 3 with repetition or

x (1 x )2 = 0 + (1) x + (1 + 2 ) x 2
+ (1 + 2 + 3) x 3 + (1 + 2 + 3 + 4 ) x 4K

FG 3 + ( m 1) 1IJ = FG m + 1IJ = FG m + 1IJ


H m 1 K H m 1K H 2 K

and 1+2+3+...+m is the coeffix


cient of xm in
.
(1 x )3
Generating Func. 2 - J. T. Butler

20

21

Generating Func. 2 - J. T. Butler

m( m + 1)
.
2
22

Alternative
Answer
We seek
this sum.

m+1

1+2+3+4+ ... + m
Generating Func. 2 - J. T. Butler

23

Generating Func. 2 - J. T. Butler

24

Ordinary Generating Functions #2 - J. T. Butler


But,

Prove:

2 S = m(m + 1)
m(m + 1)
S=
2

12 + 2 2 +K+ m2 =

FG
H

IJ
K

1 (m + 1) m
( 2m + 1)
3
2

This is called a look-see proof.


Generating Func. 2 - J. T. Butler

Answer:

25

Generating Func. 2 - J. T. Butler

26

Differentiate both sides

Consider

(1x)-2 +2x (1x)-3 = 12+22x+32x2+42x3+

(1x)-1 = 1 +x +x2 +x3 +

= (1x)(1x)-3 +2x (1x)-3 = (1+x)(1x)-3

Differentiate both sides

Multiply both sides by x

(1x)-2 = 1 +2x +3x2 +

x (1+x)(1x)-3 = 12x +22x2 +32x3 +42x4 +

Multiply both sides by x


x (1x)-2 = x +2x2 +3x3 +
Generating Func. 2 - J. T. Butler

27

Generating Func. 2 - J. T. Butler

28

Alternative Proof:

Multiply both sides by (1x)-1

Note:

x (1 + x ) 2
= 1 x + (12 + 22 ) x 2 + (12 + 22 + 32 ) x 3 +K .
(1 x )4

Therefore, (12+22+...+ m2) is the coefficient


of xm in x (1 + x4) , which is

12 22 32 42

22 = 1+3

(1 x )

FG 4 + ( m 1) 1IJ + FG 4 + ( m 2) 1IJ = FG m + 2IJ + FG m + 1IJ


H m 1 K H m 2 K H m 1K H m 2K
( m + 2 )( m + 1)m ( m + 1)m( m 1) 1 F ( m + 1)m I
=
+
= G
JK (2m + 1)
3 2 1
3 2 1
3H
2

Generating Func. 2 - J. T. Butler

12 = 1

32 = 1+3+5
42 = 1+3+5+7

29

Generating Func. 2 - J. T. Butler

30

Ordinary Generating Functions #2 - J. T. Butler


4( 4 + 1)
2

1+ 2 + 3 + 4 =

12

22

32

42

There are 4 columns of 1, 3 columns of 4, 2


columns of 5, and 1 column of 7.

Generating Func. 2 - J. T. Butler

24+1

31

Generating Func. 2 - J. T. Butler

32

Using generating functions

Example:

1. From the problem,


generating function

(4 + 1)4
3(1 + 2 + 3 + 4 ) =
(2 4 + 1)
2
2

derive

the

2. Simplify the generating function.


3. Derive expression for coefficient of xn.

This is a look-see proof.

Let A( x) = a0 + a1 x + a2 x 2 + a3 x 3 + K
B ( x ) = b0 + b1 x + b2 x 2 + b3 x 3 + K

Generating Func. 2 - J. T. Butler

C ( x ) = c0 + c1 x + c2 x 2 + c3 x 3 + K

33

Generating Func. 2 - J. T. Butler

34

C. Multiplication

A. Addition

C ( x ) = A( x )B ( x ) ci = a0 bi + a1bi 1

C( x ) = A( x) + B( x) ci = ai + bi

+ a 2 bi 2 + K + ai b0
If

B. Shifting

B ( x) =

C( x ) = x n A( x ) ci = ai n

1
= 1 + x + x 2 + x3 + K,
1 x
i

C ( x ) = A ( x ) B ( x ) ci = a j .
j =0

Generating Func. 2 - J. T. Butler

35

Generating Func. 2 - J. T. Butler

36

Ordinary Generating Functions #2 - J. T. Butler


E. Remove odd or even terms

D. Change in x

A( x) + A( x)
= a0 + a2 x 2 + a4 x 4 + K
2
+ a2i x 2i + K
A( x) A( x)
C ( x) =
= a1 + a3 x3 + a5 x5 + K
2
+ a2i +1x 2i +1 + K
C ( x) =

C( x) = A(x) ci = i ai

Generating Func. 2 - J. T. Butler

37

Generating Func. 2 - J. T. Butler

38

Known generating functions

F. Differentiation and integration


d
A( x ) (i + 1)ai +1
dx
x
1
C ( x ) = A( x ) dx ai
0
i
C( x) =

1
(1 + x ) n

Generating Func. 2 - J. T. Butler

FG nIJ + FG nIJ x + FG nIJ x +...+FG nIJ x


b1g
H 0K H 1K H 2K
H nK
F nI F nI F nI
= G J + G J x + G J x +...
b2 g
H 0K H 1K H 2K
F n + 1 1IJ x + (1) FG n + 2 1IJ x +...
= 1 + ( 1)G
H 1 K
H 2 K

(1 + x ) n =

39

Generating Func. 2 - J. T. Butler

( 3)

b4 g

40

Solving yields A = 1, B= -1, and C= -1. Thus,


1
1
1
1
=
+
+
.
( x 3)( x 2) 2 x 3 x 2 ( x 2) 2

FG 1IJ 1 + FG 1 IJ 1 + FG 1 IJ 1
H 3K 1 FG x IJ H 2 K 1 FG x IJ H 4 K (1 FG x IJ )
H 3K
H 2K
H 2K

1 = A( x 2) 2 + B ( x 2)( x 3) + C ( x 3).

Equating coefficients yields


A+B=0
-4 A + 5B + C = 0
4 A + 6 B - 3C = 1

1 x n +1
= 1 + x + x 2 +...+ x n
1 x
1
= 1 + x + x 2 + + x 3 +...
(1 x )

A useful approach is to use the method of partial fraction


expansion. Consider the following. Find the coefficient of xn in
1
.
( x 3)( x 2) 2
Thus,
1
A
B
C
=
+
+
( x 3)( x 2) 2 x 3 x 2 ( x 2) 2

Generating Func. 2 - J. T. Butler

41

Generating Func. 2 - J. T. Butler

42

Ordinary Generating Functions #2 - J. T. Butler


Each of the parts has a simple form, from
which we can extract a coefficient as follows.
n

1 1 1 1 1 2 1
+ + =
3 3 2 2 4 n 2
n

1 1 1 1 1 n + 1 1 1 1 1
1
+ +
= (n 1) 2 .
3 3 2 2 4 n 2 3 3 4

Generating Func. 2 - J. T. Butler

43

Generating Func. 2 - J. T. Butler

44

Generating Function Example - Ordered Binary


Trees - J. T. Butler
Count the ordered binary trees

Example
An important topic in
computer science is graphs
and trees. These are useful,
for example, in data structures

r=1

r=2

r=3

r=4
G. Func. Examples - J. T. Butler

G. Func. Examples - J. T. Butler

Note:

binary --- at most two edges occur at each


node

tree --- a connected graph with no circuits

ordered order is counted

G. Func. Examples - J. T. Butler

G. Func. Examples - J. T. Butler

r is the number of leaves

These count as
2 not 1.

Let T (x) be the ordinary generating


function for tr, the number of
ordered binary trees with r leaves
T (x) = t0 + t1 x + t2 x2 + t3 x3 +

leaves

G. Func. Examples - J. T. Butler

G. Func. Examples - J. T. Butler

Generating Function Example - Ordered Binary


Trees - J. T. Butler
We assume t0 = 0. That is, there are
no trees with 0 nodes. We form an
ordered binary tree as follows:
L

To form a tree, choose one tree for L and


one for R . Each choice is expressed as
T(x), giving T2(x). +x occurs because the
single tree with one leaf is not counted in
T2(x).

Subtrees with one


or more nodes

T (x) = T2(x) + x
G. Func. Examples - J. T. Butler

Rewrite (1) and solve for T(x).

(1)

G. Func. Examples - J. T. Butler

Apply the binomial theorem

0 = T 2 ( x) T ( x) + x

(1 + x ) n = 1 +

1 1 4x 1 1
= (1 4 x )1/ 2
T ( x) =
2
2 2

r =1

FG nIJ x
H rK

to get

(1 4 x ) 1/ 2 = 1 +
r =1

G. Func. Examples - J. T. Butler

G. Func. Examples - J. T. Butler

FG1 / 2IJ (4 x)
HrK

10

(1 / 2)( 1 / 2)( 3 / 2)( 5 / 2)K


( 4) r x r
r
!(
1
/
2

r
)(

1
/
2

r
)
K
r =1

= 1+

= 1
r =1

(1 / 2)( 1 / 2)( 3 / 2)K (1 / 2 r + 1)


( 4 ) r x r
r
!
r =1

= 1+

= 1
r =1

1 1 1 3 K ( 2r 3) r r
4 x
r
r!
r =1 2

(1 4 x )1/ 2 = 1

= 1

r =1

2 4 K ( 2 r 2 ) 1 3 5 K ( 2r 3) r r
4 x
2 r 1 1 2 K ( r 1)
2r r !
1 2 3 4 5 K ( 2r 3)(2 r 2 ) r
2x
( r 1)!( r 1)! r

FG
H

IJ
K

2 2r 2 r
x
r r 1

Note: The numerator is 1 when r = 1, not -1.


G. Func. Examples - J. T. Butler

11

G. Func. Examples - J. T. Butler

12

Generating Function Example - Ordered Binary


Trees - J. T. Butler
Thus, the number of ordered binary trees with r
leaf nodes is

Of the two solutions for T(x), choose the


negative one, so that
T ( x) =

1 1
(1 4 x )1/ 2
2 2

tr =

FG
H

IJ
K

1 2r 2
r r 1

=0

G. Func. Examples - J. T. Butler

13

G. Func. Examples - J. T. Butler

1 2

tr

1 1

G. Func. Examples - J. T. Butler

14 42 132

14

How many ways are there to


place parentheses around r
letters so that inside each pair
there are two terms?

15

G. Func. Examples - J. T. Butler

16

Catalan numbers also count ways


to divide polygons into triangles
and ways a rook can go from the
lower left corner of a half
chessboard to the upper right
corner.

Example:
Ways to place parantheses
Number of ways
( ab)
1
((ab)c) ( a (bc))
2
((ab)(cd )), (((ab) c)d ),(a (b(cd ))),(a ((bc)d )), ((a (bc))d ) 5

G. Func. Examples - J. T. Butler

r=0

There are called Catalan numbers


after Eugene Charles Catalan, a
mathematician from Belgium.
In
1838, he solved the following problem:

We have
r

r 1

17

G. Func. Examples - J. T. Butler

18

Generating Function Example - Ordered Binary


Trees - J. T. Butler
14

Number of ways to divide a polygon with r


sides into triangles
1

G. Func. Examples - J. T. Butler

19

G. Func. Examples - J. T. Butler

6444444447444444448

Number of ways to go from the lower


left corner of a half chessboard to the
upper right corner
1

64748

64444744448

G. Func. Examples - J. T. Butler

21

G. Func. Examples - J. T. Butler

23

20

G. Func. Examples - J. T. Butler

22

Exponential Generating Functions - J. T. Butler


Exponential
Generating Functions

Definition:
a0 +a1 x +a2 x2 + a3x3+

Generating functions
for permutations.

is the ordinary generating function


for the sequence of integers (a0, a1,
a2, a3, ).

Exp. Gen. Func.- J. T. Butler 1

Exp. Gen. Func.- J. T. Butler 2

Definition:

Observation:

a 0 a1
a
a
+ x + 2 x 2 + 3 x 3 +K
0! 1!
2!
3!

Ordinary generating functions


are often used for combinations.

is the exponential generating


function for the sequence of integers
(a0, a1, a2, a3,).
Exp. Gen. Func.- J. T. Butler 3

Exp. Gen. Func.- J. T. Butler 4

Example:

Observation:

1+

Exponential generating functions are often used for


permutations.

1
1
1
x + x 2 + x 3 +K = e x
1!
2!
3!

is the exponential generating function for


permutations of none, one, two, three,
identical objects. Since all objects are the
same, there is only one permutation.

Exp. Gen. Func.- J. T. Butler 5

Exp. Gen. Func.- J. T. Butler 6

Exponential Generating Functions - J. T. Butler


Consider the contribution to xi of G (x)
from single term from A(x) and a single
term from B(x).
1 p 1 q ( p + q )!
1
x
x =
x p+q
p! q !
p ! q ! ( p + q )!
12
4 4
3

Consider the product of two generating


functions as follows.
G ( x ) = A( x ) B ( x ),
where A( x ) = B ( x ) = (1 +

1
1
x + x 2 +...).
1!
2!

Number of ways to permute p + q objects


with p of the first kind and q of the second
kind.

Exp. Gen. Func.- J. T. Butler 7

G( x) = 1 +

Exp. Gen. Func.- J. T. Butler 8

FG 1 + 1 IJ x + FG 2 + 1 1 IJ x + FG 2 + 2 IJ x +K
H 1! 1!K H 2! 1!1!K H 3! 1!2!K
2

Example:

x
x2
x3
1 + (1 + 1) + ( 2 + 2)
+ (2 + 6) +K
1!
2!
3!

How many n-digit numbers are generated from


{0, 1, 2, 3, 4}?

aa ab aaa aab
bb ba bbb aba
baa

00 01 02 03 04 10 11 12 13 14 20 21 22
23 24 30 31 32 33 34 40 41 42 43 44

bba
bab
abb
Exp. Gen. Func.- J. T. Butler 9

IJ FG
KH

IJ FG
KH

Example:

IJ
K

1
1
1
1
1
1
1 + x + x 2 +K 1 + x + x 2 +K 1 + x + x 2 +K
1!
2!
1!
2!
1!
2!

How many n-digit numbers are generated from


{0, 1, 2, 3, 4} in which the total number of 0s
and 1s is even?

FG1 + 1 x + 1 x +KIJ FG1 + 1 x + 1 x +KIJ


H 1! 2! K H 1! 2! K
2

= ex ex ex ex ex = e5x

n=2

Exp. Gen. Func.- J. T. Butler 10

The exponential generating function is

FG
H

UV
W

00 01 02 03 04 10 11 12 13 14 20 21 22
23 24 30 31 32 33 34 40 41 42 43 44

5n n
x .
The xn term is
5!

Thus, there are 5n numbers.


Exp. Gen. Func.- J. T. Butler 11

Exp. Gen. Func.- J. T. Butler 12

UV
W

n=2

Exponential Generating Functions - J. T. Butler


There are two ways to have an even
number of 0s and 1s

1. even 0s and even 1s

FG1 + 1 x
H 2!

1. even 0s and even 1s


2. odd 0s and odd 1s

Exp. Gen. Func.- J. T. Butler 13

FG1 + 1 x + 1 x +KIJ FG1 + 1 x + 1 x +KIJ FG1 + 1 x + 1 x +KIJ


H 1! 3! K H 1! 3! K H 1! 2! K
=

IJ FG
KH

IJ
K

Exp. Gen. Func.- J. T. Butler 14

2. odd 0s and odd 1s


3

IJ FG
KH

1 4
1
1
1
1
x +K 1 + x 2 + x 4 +K 1 + x + x 2 +K
4!
2!
4!
1!
2!
1
1
1
1
1
= (e x + e x ) (e x + e x )e 3 x = e5 x + e 3 x + e x
2
2
4
2
4
(1)
2

1 x
1
1
1
1
(e e x ) ( e x e x )e 3 x = e5 x e 3 x + e x
2
2
4
2
4

Adding (1) and (2) yields

1 5x
e + ex
2
1
1
1
1
1
1
= 1 + 5x + 52 x 2 +K + 1 + x + x 2 +K
2
1!
2!
2
1!
2!

FG
H

(2)

The coefficient of

IJ FG
K H

IJ
K

xn
is
n!

1 n
(5 + 1)
2
Exp. Gen. Func.- J. T. Butler 15

Exp. Gen. Func.- J. T. Butler 16

FG nIJ (1) e
HiK
F nI
1
= G J ( 1) (n i ) x
r!
HiK
F nI
x
= ( 1) G J (n i )
r!
HiK

Distributing distinct
objects into nondistinct cells

( n i ) x

i =0
n

The exponential generating function for the


number of ways to distribute distinct objects
into n distinct cells where no cell is empty is

FG x + x + x +KIJ
H 2! 3! K

i =0

= ( e x 1) n

r =0

Exp. Gen. Func.- J. T. Butler 17

r =0

i =0

Exp. Gen. Func.- J. T. Butler 18

Exponential Generating Functions - J. T. Butler


Thus, the number of ways to place r distinct
objects into n distinct cells with no cell left
empty is

F nI
( 1) GH i JK (n i )

Thus, the number of ways to place r


distinct objects into n nondistinct cells is
S ( r , n) =

= n ! S ( r , n)

FG IJ
HK

n
1 n
( 1) i
(n i ) r

i
n! i =0

i =0

Exp. Gen. Func.- J. T. Butler 19

Exp. Gen. Func.- J. T. Butler 20

The second equation can be seen as


follows. Select one object , and place
it by itself. Then, distribute the r1
remaining objects in the n1 remaining
cells.
This
is
counted
by
S (r1, n1).

Note:
S(n,1) = S(r,r) = 1
S(r,n) = S(r -1, n -1) + nS(r - 1, n)
for 1 < r < n

Exp. Gen. Func.- J. T. Butler 21

Exp. Gen. Func.- J. T. Butler 22

Stirling number triangle

Otherwise, distribute all r1 objects


except in n cells, and then place in
one of the n cells. This is counted by
nS(r1, n). In effect, there are now n
distinct cells because they contain
distinct objects, which can be chosen in
n ways.

B(n)
r

Bell numbers

1
1
2
3
4
5
6

Exp. Gen. Func.- J. T. Butler 23

2
3
4
5
6
7

1
1

1
1

3
6

1
1
10
25
15
1
15
65
90 31
1

Exp. Gen. Func.- J. T. Butler 24

1
7

1
2
5
15
52
203

Exponential Generating Functions - J. T. Butler


B(n) represents the Bell numbers, named
after Eric Temple Bell, who was the first
to analyze them in detail. He died in
1960. In the 1920s and 1930s, he
wrote science fiction under the name
John Taine.

B(n) is the number of ways to place n


distinct objects into n nondistinct cells,
where cells can contain any number of
objects including 0.

Exp. Gen. Func.- J. T. Butler 25

Exp. Gen. Func.- J. T. Butler 26

Bell numbers can be described by

The first ten Bell numbers

B(n , r ) = B (n 1, r 1) + B (n, r 1),


n

0 1 2 3

B(n)

1 1 2 5 15 52 203 877 4190 21,147

Exp. Gen. Func.- J. T. Butler 27

Interesting properties

Sum

1. The sum of the horizontal row


is in the second diagonal.

r
0
1
2
3

1
1

2
5

n1

Exp. Gen. Func.- J. T. Butler 28

Bell triangle
0
1
2
3
4
5

n r 1

B (n) = B (n,0) = B (n 1, n 1)
B( 0,0) = 1

3
7

5
10

15
4
15
20
27
37 52
5
52 66
87 114 151 203

1
3
10
37
151
674

2. If the sum of the row is added to


the number at the end of the row,
the next Bell number is obtained.
`

3. Every third Bell number is even.

B(n)
Exp. Gen. Func.- J. T. Butler 29

Exp. Gen. Func.- J. T. Butler 30

Exponential Generating Functions - J. T. Butler


Bell numbers

2. Note that a way to rhyme 5 lines


corresponds to distributing 5 distinct
objects (lines of a poem) into nondistinct cells (each line in a cell rhymes
with all other lines in that cell).

1. Count the number of ways a number


with distinct prime factors can be
factored. For example, 30 has 3 distinct
prime factors, 2, 3, and 5. The number
of ways to factor 30 (2 3 5, 5 6, 3
10, 2 15, and 30) is 5, which is B(3).

Exp. Gen. Func.- J. T. Butler 31

Exp. Gen. Func.- J. T. Butler 32

Counts the number of ways to rhyme


lines of poetry. For example, B (5)
appears in the Tale of the Genji, a
famous Japanese book written by Lady
Murasaki,
who
lived
from
about 978 to 1031.

Every chapter of this 54-chapter


book, except the first and the last begin
with one of the 52 ways to rhyme five
lines of poetry. Horizontal lines join
lines that rhyme. The 52 ways to rhyme
five lines of poetry is shown on the next
two pages.

Exp. Gen. Func.- J. T. Butler 33

Exp. Gen. Func.- J. T. Butler 34

Limerick

Exp. Gen. Func.- J. T. Butler 35

Exp. Gen. Func.- J. T. Butler 36

Exponential Generating Functions - J. T. Butler

Exp. Gen. Func.- J. T. Butler 37

Partitions of Integers - J. T. Butler


Partitions of Integers

Example:

Definition:

There are five partitions of 4;


1+1+1+1, 2+1+1, 2+2, 3+1, and
4.

A partition of integer n is an integer solution


to
n = n1 + n2 + + nk ,
where ni > 0 and n > 0. Specifically, this is a
partition of n into k parts.
Partitions of Integers - J. T. Butler

Partitions of Integers - J. T. Butler

Note:

A compact way to represent a


partition is with exponents. That is,
the partitions of 4 are 14, 212, 22,
31, and 4.

A partition of n is a way to distribute n


nondistinct objects into n nondistinct
cells with empty cells allowed.
The order of the parts is not important.
That is, 3+1 is the same as 1+3.

Partitions of Integers - J. T. Butler

Partitions of Integers - J. T. Butler

Recurrence Relation for Partitions

If ms > 0, but ms+1 = ms+2 = = mk = 0,


then we have a partition of n k into s
parts. Each partition of n k into s parts
corresponds to a k part partition of n and
vice versa.

We can write a partition like so


n = n1 + n2 +K+ n k ,

n1 n2 n3 K n k 1

Now form
n k = ( n1 1) + ( n2 1) +K+ ( nk 1)
= m1 + m2 +K+ mk
m1 m2 K mk 0

Partitions of Integers - J. T. Butler

Partitions of Integers - J. T. Butler

Partitions of Integers - J. T. Butler


Thus, we can form the following table.

Thus,
p k ( n ) = p k ( n k ) + p k 1 ( n k ) +K+ p 0 ( n k ) ,

n
k

where pk (n) is the number of partitions of n into k


parts.

0
1
2
3
4
5
6
Sum

Example:
p2 (4) = p2(2) + p1(2) + p0(2)
2 = 1 + 1 + 0
p4 (4) = p4(0) + p3(0) + p2(0) + p1(0) + p0(0)
1

0 +

Partitions of Integers - J. T. Butler

In

(n)

k =1

Partitions of Integers - J. T. Butler

1 + x 2 + x 4 + x 6 +K+ x 2 r +K =

4
0
1
2
1
1
0
0
5

5
0
1
2
2
1
1
0
7

6
0
1
3
3
2
1
1
11 p (n)

1 + x + x 2 + x 3 +K+ x r +K =

1
1 x

the coefficient of xr is the number of ways


to have r 1s in a partition integer n.
Partitions of Integers - J. T. Butler

10

If P (x) is the generating function for the


number of partitions on n, then

Similarly, the polynomial

1
1 x2

P ( x ) = (1 + x + x 2 +K+ x r +K )(1 + x 2 + x 4 +K+ x 2 r +K )


(1 + x 3 + x 6 +K+ x 3r +K )(1 + x 4 + x 8 +K+ x 4 r +K )K
1
1
1
1
=
K
1 x 1 x2 1 x3 1 x4
= 1 + x + 2 x 2 + 3x 3 + 5x 4 + 7 x 5 + 11x 6 +K

enumerates ways 2s can appear in a


partition of n.

Partitions of Integers - J. T. Butler

pk(n)
2 3
0 0
1 1
1 1
0 1
0 0
0 0
0 0
2 3

Generating Functions for


Partitions

1
0
1
0
0
0
0
0
1

Partitions of Integers - J. T. Butler

The last line of the previous slide


shows the number of partitions on n;
that is,

p(n) =

0
1
0
0
0
0
0
0
1

11

Partitions of Integers - J. T. Butler

12

Partitions of Integers - J. T. Butler


Note:

Partitions with every part odd

It is convenient to represent special


partitions using generating functions.
Partitions with no repeated
(summands are distinct)

S ( x) =

parts

1
1
1
K
3
1 x 1 x 1 x5

R ( x ) = (1 + x )(1 + x 2 )(1 + x 3 )K
Partitions of Integers - J. T. Butler

13

Partitions of Integers - J. T. Butler

Note:

Example:

1 x 2 1 x 4 1 x 6 1 x 8 1 x 10
K
1 x 1 x 2 1 x 3 1 x 4 1 x5
1
1
1
=
K
3
1 x 1 x 1 x5

R( x ) =

Among the partitions on 4, there are


two with all parts odd (31 and 14),
and there are two with no repeated
parts (31 and 4).

Thus,
Theorem: The number of partitions with
every part odd is the same as the number
of partitions with no repeated parts.
Partitions of Integers - J. T. Butler

15

Partitions of Integers - J. T. Butler

Let

1
1
1
1
K
= p k ( n ) x n
1 x 1 x 2 1 x 3 1 x k n =0

x track the value of n


y track the number of parts

where, p k ( n) = pi ( n).

P( x, y ) = (1 + xy + x 2 y 2 + K)(1 + x 2 y + x 4 y 2 + K) K
1
1
1
=
K
(1)
2
1 xy 1 x y 1 x 3 y

i=0

Partitions of Integers - J. T. Butler

16

Use generating functions to track the


number of parts

Partitions with no part greater than k.


Q( x) =

14

17

Partitions of Integers - J. T. Butler

18

Partitions of Integers - J. T. Butler


A typical term in this expression is

Example

pk(n) xn yk,

From the table for pk(n), the coefficient of

where pk(n) is the number of partitions of n


into k parts.

y2 is
[ 1 x2 + 1 x3 + 2 x4 + 2 x5 + 3 x6 + ... ] y2
12
12 13
14 15
22
23 24
32

A typical coefficient of yk in this


expression is
p ( k ) x k + p ( k + 1) x k +1 +K y k
1k44444k2444443

Pk ( x )

Partitions of Integers - J. T. Butler

19

Partitions of Integers - J. T. Butler

Pk ( x ) y k xy pk 1 ( k 1) x k 1 + pk 1 ( k ) x k +K y k 1 =

Note:

pk ( k ) x k + pk ( k + 1) x k +1 +K x k y k

From (1), we can write


(1 xy) P (x,y) = P (x,xy)

Pk ( x ) y k x Pk 1 ( x ) y k = x k Pk ( x ) y k

(2)

(1 x k ) Pk ( x ) = x Pk 1 ( x )
x
Pk 1 ( x )
1 xk
x
Pk 1 ( x ) =
Pk 2 ( x )
1 x k 1

Equating the coefficient of yk on both


sides of (2) yields

Partitions of Integers - J. T. Butler

and
Pk ( x ) =

Pk ( x ) =

21

Partitions of Integers - J. T. Butler

and

x2
Pk 2 ( x )
(1 x k )(1 x k 1 )

Pk ( x ) =

Similarly,

Pk ( x ) =

20

22

xk
P0 ( x)
(1 x k )(1 x k 1 ) K (1 x ) 123
1

Note:

x3
Pk 3 ( x )
(1 x k )(1 x k 1 )(1 x k 2 )

Pk ( x ) = x k Q ( x ),
where Q ( x ) is the generating function for
partitions with no part greater than k .

Partitions of Integers - J. T. Butler

23

Partitions of Integers - J. T. Butler

24

Partitions of Integers - J. T. Butler


Theorem:

Example:

The number of partitions of n with no


part greater than k equals the number
of partitions of n+k with exactly k
parts.

There are four partitions of 6 with no part


greater than 2 (16, 214, 2212, and 23).
There are four partitions of 8 with exactly
two parts (42, 53, 62, and 71).

Partitions of Integers - J. T. Butler

25

Partitions of Integers - J. T. Butler

26

that a represent the parts. This shows

Theorem: The number of partitions


of n with the largest part k equals the
number of partitions of n with
exactly k parts.

6+4+3+1

Proof: Consider the Ferrers graph

27

Partitions of Integers - J. T. Butler

29

4+3+3+2+1+1

that a partition of 14 into 4 parts


corresponds to a partition of 14
where the largest part is 4. The
theorem statement follows.

of a partition, as shown below. Here,


dots represent the parts. This shows
Partitions of Integers - J. T. Butler

Partitions of Integers - J. T. Butler

28

Recurrence Relations - J. T. Butler


Recurrence
Recurrence Relations
Relations
Example: Fibonacci Sequence
n
an

0
1

1
1

2
2

3
3

4
5

5 6 7
8 13 21
11701250
Born: Pisa, Italy

Recurrence Rel. - J. T. Butler

Recurrence Rel. - J. T. Butler

We have

The French mathematician, Edouard


Lucas, used Fibonacci numbers to prove
2127 1 is prime. This 39-digit number
was the largest known until 1952 when a
computer was used to find five higher
primes, the largest being 22281-1. The
Lucas sequence is
1 2 3 5 8 13, ...
Recurrence Rel. - J. T. Butler

This originated in 1202 by


Leonardo Fibonacci.
He
was educated in North
Africa, where his father held
a diplomatic post.
He
published Liber abaci in
1202, which introduced the
Hindu-Arabic placed-valued
decimal system and Arabic
numerals in Europe.

an = an-1 +an-2 .
This is a recurrence relation. It can be solved in
a way similar to differential equations.
Assume a solution of the form
an = A n .

Recurrence Rel. - J. T. Butler

and we have
We have

a n = A1

0 = A n A n-1 A n-2

F1+ 5I
GH 2 JK

+ A2

F 1 5 I
GH 2 JK

or
Applying the boundary conditions gives

0 = 2 1.
This is called the characteristic equation.
Solving for yields

a0 = 1 = A1
a1 = 1 = A1

1 1+ 4 1 5
=
=
.
2
2
Recurrence Rel. - J. T. Butler

Recurrence Rel. - J. T. Butler

+ A2

F1+ 5I + A F1 5I .
GH 2 JK GH 2 JK
2

Recurrence Relations - J. T. Butler


Solving for A1 and A2 yields
A1 =

F
GH

1 1+ 5
2
5

Thus

I
JK

A2 =

F
GH

F
GH

I
JK

IF 1+ 5I
JK GH 2 JK
1 F 1 5IF 1 5I
G JG J
5 H 2 KH 2 K

1 1+ 5
an =
2
5

Recurrence Rel. - J. T. Butler

or

1 1 5
.
2
5

an = 0.724 (1.62)n +0.276 (0.62)n


Note that the second term approaches 0 as n
approaches .

Recurrence Rel. - J. T. Butler

Properties of Fibonacci Numbers

2. Fibonacci Numbers in Sunflower Heads


In sunflowers, the seeds of the head form

1. Fibonacci Numbers in Anatomy


A study showed that the average ratio of
H/B

55

89
H

Belly button
B

two spirals. The number of seeds in each


spiral is a Fibonacci number.

for children in England was 1.62. For


children in India (where height is smaller),
this ratio was also 1.62.
Recurrence Rel. - J. T. Butler

Recurrence Rel. - J. T. Butler

3. Fibonacci Numbers in Flower Petals

10

4. Fibonacci Numbers in Fruits

8
21
13
Daisy - 13 petals

Aarons - 5 petals

Recurrence Rel. - J. T. Butler

Orange - 8
sections

Pineapple - 8-1321 rows

Hibiscus- 5 petals

11

Recurrence Rel. - J. T. Butler

12

Recurrence Relations - J. T. Butler


5. Fibonacci Numbers in the Solar System
Planet
Mercury
Venus
Earth
Mars
Aster.
Jupiter

Aphelion Dis.
from Sun
x 106 km.
70
109
152
249
816

Saturn
Uranus
Neptune
Pluto

1504
3002
4537
7375

Recurrence Rel. - J. T. Butler

Fibon. Dis. Proport.


Num.
to Fibon.
Num.
1
51
2
102
3
154
5
256
8
410
13
666
21
1075
34
1741
55
2817
89
4558
144
7375

an ~

Note:

Similar relationships are seen in the positions of


the moons of the planets Jupiter and Saturn.
For example,
51.2 = 7375/144

F
GH

Recurrence Rel. - J. T. Butler

I
JK

14

1.62 is the Golden Ratio or Divine


Proportion. It is the ratio of the
lengths of two sides of a rectangle
that has the most pleasing
appearance. It is commonly represented by (phi)

fn
=1
gn

1 1+ 5 1+ 5
2
5 2

Aphelion

Sun

13

Let fn ~ gn mean nlim

Thus,

Data from O. Lombardi and M. A. Lombardi,


The Golden Mean in the solar system,
Fibonacci Quarterly, Feb. 1984, pp.70-75.

= 0.724 (1.62) n

a n +1 1 + 5

= 162
.
an
2

Recurrence Rel. - J. T. Butler

15

Recurrence Rel. - J. T. Butler

The Fibonacci Square

16

Rearrange the pieces to form a 5 x 13 rectangle, as shown.

Cut the 8 x 8 square below into four


pieces as shown

Area = 8 x8 = 64

Area = 5 x13 = 65. The area has been


increased by 1.
Recurrence Rel. - J. T. Butler

17

Recurrence Rel. - J. T. Butler

18

Recurrence Relations - J. T. Butler


Identities

How to become rich!!

Fibonacci numbers satisfy many identities.

Theorem*:
an an-2 a2n-1 = (1)n
64

65

66.02

67.05

Do this with
gold!
Recurrence Rel. - J. T. Butler

Proof:

*This is due to J. D. Cassini Histoire Acad. Roy.


Paris 1 (1680), 201.

19

Recurrence Rel. - J. T. Butler

(1) with n replaced by n+1

n
an

0 1 2 3 4 5 6
1 1 2 3 5 8 13 ...
an = an-1 +an-2
an an-2 = a2n-1 +(1)n
13 5 = 82 +(1)6

Q.E.D.

21

Consider Pascals triangle left justified


n an
1
1 1
1 1
2 2
1 2 1
3 3
1 3 3 1
4 5
1 4 6 4 1
5 8
1 5 10 10 5 1
6 13
1 6 15 20 15 6 1
7 21
1 7 21 35 35 21 7
Recurrence Rel. - J. T. Butler

20

Fibonacci Sequence

By induction

a) (1) is satisfied for a0 = a1 = 1 and a2 = 2.


b) Assume (1) holds. We have
multiply (1) by -1
a2n-1 an an-2 = (1)n+1
(an+1 an) an-1 an an-2 = (1)n+1
an+1 an-1 an an-1 an an-2 = (1)n+1
an+1 an-1 an (an-1 +an-2) = (1)n+1
an+1 an-1 a2n = (1)n+1
Recurrence Rel. - J. T. Butler

(1)

Recurrence Rel. - J. T. Butler

22

Note that the diagonals sum to


Fibonacci numbers. Thus,
n
n k

an =
k = 0 k

23

Recurrence Rel. - J. T. Butler

24

Recurrence Relations - J. T. Butler


Problem:

Solution:

In a disk system, the appearance of a


pulse corresponds to a 1 and no pulse to a
0. However, because of instabilities, the
reading of data can become improperly
synchronized if too many consecutive 0s
occur. Derive an expression for bn, the
number of n bit binary numbers that
contain no pair of 0s. We will use these
as data.
Recurrence Rel. - J. T. Butler

We can form an n+1 bit sequence by


appending a 0 or 1 to an n bit
sequence. A 1 can be appended to an
n bit sequence that ends in either a 0 or
1. However, a 0 can only be appended
to an n bit sequence that ends in a 1
only.

25

Recurrence Rel. - J. T. Butler

b1n+1 = b1n +b1n-1 .


This looks like the Fibonacci recurrence.
In fact,
b11 = 1 (1)
b12 = 2 (01, 11)

Let b0n (b1n) be the number of n bit binary


numbers with no 00 that end in 0(1).
For n > 2
b1n+1 = b1n +b0n
(1) ends in a 1
b0n+1 = b1n
(2) ends in a 0
From (2)
b0n = b1n-1
(3)
Substitute (3) into (1)
Recurrence Rel. - J. T. Butler

27

Recurrence Rel. - J. T. Butler

n : 1
bn : 2
2n : 2

Choose
b10 = 1 .

Fibonacci sequence

Thus,
b1

n = an
b0n = b1n-1 = an-1

2
3
4

28

3
5
8

4
5
6
7
8
8 13 21 34 55
16 32 64 128 256

Note:
bn 0.724(1.62 ) n +1

= 0.
n 2 n
2n

and
bn = b1n +b0n = an +an-1 = an+1
Recurrence Rel. - J. T. Butler

26

lim

29

Recurrence Rel. - J. T. Butler

30

Recurrence Relations - J. T. Butler


a2x2 = a1x2 + a0 x2
a3x3 = a2x3 + a1 x3
a4x4 = a3x4 + a2 x4
etc.
Summing over all equations yields

Solution by Generating Function


We have
an = an-1 + an-2 .
Multiply both sides by xn. This yields
an xn= an-1 xn+ an-2 xn.
This represents an arbitrarily large number of
equalities, like so

a x

n=2

n=2

= x a n 1 x n 1 + x 2 a n 2 x n 2 .

n=2

With
A(x) = a0 + a1x + a2x2 +a3x3 + ... ,

Recurrence Rel. - J. T. Butler

31

Recurrence Rel. - J. T. Butler

A(x) can be expressed as follows.

[A(x) a1 x a0] = x [A(x) a0] +x2 A(x) .

A ( x) =

Solving yields

1
1 x x2
= 1 + x + 2 x 2 + 3x 3 + 5x 4 + 8x 5 +K .

A ( x) =

Recurrence Rel. - J. T. Butler

which is

FG
H

5 5 +1

2
1
x
5 1

IJ FG
K H
+

5 5 1

2
1
x
5 1

I
JK

I F
JK GH

1
5
.
5 1
2

I
JK

34

From the last expression, we can write the nth


term in the power series expansion of A(x) as

IJ
K

F
GH

1 1+ 5
an =
2
5

IF1+ 5I
JK GH 2 JK

F
GH

1 1 5

2
5

IF1 5I
JK GH 2 JK

which agrees, as it should, with the expression


as derived from the recurrence relation
solution.

F I
1 F 1 5I

G J 15 GH 1 +2 5 JK
5H 2 K
A( x ) =
F 1 1 5 xI + F 1 1 + 5 xI .
GH 2 JK GH 2 JK

Recurrence Rel. - J. T. Butler

IF
JK GH

5 1
5 1
x
2
2

F
GH

Rewriting this yields,

A( x) =

Fx
GH

5
=
+
5 1
x
x
2

33

1
1
=
,
1 x x2 x2 + x 1
1

Expanding in partial fractions, yields

These first few terms can be extracted using a


polynomial manipulation package like
MACSYMA.
Recurrence Rel. - J. T. Butler

32

35

Recurrence Rel. - J. T. Butler

36

Recurrence Relations - J. T. Butler


To find known sequences*, you can

An interesting application of
recurrence relations is the
Fibonacci Number System

send an E-mail message to sequences


@research.att.com , in which the first line
is, for example, "lookup 1 1 2 3 5 8 13".
Sometime later, you will receive an E-mail
showing the result of the search. Also visit
the web page http://netlib.att.com/netlib

An alternative to the binary number


system is the Fibonacci number system.

/att/math/sloane /doc/eistop.html .
*The Encyclopedia of Integer Sequences by N. J. A.
Sloane & S. Plouffe, Academic Press, ISBN 0-12558630-2.
Recurrence Rel. - J. T. Butler

37

Recurrence Rel. - J. T. Butler

Recall that in the standard binary number


system, an integer N is the sum of powers of 2.
That is,

Example:
1=
1
2 = 10
3 = 100
4 = 101
5 = 1000

N = bm-12m-1 + bm-22m-2 + ... + b121 + b020.


In the Fibonacci number system, an integer N
is the sum of Fibonacci numbers. That is,
N = bm-1am + bm-2am-1 + ... + b1a2 + b0a1,
where a1=1, a2=2, a3=3, a4=5, a5=8, ... .
Recurrence Rel. - J. T. Butler

39

Recurrence Rel. - J. T. Butler

b2 b1 = 1
678
011 = 3
110 = 5
123
b3 b2 = 1
40

are useful in encoding applications.


For example, due to physical
limitations of CD-ROMs, data with
adjacent 1s cannot be reliably stored,
and a Fibonacci-like number system
is used1.

A disadvantage of the Fibonacci


Number System is that certain integers
have more than one representative.
For example,
100 = 011 = 3.
However, if we restrict the binary
tuples to having no pair of adjacent
1s, then each integer has a unique
representative. Such representations
Recurrence Rel. - J. T. Butler

38

1S. T. Klein, Combinatorial representation of

generalized Fibonacci numbers, The Fibonacci Quarterly, 29.2, May 1991, pp. 124-131.

41

Recurrence Rel. - J. T. Butler

42

Recurrence Relations - J. T. Butler


Theorem:

Any integer n can be


expressed uniquely as

Proof:

By induction.

The statement holds for m = 3, e.g., 1 = 1, 2 =


10, 3 = 100, and 4 = 101.

n = bi ai ,
i =1

where bi = 0 or 1, bi bi+1 = 0, bm =
1, ai is the ith Fibonacci number,
and am is the largest Fibonacci
number just less than or equal
to n.
Recurrence Rel. - J. T. Butler

Assume that it holds for all m < m, and


consider an n such that am is the largest
Fibonacci number < n.
Let bm = 1, and
consider bm-1, which is determined by n-bm.

43

Recurrence Rel. - J. T. Butler

Solving recurrence relations

If n-am am-1, then n am+am-1 = am+1, and it


follows that am is not the largest Fibonacci
number greater than or equal to n. Therefore,
n - am < am-1, and it follows that bm-1 = 0.
By the inductive assumption, n am has
a unique representation of the form described
in the problem statement. Since bmbm-1 = 10,
so does n.

This is similar to the process of solving


differential equations.

Example:

Solve the difference equation


an +2an-1 = n + 3,
subject to the initial condition
a0 = 3.

Q.E.D.
Recurrence Rel. - J. T. Butler

44

45

Recurrence Rel. - J. T. Butler

46

Substituting yields
A n = 2A n-1
= 2 .

First, solve for the homogeneous solution


a(h)n + 2a(h)n-1 = 0
a(h)n = 2a(h)n-1 .
Assume a solution of the form
a(h)n = A n .

Recurrence Rel. - J. T. Butler

Thus,
a(h)n = A (2)n .
Assume a particular solution of the form
a(p)n = Bn +D .
Substituting this yields
[Bn +D] +2 [B (n1) +D] = n + 3 .

47

Recurrence Rel. - J. T. Butler

48

Recurrence Relations - J. T. Butler


which yields

The total solution is the sum of the


homogeneous and particular solution.

3Bn + 3D -2B = n + 3 .
Comparing coefficients yields
3B = 1 and 3D 2B = 3 .
That is,
B=

1
3

D=

an = an( h ) + an( p ) = A ( 2) n +

Applying the boundary condition a0 = 3 yields


A = 16/9 and so

11
.
9

and so
a
Recurrence Rel. - J. T. Butler

( p)
n

n 11
+ .
3 9

an =

n 11
= + .
3 9
49

Recurrence Rel. - J. T. Butler

When the particular and homogenous solutions are not linearly


independent

16
n 11
( 2 ) 2 + + .
9
3 9
50

First, solve for the homogeneous solution


a(h)n - 2a(h)n-1 = 0
a(h)n = 2a(h)n-1 ,
which has a solution of the form
a(h)n = A 2n .

This is similar to the process of solving


differential equations under similar conditions.

Example: Solve the recurrence relation


an =2an-1 +2n - 1
subject to the initial condition a0 = 0 .
Recurrence Rel. - J. T. Butler

51

Recurrence Rel. - J. T. Butler

Assume now a particular solution of the form


a(p)n = Bn2n +D .

Assume a particular solution of the form


a(p)n = B2n +D .

Substituting this yields


[Bn2n +D] =2 [B(n -1)2n -1+D] + 2n - 1.

Substituting this yields


[B2n +D] =2 [B2n -1+D] + 2n - 1.

Equating coefficients yields the following.


Bn2n =2Bn2n-1 - 2B 2n-1 + 2n and
D = 2D - 1.

Note that we cannot solve for B; it drops out


of both sides of the equation.
Recurrence Rel. - J. T. Butler

52

53

Recurrence Rel. - J. T. Butler

54

Recurrence Relations - J. T. Butler


Domain and range
transformation

Therefore, B = 1 and D = 1, and we have


an = a(h)n+a(p)n = A2n + n2n+1.
Solving for A yields
a0 = 0 = A1 + 0 +1,
and
A = -1.
Therefore,
an = (n-1) 2n + 1.
Recurrence Rel. - J. T. Butler

Applies to recurrence relations that are not


linear.
Domain
Range

55

n=0 1 2 3 4 5 6
an = 1 1 2 3 5 8 13 ...

Recurrence Rel. - J. T. Butler

56

Range Transformation
Consider

Solving bn = 2 bn-1 + log2 3 using methods


described earlier yields

an = 3a2n-1
for n > 1 and a0 = 1. Let
bn = log2 an.
Thus,
bn = log2 an = 2log2 an-1 + log2 3 = 2bn-1 +log2 3
with
b0 = 0 .
Recurrence Rel. - J. T. Butler

or

an = 2 ( 2

57

1) log 2 3

Recurrence Rel. - J. T. Butler

= 2 log 2 3

( 2 n 1 )

= 32

58

Let n = 2k and ak = tn. Thus,


ak = 2ak -1 + 2k - 1 for k > 1
a0 = 0.
Solving this yields
ak = -2k + k2k + 1 = (k-1)2k + 1.
From this, we obtain
tn = (log2 n - 1) n + 1.

Domain Transformation
The merge sort divides a set of n numbers in
half, sorts each half, then merges each half
together using at most n-1 comparisons. If n
is a power of 2, an upper bound tn on the
number of comparisons is
tn = 2tn/2 + n - 1
n>2
t1 = 0.
.
Recurrence Rel. - J. T. Butler

bn = ( 2 n 1) log 2 3

59

Recurrence Rel. - J. T. Butler

10

60

Recurrence Relations - J. T. Butler


n 1

Distinct Recurrence Relations


Generate the Same Sequence

dn =

rd

n r +1

+ n +1

n 3,

(1)

r =2

where d0 = 0, d1 = 1 and d2 = 3. Rearranging yields

An interesting recurrence relation appears in


T. Sasao and K. Kinoshita, On the number of
fanout-free functions and unate cascade functions,
IEEE Trans. on Comp. Jan. 1979, p. 66-71.

n +1

2d n =

Recurrence Rel. - J. T. Butler

+ 1.

( 4)

n =1

n i

xn

n =1 i = 0

(5)
D( x ) =

n =1

O( x ) = 1 + 2 x + 3x 2 +... =

b g
1 x

D ( x ) 4 xD( x ) + 2 x 2 D ( x ) x + x 2 = 0 .
Recurrence Rel. - J. T. Butler

64

Recurrence Rel. - J. T. Butler

66

(9)

Comparing (1) and (9) shows a very interesting


relation. The recurrence relation expressed in the
sum of (1) describes exactly the recurrence relation
of (9) without sums!

Recurrence Rel. - J. T. Butler

( 6)

x x2
= x + 3 x 2 + 10 x 3 + 34 x 4 +... .(7 )
1 4x + 2x2

Equating coefficients in (8) yields

n3

Rearranging (7) yields

63

d n = 4 d n 1 2 d n 2 .

b1 xg

Rearranging (6) yields

x .

Let

Recurrence Rel. - J. T. Butler

(3)

62

2 D( x ) = O( x ) D( x ) +

+1,

We have

Multiplying (4) by xn and summing yields

d x = o d

n i

D ( x ) = d 0 + d 1 x + d 2 x 2 +... .

i =0

(i + 1)d
i =0

61

n i

( 2)

2d n =

o d

n 1.

The range of (2) is noted to now apply to n = 1 and n = 2.


Letting i = r - 1 yields,

and substituting oi = i + 1 yields

2d n =

+1

n r +1

r =1

The number of p-equivalent classes of


cascade functions dn on n variables is given by the
recurrence relation
Recurrence Rel. - J. T. Butler

rd

65

11

(8)

Inclusion/Exclusion - J. T. Butler
Inclusion/Exclusion

Example:

Example:

How many numbers between 1 and


6300 inclusive are not divisible by
either 5 or 3?

How many numbers between 1 and


6300 inclusive are not divisible by 5?

6300/3 = 2100 are divisible by 3

Every 5th number is divisible by 5.


That is, of the 6300 numbers, 6300/5 =
1260 are divisible by 5. Thus, 6300
1260 = 5040 are not.
Inclusion/Exclusion - J. T. Butler

6300/5 = 1260 are divisible by 5

Inclusion/Exclusion - J. T. Butler

Thus, 6300 -2100 -1260 +420 = 3360


numbers are divisible by either 5 or 3.

But 630021001260 is not


correct,
because
we
have
subtracted out those numbers
divisible by 3 and 5 twice (once in
2100 and once in 1260). We must
add it back in. That is, we must
add 6300/5 3 = 420 back in.

6300

2100

1260

420
Divisible by 3

Divisible by 5
Divisible by 5 & 3

Inclusion/Exclusion - J. T. Butler

Inclusion/Exclusion - J. T. Butler

Let

General Formulation

N (ai) = number of elements with property ai


(and maybe other properties)

Consider a set of N objects with


properties a1, a2, ... , and ar. The
properties could be color, divisibility by
certain numbers, etc. In general, any of
the N objects can have more than one
property.
Inclusion/Exclusion - J. T. Butler

N (ai, aj, ... , ak) = number of elements with


properties ai, aj, ... , & ak
N (ai) = number of elements that do not have
property ai
N (ai, aj, ... , ak) = number of elements that
do not have properties ai, aj, ... , & ak

Inclusion/Exclusion - J. T. Butler

Inclusion/Exclusion - J. T. Butler
In our example,

Theorem:

a1 --- divisible by 3
a2 --- divisible by 5

N (a1 , a 2 ,K , a r ) = N N (ai )
i

We saw that

3360
6300 2100 1260
420
N (a1, a2) = N N (a1) N (a2) +N (a1, a2)

N (a , a

, ak )

i , j ,k i j , j k ,k i

Objects with exactly s of the properties


contribute 1 to N, C (s,1) to i N (ai),
C (s,2) to i j N (ai, aj), C (s,3) to
i j, j k, k i N (ai, aj, ak), etc. Thus,
the contribution to the right side is

Objects which do not have any property


a1, a2, ... , and ar are counted once in
N(a1, a2, ... , ar) and once in N, but no
where else.

0 = 1 C(s,1) + C(s,2) C(s,3)

Objects with exactly one property are


counted once in N and once in N ( ai )
i
and no where else.

+ ... + (1)s C(s,s)


Q.E.D.

Inclusion/Exclusion - J. T. Butler

10

Let S be the set of permutations of the


26 letters. It has N = 26! elements.
Let there be 4 properties
a1 contains the pattern car ,
a2 contains the pattern dog ,
a3 contains the pattern pun,
a4 contains the pattern byte
N (a1 ) = 24!, since we can have a

Example
In how many ways can the 26 letters
be permuted so that none of the ways
contains pattern car, dog, pun, or
byte?

Inclusion/Exclusion - J. T. Butler

Inclusion/Exclusion - J. T. Butler

Proof:

Inclusion/Exclusion - J. T. Butler

+K+ ( 1) r N (a1 , a 2 ,K , a r )

Number divisible by 3
Number divisible by 5
Number divisible by 3 and 5
Inclusion/Exclusion - J. T. Butler

N (a , a

i, j, i j

11

Inclusion/Exclusion - J. T. Butler

12

Inclusion/Exclusion - J. T. Butler
and N (ai , a 4 ) = 21!, for i 4. Also,
N (a1 , a 2 , a 3 ) = 20!, N (ai , a j , a 4 ) = 19 !, for

permutation of car , b, d , e, ... , y , z in


24! ways. Note that N ( a1 ) counts permu tations that contain car and may or may
not contain other patterns. Similarly,
N ( a2 ) = N ( a3 ) = 24! and N (a4 ) = 23!.
N ( a1 , a2 ) = 22! because this is the number
of ways to permute the 22 objects car ,
dog , b, e, ... y , z. Further, N ( a1 , a3 ) =
N ( a2 , a3 ) = 22!
Inclusion/Exclusion - J. T. Butler

1 i < j 3, and N ( a1 , a 2 , a 3 , a 4 ) = 17 !.
Applying the principle of inclusion / exclu sion, we find that N (a '1 , a ' 2 , a ' 3 , a ' 4 ) =
26! [3 24 !+ 23!] + [3 22 !+ 3 21!] [20!+
3 19 !] + 17 !.

13

Inclusion/Exclusion - J. T. Butler

Example

14

For n = 3, there are two derangements

Definition:

1 2 3

A derangement is a permutation of n
integers such that no integer is in its
own position. Let dn be the number
of derangements on n integers.

2 3 1
3 1 2

Inclusion/Exclusion - J. T. Butler

15

Inclusion/Exclusion - J. T. Butler

Calculate dn using the principle of


inclusion/exclusion.
Let ai be the
property that i is in its natural position.
Then,
N (ai) = (n1)!

N(a1,a2,a3)=1 1 2 3
N(a1)=2

N (ai, aj ,ak) = (n3)!

17

1
1
3
2
3
2

Inclusion/Exclusion - J. T. Butler

d3 = 2

16

For n = 3, N(ai), etc. is

N (ai, aj) = (n2)!

Inclusion/Exclusion - J. T. Butler

U|
V|
W

2
3
2
1
1
3

3
2
1
3
2
1
18

N(a1,a2)=1
N(a1,a3)=1
N(a2,a3)=1
N(a2)=2
N(a3)=2

Inclusion/Exclusion - J. T. Butler
d n = N ( a1, a2 ,K, an ) = n !

FG nIJ ( n 1)!
H 1K

The general term in this sum is


( 1) i

FG nIJ ( n 2)! FG nIJ ( n 3)!


H 2K
H 3K
F nI
+K+( 1) G J 0 !
H nK

FG
H

IJ
K

Truncated Maclaurin series* for e-1


*The Maclaurin series for the exponential

x2 x3
xi
function is e x = 1 + x +
+ +... = .
2! 3!
i =0 i !

19

Inclusion/Exclusion - J. T. Butler

20

Example:

It turns out that


n!
,
e

dn =

Ten gentlemen check their hats and


receive them back randomly. The
number of ways hats can be returned
such that no gentleman gets his own
hat is
10 !
dn =
= 1,334,961
e

where ||a|| is the closest integer to a.

21

Inclusion/Exclusion - J. T. Butler

The probability that no gentleman will


get his own hat is
10!
dn
1
e
=
= 0.36788
10! 10! e
Note: This approximation is independent
of n. That is, d10/10! is essentially the
same as d10000/10000!.

Inclusion/Exclusion - J. T. Butler

1 1 1
1
d ( n) = n! 1 + +L+ ( 1) n
1
!
2
!
3
!
n
!
1444442444443

Inclusion/Exclusion - J. T. Butler

Thus,

Inclusion/Exclusion - J. T. Butler

FG nIJ (n i )! = (1) FG n! IJ (n i )! = (1) n! .


i!
H iK
H (n i)!i !K

22

Example:
A man takes 8 spark plugs out of
his car to clean them. He
intended to put each back into the
same cylinder from which it
came, but got mixed up.

23

Inclusion/Exclusion - J. T. Butler

24

Inclusion/Exclusion - J. T. Butler
d8
8!

Assuming the spark plugs go


back randomly, what is the
probability at least one goes
back to where it came? at least
2?

is the probability that no spark


plug goes in its original
position

d8
is the probability that at least
8! one goes back in its original
position

Inclusion/Exclusion - J. T. Butler

25

8d7

is the number of ways exactly


one spark plug goes in its original position

d8

is the number of ways no spark


plug goes in its original position

Inclusion/Exclusion - J. T. Butler

Inclusion/Exclusion - J. T. Butler

d8 +8d7

26

is the number of ways


one or no spark plug
goes back in its original
position

8! d8 8d7 is the number of ways


2, 3, ... , or 8 spark
plugs go back into their
original positions

27

Inclusion/Exclusion - J. T. Butler

28

Inclusion/Exclusion - J. T. Butler

30

Thus, the probability at least two


spark plugs go back into their
original position is
8 ! d8 8 d7
d 8d
= 1 8 7
8!
8! 8!
d
d
= 1 8 7
8! 7!
1 2 e 1
0.26424
Inclusion/Exclusion - J. T. Butler

29

Asymptotic Approximations from Generating


Functions - J. T. Butler
Asymptotic Approximations
from Generating Functions

an ~ bn if lim
n

an is an asymptotic approximation
to bn. Typically, an is the exact
value, and bn is a simple
approximation.

A simple expression for


the coefficient an of x n
in A( x) when n is large
Asymptotic Approximations - J. T. Butler 1

Asymptotic Approximations - J. T. Butler 2

Example: Fibonacci

(1) can be written as

Generating Function
A( x ) =

A( x ) = 1 + x + 2 x 2 + 3x 3 + 5 x 4 + ...
1
=
1 - x - x2

(1)

Asymptotic Approximations - J. T. Butler 3

an =

F
GH

F
GH

1 1+ 5
2
5

I
JK

1+ 5
1
x
2

F
GH

1 1 5
2
5
1 -

I
JK

1- 5
x
2

Asymptotic Approximations - J. T. Butler 4

a n = 0.724 1.618 n

From this, we can write

I LM1 + 5 OP
JK N 2 Q
1 F 1 5 I L1 5 O
G JM P
5 H 2 KN 2 Q

1 1+ 5
2
5

an
=1
bn

+ 0.276 0.618 n , (2)


where 0.724 is the (approximate)
n

value of

Asymptotic Approximations - J. T. Butler 5

F
GH

Asymptotic Approximations - J. T. Butler 6

I
JK

1 1+ 5
, etc.
2
5

Asymptotic Approximations from Generating


Functions - J. T. Butler
When n is large, the left term of (2)

The original equation had the form


g1
g
g
A( x ) =
+ 2 +...+ k (3)
x
x
x
1111
2
k

dominates, and we can write

F
GH

1 1+ 5
2
5

a n ~ bn =

I LM1 + 5 OP
JK N 2 Q

0.724 1.618 n
Asymptotic Approximations - J. T. Butler 7

Asymptotic Approximations - J. T. Butler 8

Example:

If 1 < 2 < ... < k are real - valued


and g1 , g2 , ... , gk are real - valued,
then we have
an ~ g1

LM 1 OP
N Q

A( x ) =

Asymptotic Approximations - J. T. Butler 10

i greater than 1 complicates the calcula tion. However, we can proceed as follows.

A more general form of (3) is


g1 ( x )
g2 ( x )
gk ( x)
A( x ) =
+
+...+
, (4)
1
2

x
x
x
1111
2
k

FG
H

1000
1000000
+
x
x
1
1
13
12

~ 4 5n .

Asymptotic Approximations - J. T. Butler 9

IJ
K

x
15

then, an = 4 5n + 1000 3n + 100000 2 n

FG
H

If

IJ
K

FG
H

IJ
K

Example:

where 1 < 2 < ... < k and i 1.

A( x ) =

Asymptotic Approximations - J. T. Butler 11

1 + x2
1 1+ x2
=
2
4 4x + x2
4
x
1
2

Asymptotic Approximations - J. T. Butler 12

FG
H

IJ
K

Asymptotic Approximations from Generating


Functions - J. T. Butler
We can write
an =
=

LM FG
N H

IJ
K

The asymptotic approximation is


only slightly less complex than
the exact value.
5n
an ~ n+2 .
2

IJ OP (5)
KQ

FG
H

1 1 n + 2 1
1 n 2 + 2 1
+ n2
n
n2
4 2n
2
5n 3
2n+2

Asymptotic Approximations - J. T. Butler 13

Asymptotic Approximations - J. T. Butler 14

If the leftmost term of (4) has the form

Notice that both terms in (5)


contribute to the asymptotic
approximation. This is true, in
general, for such expressions.
Consider this in more detail.

g1 ( x )

FG1 x IJ
H K

FG1 x IJ
H K

Asymptotic Approximations - J. T. Butler 16

Note that

then,

FG n i + s 1IJ =
H ni K
bn i + s 1gbn i + s 2g...(n i + 1) ,
bs 1g!
which is approximately n b s 1g!

FG 1 IJ FG n + s 1IJ + b FG 1 IJ FG n 1 + s 1IJ +
H K H n K H K H n 1 K
F 1 I FG n p + s 1IJ
...+b G J
(6)
H K H n p K
n

n 1

Asymptotic Approximations - J. T. Butler 15

a n ~ b0

b0 + b1 x +...+b p x p

n p

s 1

when n is large.
Asymptotic Approximations - J. T. Butler 17

Asymptotic Approximations - J. T. Butler 18

Asymptotic Approximations from Generating


Functions - J. T. Butler
Theorem 1:

(from Leuker [1])


Suppose that for some real r > 0, A( x )
is analytic in the region | x| < r , and has

Thus,
an

n s 1
~
(b0 + b1 +...+b p p )
n
( s 1)!

an ~

a finite number k > 0 of singularities on


the circle | x| = r , all of which are algebraic.
Let i , i , and gi , i = 1,2,..., k , be the values

n s 1
g( )
n ( s 1)!

of , , and g in (4) corresponding to the ith


such singularity.

Asymptotic Approximations - J. T. Butler 19

Asymptotic Approximations - J. T. Butler 20

Then, A( x ) is the generating function

Definition: Gamma function, ( ),

whose coefficient of x n , an satisfies


1 k gi ( ) n
an ~
,

n i=1 ( i ) in

( ) =

(7)

e t t 1dt .

t =0

This is one of several definitions.

where denotes the gamma function.

Next (hidden) slide has two more.

Asymptotic Approximations - J. T. Butler 21

Asymptotic Approximations - J. T. Butler 22

b g

Properties

Definition: Gamma function, ( ),

( ) = 1 ! when is

m m!
,
m ( + 1)( + 2)...( + m)

a positive integer.

( ) = lim
and

( ) = ( 1)

(0) = ,

t
( ) = lim (1 ) mt 1dt .
m
m
t =0

FG 1 IJ = 2
H 2K

Asymptotic Approximations - J. T. Butler 23

FG 1IJ =
H 2K
.

Asymptotic Approximations - J. T. Butler 24

Asymptotic Approximations from Generating


Functions - J. T. Butler
Example:

Note:

Find an asymptotic
approximation to the number tn of
ordered binary trees with leaf nodes
given by

Theorem 1 applies to a
situation where there is more than one
singularity
on
the
circle
of
convergence (surrounding the region
|x|<r), where A(x) is analytic. In most
applications of this theorem, however, there is one or maybe two singularities.

T ( x) =

Asymptotic Approximations - J. T. Butler 25

12
1 1
1

1 4x =
+
. (8)
2 2
2 1 4 x 1 2

Asymptotic Approximations - J. T. Butler 26

Therefore,

Comparing (8) to (7), we find


1
k =1
1 =
4
1
1
1 =
g1 ( x ) = .
2
2

tn
since

1
n 1 2
1
2
~
n
1 1

2 4

FG IJ FG IJ
H KH K

FG 1 IJ = 2
H 2K

Asymptotic Approximations - J. T. Butler 27

Asymptotic Approximations - J. T. Butler 28

References
1. Leuker, G.S., "Some techniques for solving
recurrences," Computing Surveys, Vol. 12,
No. 4, Dec. 1980.
2. Bender, E. A., "Asymptotic methods in enu meration," SIAM Review, Vol. 16,
No. 4, Oct. 1974.
Asymptotic Approximations - J. T. Butler 29

Asymptotic Approximations - J. T. Butler 30

4 n 1
,
n3 2

Example of Asymptotic Approximations Structured Flowcharts- J. T. Butler


Enumeration of Structured Flowcharts

Assume that interchanging F1 and F2 in an


IF-THEN-ELSE flowchart leaves the
flow-chart unchanged.
Let ITE(x),
DW(x),and F(x) be the ordinary
generating functions for the number of IFTHEN-ELSE, DO-WHILE, and SEQUENCE flowcharts, respectively. A
structured flowchart is a SEQUENCE of p
IF-THEN-ELSE
and
DO-WHILE
flowcharts where p 0.

A structured flowchart consists of a set of decision


nodes interconnected by paths
Structured
Flowchart

N
F1

Structured
Flowchart

F1
F2

F1
F2

Fp
IF-THEN-ELSE

DO-WHILE
SEQUENCE

Structured Flowcharts - J. T. Butler 1

Structured Flowcharts - J. T. Butler 2

Specifically, ITE (x) = i0 +i1 x +i2 x2 + ,


DW (x) = d0 +d1 x +d2 x2 + , and F (x) =
f0 +f1 x +f2 x2 + , where ij, dj, and fj are
the number of IF-THEN-ELSE, DOWHILE, and SEQUENCE flowcharts,
respectively, with j decision nodes.

By hand calculation, we have ITE (x) =


x + 2x2 + , DW (x) = x + 2x2 + ,
and F (x) = 1 + 2x + 8x2 + . The
flowcharts with j nodes, for 0 j 2,
are shown on the next slide.

Structured Flowcharts - J. T. Butler 3

Structured Flowcharts - J. T. Butler 4

Let
represent a one-node IF-THEN-ELSE
flowchart and a one-node DO-WHILE
flowchart.
j

Structure SEQ ITE DW


type

We can calculate ITE (x) directly as


follows

2
ITE

DW

SEQ

ITE ( x ) =

1
(a path)

ij
0
1
dj
0
1
dj
1
2
Structured Flowcharts - J. T. Butler 5

x
x
F ( x) F ( x) + F ( x 2 )
2
2

2
2
8
Structured Flowcharts - J. T. Butler 6

(1)

Example of Asymptotic Approximations Structured Flowcharts- J. T. Butler


Consider the left term in (1) first. The x
represents the contribution to the node count
by N, the topmost node, while the two factors
F(x)F(x) represent the contributions to the node
count by sub-flowcharts F1 and F2. The factor
1/2 appears because of double counting which
occurs in xF(x)F(x). That is, a flowchart with
distinct choices for F1 and F2 is considered the
same as the flowchart obtained by interchanging
F1 and F2. Both flowcharts are included in
xF(x)F(x).

However, double counting does not occur if we


happen to choose F1 and F2 the same. Such
charts contribute only one-half of what they
should in x F(x) F(x)/2. Thus, we must add the
remainder of their contribution to the node count.
This contribution is expressed by x F(x2)/2, the
right term of (1).

Structured Flowcharts - J. T. Butler 7

Structured Flowcharts - J. T. Butler 8

All structured flowcharts consist of a


SEQUENCE of no, one, two, IFTHEN-ELSE
and
DO-WHILE
flowcharts. Thus, F(x) is

Similarly, for DO-WHILE flowcharts we


DW (x) = x F (x)

(2)

F ( x ) = 1 + ITE ( x ) + DW ( x ) + ITE ( x ) + DW ( x )

+ ITE ( x ) + DW ( x ) +K

Structured Flowcharts - J. T. Butler 9

(3)

Structured Flowcharts - J. T. Butler 10

The constant term of (3) corresponds to the


flowchart of no nodes. The [ITE (x) +DW (x)]
term is the contribution of a SEQUENCE of
one IF-THEN-ELSE or DO-WHILE flowchart.
The [ITE (x) + DW (x)]2 term corresponds to a
SEQUENCE of two such flowcharts, etc. We
can write (3) as follows
1
F ( x) =
(4)
1 ( ITE ( x ) + DW ( x ))

Substituting (1) and (2) into (4) and rearranging yields


F ( x) =

xF 3 ( x )
xF ( x ) F ( x 2 )
+ xF 2 ( x ) +
+1
2
2

(5)

Structured Flowcharts - J. T. Butler 11

Structured Flowcharts - J. T. Butler 12

Example of Asymptotic Approximations Structured Flowcharts- J. T. Butler


We have
We seek fn, the coefficient of xn in F (x).
This is accomplished by equating coefficients
on each side of (5). For example,

F (x) = 1 +2x +8x2 +43x3 + 258x4 +


The calculation of these coefficients was done
by computer using polynomial manipulation
programs. That is, substituting [0,0,0,0, ]
for F (x) on the left produces [1,0,0,0, ] for
F (x) on the left. Substituting [1,0,0,0, ] for
F (x) on the right produces [1,2,0,0, ] on the
left, etc. Substituting [1,2,0,0, ] for F (x) on
the right produces [1,2,8,0, ] on the left, etc.

f 0 = 1,
f1 =

f 03
f2
+ f 02 + 0 = 2 ,
2
2

f2 =

3 f 0 f1
f f
+ 2 f 0 f1 + 0 1 = 8
2
2

and

Structured Flowcharts - J. T. Butler 13

Structured Flowcharts - J. T. Butler 14

Enumeration of Structured Flowcharts


by Node Type and Height

A typical term in F (x,y) is anp xn yp, where


anp is the number of structured flowcharts
with n nodes p of which are IF-THEN-ELSE.
We have

I. Counting flowcharts by node type


Note that each node in a structured flow- chart
can be classified as on IF-THEN-ELSE type or
DO-WHILE type depending on how it is used.
Let F (x,y) be an ordinary generating function for
such flowcharts, where y accounts for IF-THENELSE nodes.
Structured Flowcharts - J. T. Butler 15

xyF 2 ( x , y ) xyF ( x 2 , y 2 )
+
2
2
DW ( x , y ) = xF ( x , y )
1
F ( x, y) =
1 ITE ( x , y ) DW ( x , y )
ITE ( x , y ) =

Structured Flowcharts - J. T. Butler 16

Substituting (4) and (5) into (6) and


rearranging yields

(6)
(7)

F ( x, y ) =

(8)

xyF 3 ( x , y )
xyF ( x , y ) F ( x 2 , y 2 )
+ xF 2 ( x , y ) +
+1
2
2

(9)

Structured Flowcharts - J. T. Butler 17

Structured Flowcharts - J. T. Butler 18

Example of Asymptotic Approximations Structured Flowcharts- J. T. Butler


Equating coefficients on each side of (7), we
get
a00 = 1
a10 = a00 = 1
a11 =

3
a00
a2
+ 00 = 1
2
2

Similarly, we can count the number of n-node


structured flowcharts where q of the nodes are
of type DO-WHILE. Let formal variable z
account for such nodes, and let F(x,z) be the
corresponding generating function. A typical
term in F(x,z) is bnqxpzq, where bnq is the
number of n-node structured flowcharts with q
DO-WHILE nodes.

a20 = 2a00 a10 = 2


3a a
a a
a21 = 00 10 + 2a00 a11 + 00 10 = 4
2
2
3a00 a11 a00 a11
a22 =
+
=2
2
2

Structured Flowcharts - J. T. Butler 19

Structured Flowcharts - J. T. Butler 20

Equating coefficients on each side of (8) we


get

We have
F ( x, z) =

xF 3 ( x , z )
xF ( x , z ) F ( x 2 , z 2 )
+ xzF 2 ( x , z ) +
+1
2
2

b00 = 1

(10)

b003 b002
+
=1
2
2
b11 = b002 = 1
b10 =

Structured Flowcharts - J. T. Butler 21

3b00b10 b00b10
+
=2
2
2
3b b
b b
b21 = 00 11 + 2b00b11 + 00 11 = 4
2
2
b22 = 2b11

b20 =

Structured Flowcharts - J. T. Butler 22

II. Counting Flowcharts by Height

F (x,t) is

A structured flowchart consists of a


SEQUENCE of h = 0, 1, 2, etc. IF-THENELSE and DO-WHILE flowcharts. h is
called the height. Consider a generating
function F(x,t) which accounts for height.
A typical term in F(x,t) is cnhxnth, where cnh
is the number of n-node flowcharts of
height h.

F ( x , t ) = 1 + ITE ( x ) + DW ( x ) t + ITE ( x ) + DW ( x ) t 2 +K

or
F ( x, t ) =

Structured Flowcharts - J. T. Butler 23

1
1 t ITE ( x ) t DW ( x )

Structured Flowcharts - J. T. Butler 24

(11)

Example of Asymptotic Approximations Structured Flowcharts- J. T. Butler


Knowing the coefficients in F(x), we can
derive the coefficients of F(x,t) in a manner
similar to past calculations

Substituting the expressions for ITE(x) and


DW(x) shown in (1) and (2), respectively, and
rearranging yields

c00 = 1

xt F 2 ( x ) F ( x , t ) xt F ( x 2 ) F ( x , t )
F ( x, t ) =
+
2
2
+ xt F ( x ) F ( x , t ) + 1

f 02 c00 f 0c00
+
+ f 0c0 = 2
2
2
2c f f
c21 = 00 1 2 + f 1c00 = 4
2
f 02 c11 f 0c11
c22 =
+
+ f 0c11 = 4
2
2
c11 =

(12)

Structured Flowcharts - J. T. Butler 25

Structured Flowcharts - J. T. Butler 26

Calculation of the Average Height


of n-node Structured Flowcharts

A typical term in F (x,t) is

cc t + c

From the section Counting Flowcharts by


Height, the generating function for n-node
height h flowcharts was
F ( x, t ) =

n1

n2

t 2 +K+ cnn t n x n ,

where cni is the number of n-node flowcharts


of height i.

xt F 2 ( x ) F ( x , t ) xt F ( x 2 ) F ( x , t )
+
+ xt F ( x ) F ( x , t ) + 1
2
2

where x and t account for n and h, respectively.


Structured Flowcharts - J. T. Butler 27

Structured Flowcharts - J. T. Butler 28

If F (x,t) is differentiated with respect to t, this


term becomes

cc

n1

cn1 + 2cn 2 +K+ ncnn


fn

+ cn 2 t +K+ ncnn t n 1 x n .

Setting t = 1 yields

bc

The average depth of n-node flowcharts is just

n1

+ 2cn 2 +K+ ncnn x n .

where fn is the number of n-node structured


flowcharts.

The coefficient is a weighted sum in which each


n-node flowchart with height i contributes i.
Structured Flowcharts - J. T. Butler 29

Structured Flowcharts - J. T. Butler 30

Example of Asymptotic Approximations Structured Flowcharts- J. T. Butler


We have

Thus, we proceed by differentiating F (x,t)


with respect to t and setting t to 1.
3

F ( x ,1) =

c11 =

F ( x , t )
xF ( x ) + F ( x ) F ( x ,1)
=
t t =1
2
xF ( x 2 ) F ( x ) + F ( x 2 ) F ( x ,1)
2
+ xF 2 ( x ) + xF ( x ) F ( x ,1)
+

2c11 =

Structured Flowcharts - J. T. Butler 31

f 03 + f 02 0 f 03 + f 02 0
+
+ f0 + f00 = 2
2
2
c
2
Avg.ht. = 11 = = 1.0
f1 2
3 f 02 f 1 + f 02 c11 + 0 f 0 f 1 + f 0c11
+
+ 2 f 0 f 1 + f 0c11 = 12
2
2
c21 + 2c22 12
Avg.ht. =
=
= 15
.
f2
8

Structured Flowcharts - J. T. Butler 32

Large Structured Flowcharts


Fraction
of large
flowcharts

DWW

UV
W
R

ITE

ST

1 2

Height

ITE -- fraction of flowcharts of height 1 which are


IF-THEN-ELSE.
DWW -- fraction of flow charts of height 1 which are
DO-WHILE.
Structured Flowcharts - J. T. Butler 33

Structured Flowcharts - J. T. Butler 34

Example of the Use of Asymptotic Approximations - Binary Decision Diagrams - J. T. Butler


Outline

Example of the Use of


Asymptotic Approximations

Introduction
Average

Asymptotic approximations

Finding average value


asymptotic approximations
for Fibonacci BDDs

BDD Avg. No. of Nodes - J. T. Butler

number of nodes

Variance

of the number of nodes

Asymptotic approximations
Conclusions

BDD Avg. No. of Nodes - J. T. Butler

Example: A BDD for the AND function is

Introduction
decision diagram (BDD) graph representation of a switching
function, where

x2

1
0

Nodes represent subfunctions


Arcs represent assignments of values
to variables
BDD Avg. No. of Nodes - J. T. Butler

x1

Binary

BDD Avg. No. of Nodes - J. T. Butler

x3

1 x4

1
4

A threshold function, f ( x1 , x 2 ,... x n ) has the pro perty that f = 1 if and only if w1 x1 + w2 x 2 +...

For example, (1,1,1,1;4) is the weight threshold vector of the AND function,
whose BDD has been previously shown.

+ wn x n T . For some assignments of values to


x1 , x 2 ,..., x n , the weighted sum w1 x1 + w2 x 2 +...
+ wn x n is T or greater, in which case f = 1.
Otherwise, f = 0.
( wn , wn 1 ,..., w1 ; T ) is the weight - threshold
vector of f .
BDD Avg. No. of Nodes - J. T. Butler

BDD Avg. No. of Nodes - J. T. Butler

Example of the Use of Asymptotic Approximations - Binary Decision Diagrams - J. T. Butler


A Fibonacci function is a threshold
function in which the weights, wi ,

For example, (3,2,11


, ;7) is the weight threshold vector of the AND function,
which is a Fibonacci function!

are Fibonacci numbers. Specifically,


Fibonacci functions have a weight threshold vector of the form ( f n , f n 1 ,
..., f 1 ; T ), where f i is the nth Fibo nacci number.
BDD Avg. No. of Nodes - J. T. Butler

BDD Avg. No. of Nodes - J. T. Butler

Average Number of Nodes


We have,

The generating function for the number


of Fibonacci BDDs with n variables
and i nodes is T(x,y). That is,

T ( x, y) =

x 3 y 5 2 x 3 y 7 + xy 3

b1 xyg c1 x y
2

2x2 y4

(1)

T ( x , y ) = ... + t n ,i x n y i + ... ,
where t n ,i is the number of Fibonacci
BDD' s with n variables and i nodes.
BDD Avg. No. of Nodes - J. T. Butler

BDD Avg. No. of Nodes - J. T. Butler

10

We have
T ( x , y) =

... + x n [t n ,n + 2 y n + 2 + t n ,n + 4 y n + 4 +...]+... .

Setting y to 1 yields
d
T ( x , y ) =...+ x n [(n + 2) t n ,n + 2 + (n + 4) t n ,n + 4 +...]+... ,
dy

Differentiating with respect to y yields


d
T ( x , y ) = ... + x n [(n + 2)t n ,n + 2 y n +1
dy

y =1

where the sum represents the total number of

+ ( n + 4)t n ,n + 4 y n + 3 +...]+... .

BDD Avg. No. of Nodes - J. T. Butler

nodes in BDD' s on n variables. Dividing this


by the total number of BDD' s, yields the aver age number of nodes in BDDS' s on n variables.

11

BDD Avg. No. of Nodes - J. T. Butler

12

Example of the Use of Asymptotic Approximations - Binary Decision Diagrams - J. T. Butler


Differentiating (1) with respect to y and setting

The total number of BDD' s is f n + 2 1, which

y to 1 yields
T ( x) =

3 + 2x

c1 x x h

2 2

7 + 3x
1 x x2
1

b1 xg

BDD Avg. No. of Nodes - J. T. Butler

is given by the asymptotic approximat ion

3
.
1 x

1
5

(2)

13

1 + 5

BDD Avg. No. of Nodes - J. T. Butler

n+2

(3)

14

Asymptotic Approximations

Next, derive the asymptotic approximation

Now , derive an asymptotic approximation

for the total number of nodes from (4)

for the total number of nodes. First, form a

as follows.

F 11 + 5
GH 10

partial fraction expansion of (2), like so


11 + 5 5
10
T ( x) =
2
1
x
5 1

LM
N

61 + 31 5

OP LM1
Q N
2

BDD Avg. No. of Nodes - J. T. Butler

10 5
2

(n + 1)

61 + 31 5
10 5

IJ
K

2
. (5)
5 1

OxP +... (4)


5 1 Q

15

BDD Avg. No. of Nodes - J. T. Butler

Dividing (5) by (3) yields the average


number of nodes as

16

Using generating functions, we can also


compute the actual average number of
nodes. We can then compare with the
asymptotic approximation. Doing this
yields an interesting result, as shown in
the following table.

5+ 2 5
2+6 5
n
18944
.
n 3.0832.
5
5
The only other known average number of
nodes is for symmetric functions, which is
n2
.
2
BDD Avg. No. of Nodes - J. T. Butler

I FG
JK H

17

BDD Avg. No. of Nodes - J. T. Butler

18

Example of the Use of Asymptotic Approximations - Binary Decision Diagrams - J. T. Butler


At n=14, the actual average number of
nodes is 23.481. The asymptotic
approximation, 1.8944n, yields, for
n=14, a value of 26.5216.
The
asymptotic approximation we derived
earlier, 1.8944n - 3.0832, yields, for
n=14, a value of 23.4384, which is
closer. Thus, for small n, 3.0832 is
significant.

No. of
Avg. No.
Variables of Nodes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Infinity

3.000
4.000
5.000
6.286
7.667
9.200
10.818
12.519
14.273
16.070
17.897
19.745
21.608
23.481
1.8944n

BDD Avg. No. of Nodes - J. T. Butler

19

BDD Avg. No. of Nodes - J. T. Butler

Variance on Number of Nodes

If we differentiate (1) with respect to y multiply

If X is a random variable, then the variance,


( X ), of X is given as
( X ) = E( X 2 ) E 2 ( X )

20

by y , differentiate again with respect to y , and


set y equal to 1, the coefficient of x n in the

resulting expression is X 2 . Dividing this by

where E ( X ) is the expected value of X . We


just calculated E ( X ). Now consider the cal -

the number of BDD' s on n variables yields


E ( X 2 ). Doing this

cuation of E ( X ).
BDD Avg. No. of Nodes - J. T. Butler

16 + 10 x

1 x x
+

h c

2 3

49 + 16 x

1 x x

21

BDD Avg. No. of Nodes - J. T. Butler

49 + 25x
1 x x2

h c

2 2

b1 - xg b g b g b g
3

Asymptotic Approximations

1
23
2

+
1- x
1- x
1+ x

We can rewrite (6) as

( 6)

FG
H

The coefficient of x in (6) is decreased by

47 + 21 5
5 5
2
1
x
5 1

691 + 277 5
50

2
2
1
x
5 1

IJ FG
K H
3

E 2 ( X ) and the result divided by the number


2

of Fibonacci BDD' s to get ( X ).


BDD Avg. No. of Nodes - J. T. Butler

22

23

BDD Avg. No. of Nodes - J. T. Butler

IJ
K

2131 + 881 5
50 5
+
+ ... (7)
2
1
x
5 1
24

FG
H

IJ
K

Example of the Use of Asymptotic Approximations - Binary Decision Diagrams - J. T. Butler


where the contribution to

Dividing this result (7) by the number of Fibonacci

from other terms

is negligible compared to the terms shown. The

BDD's (3), yields E ( X 2 ). Subtracting from this the


square of the average number yields the following

contribution of these three terms is

asymptotic approximation for the variance

b g

47 + 21 5 2
691 + 277 5
n + 3n + 2
n +1
50
10 5
+

2131 + 881 5
]
50 5

BDD Avg. No. of Nodes - J. T. Butler

LM
N

2
5 1

OP
Q

100 44 5
228 28 5
n+
= 0.0645n + 6.6156. (9)
25
25

(8)

25

BDD Avg. No. of Nodes - J. T. Butler

Using generating functions, we can


also compute the actual standard
deviation of nodes. We can then
compare with the asymptotic
approximation. Doing this yields
and interesting result, as shown in
the following table.

(8) is an expression for 2 ( X ). The standard


deviation ( X ) is
(X) ~

0.0645n + 6.6156

~ 0.2540 n

BDD Avg. No. of Nodes - J. T. Butler

27

BDD Avg. No. of Nodes - J. T. Butler

BDD Avg. No. of Nodes - J. T. Butler

28

At n=14, the actual standard deviation


of nodes is 2.609. The asymptotic
approximation, 0.2540 n , yields, for
n=14, a value of 0.9504.
The
asymptotic approximation we derived
earlier, 0.0645n + 6.6156 , yields, for
n=14, a value of 2.7420, which is
closer. Thus, for small n, 6.6156 is
significant.

No. of
Standard
Variables Deviation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Infinity

26

0.000
0.000
0.000
0.700
0.943
1.327
1.585
1.853
2.049
2.224
2.354
2.462
2.543
2.609
1/2
0.2540n

29

BDD Avg. No. of Nodes - J. T. Butler

30

Example of the Use of Asymptotic Approximations - Binary Decision Diagrams - J. T. Butler


Conclusions

Reference

Generating

functions provide an
effective way to compute

1.
J. T. Butler and T. Sasao,
Average number of nodes in binary
decision diagrams of Fibonacci
functions, The Fibonacci Quarterly,
Vol. 34.5, November 1996, pp. 413422.

Average values
Standard Deviation (Variance)
Generating

functions provide an
effective way to compute simple
asymptotic approximations

BDD Avg. No. of Nodes - J. T. Butler

31

BDD Avg. No. of Nodes - J. T. Butler

33

BDD Avg. No. of Nodes - J. T. Butler

32

You might also like