Generating Functions and Counting Trees. Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

6.4 Factoring and Solving Polynomial Equations
Chapter 6 Advanced Counting 6.1 Recurrence Relations.
Recursion Lecture 18: Nov 18.
Ch 5.2: Series Solutions Near an Ordinary Point, Part I
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
6.5 & 6.6 Theorems About Roots and the Fundamental Theorem of Algebra
Linear Equations in Linear Algebra
Recursion Lecture 17: Nov 11. Quiz int hello(int n) { if (n==0) return 0; else printf(“Hello World %d\n”,n); hello(n-1); } 1.What would the program do.
6.Advanced Counting Techniques 1 Copyright M.R.K. Krishna Rao 2003 Ch 6. Recurrence Relations A recurrence relation for the sequence {a n } is an equation.
Solving Polynomial Equations
1 5.6 Complex Zeros; Fundamental Theorem of Algebra In this section, we will study the following topics: Conjugate Pairs Theorem Finding a polynomial function.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Quadratic Functions A quadratic function is a function with a formula given by the standard form f(x) = ax2+bx+c, where a, b, c, are constants and Some.
Generating Function October 21, 2014 Generating Functions Given an infinite sequence, its ordinary generating function is the power series: ‏G(x) = g.
The Rational Zero Theorem
Quadratics       Solve quadratic equations using multiple methods: factoring, graphing, quadratic formula, or square root principle.
Advanced Counting Techniques
IB Math Studies – Topic 2. IB Course Guide Description.
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
Imaginary & Complex Numbers 5-3 English Casbarro Unit 5: Polynomials.
More Key Factors of Polynomials. Recall: From Lesson 4 Standard form (left to right) Factored form The FTA (Fundamental Theorem of Algebra) states that.
Copyright © Cengage Learning. All rights reserved.
Binomial Coefficients, Inclusion-exclusion principle
College Algebra Sixth Edition James Stewart Lothar Redlin Saleem Watson.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
What are two types of Sequences?
1 Section 5.5 Solving Recurrences Any recursively defined function ƒ with domain N that computes numbers is called a recurrence or recurrence relation.
15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections Reading:
1 Chapter 7 Generating functions. 2 Summary Generating functions Recurrences and generating functions A geometry example Exponential generating functions.
Recursion. Quiz int hello(int n) { if (n==0) return 0; else printf(“Hello World %d\n”,n); hello(n-1); } 1.What would the program do if I call hello(10)?
Great Theoretical Ideas in Computer Science.
Precalculus Complex Zeros V. J. Motto. Introduction We have already seen that an nth-degree polynomial can have at most n real zeros. In the complex number.
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
Chapter 9 Polynomial Functions
Real Zeros of Polynomial Functions
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Infinite Sequences and Series 8. Taylor and Maclaurin Series 8.7.
CompSci 102 Discrete Math for Computer Science January 31, 2012 Prof. Rodger Slides modified from Rosen AB a b c d x y z.
after UCI ICS/Math 6A, Summer AdvancedCounting -1 Recurrence Relations (RRs) A “Recurrence Relation”
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
3.4 Zeros of Polynomial Functions Obj: Find x-intercepts of a polynomial Review of zeros A ZERO is an X-INTERCEPT Multiple Zeros the zeros are x = 5 (mult.
Introduction Synthetic division, along with your knowledge of end behavior and turning points, can be used to identify the x-intercepts of a polynomial.
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
Advanced Engineering Mathematics, 7 th Edition Peter V. O’Neil © 2012 Cengage Learning Engineering. All Rights Reserved. CHAPTER 4 Series Solutions.
RECURRENCE Sequence Recursively defined sequence
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
Warm Up Write down objective and homework in agenda Lay out homework (None) Homework (Recursive worksheet) Get a Calculator!!!
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Copyright © Cengage Learning. All rights reserved.
End Behavior.
Chapter 4 Quadratic Equations
Generating Functions II
Math NS FUNCTIONS QUADRATIC.
Copyright © Cengage Learning. All rights reserved.
Great Theoretical Ideas in Computer Science
6.4 Factoring and Solving Polynomial Equations
5.1 Power Series Method Section 5.1 p1.
COUNTING AND PROBABILITY
Quadratic Equations and Functions
More Nonlinear Functions and Equations
5.6 Complex Zeros; Fundamental Theorem of Algebra
Presentation transcript:

Generating Functions and Counting Trees

Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve recurrences 5.Catalan number 6.Counting Spanning Trees

Generating Functions a sequence of numbersa function a polynomial Through this mapping, we can apply our techniques for manipulating functions. 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve recurrences

Ordinary Generating Functions Given a sequence the ordinary generating function is: We use a double sided arrow to indicate the correspondence.

Simple Examples The pattern here is simple: the i-th term in the sequence (indexing from 0) is the coefficient of x i in the generating function. What is the generating function for ?

Geometric Series What is the closed form expression of G n ? G n  xG n =1 …… + ……

More Examples These are all closed form generating functions.

Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve recurrences 5.Catalan number 6.Counting Spanning Trees

Operations on Generating Functions manipulations on sequencesmanipulations on functions There are a few basic operations we’ll learn. 1.Scaling 2.Addition 3.Right shift 4.Differentiation 5.Product We can use these operations to get new sequences from known sequences, and new generating functions from known generating functions.

Scaling Multiplying a generating function by a constant => scales every term in the associated sequence by the same constant. Multiply the generating function by 2 gives which generates the sequence:

Addition Adding generating functions corresponds to adding sequences term by term. The same result as in the previous slide.

Right Shift How to generate the sequence ? k zeros Adding k zeros  multiplying x k on the generating function.

Differentiation How to generate the sequence ? The generating function is How to obtain a closed form of this function? We found a generating function for the sequence of positive integers!

More Differentiation How to generate the sequence ? Nice idea. But not what we want.

More Differentiation How to generate the sequence ?

Product What is the sequence corresponds to the polynomial C(x) = A(x)B(x)?

Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve recurrences 5.Catalan number 6.Counting Spanning Trees

Counting with Generating Functions General strategy: coefficient of x n = number of ways to choose n items. A simple example: the coefficient of x n in (1 + x) k is the number of ways to choose n distinct items from a set of size k.

Convolution Rule Let A(x) be the generating function for selecting items from set A. Let B(x) be the generating function for selecting items from set B. If A and B are disjoint, then the generating function for selecting items from the union A U B is the product A(x) · B(x).

Choosing Subsets Choose n items from k distinct elements {a1, a2, …, ak} How many ways to choose from single element set {a1}? There is one way to choose 0 item, one way to choose 1 element. So the generating function for {a1} is (1+x) So the generating function for {a2} is (1+x) …………… By convolution rule, the generating function for choosing items in a k-element set {a1,a2,…,ak} is:

Choosing Doughnuts How many ways can we select n doughnuts with k varieties? Suppose there is only chocolate doughnuts. How many ways can we select n doughnuts? Well there is only one way to choose zero, one, two, three, ……, chocolate doughnuts. So the generating function for choosing chocolate doughnuts is: By convolution rule: The generating function for choosing doughnuts with k varieties is:

By convolution rule: The generating function for choosing doughnuts with k varieties is: Choosing Doughnuts Now what? How do we obtain the answer? Taylor’s Theorem where f (n) (x) is the n-th derivative of f(x).

Taylor’s Theorem

Choosing Doughnuts The generating function for choosing doughnuts with k varieties is: ……

Choosing Doughnuts The generating function for choosing doughnuts with k varieties is: The number of ways to choose n doughnuts with k varieties is: This is what we get before. Now there is a general method to derive it.

Choosing Fruits This is an “impossible” counting problem… How many ways can we fill a bag with n fruits with the following constraints? The number of apples must be even. The number of bananas must be a multiple of 5. There can be at most four oranges. There can be at most one pear. For example, there are 7 ways to form a bag with 6 fruits

Choosing Fruits The number of apples must be even. The number of bananas must be a multiple of 5. There can be at most four oranges. There can be at most one pear. GF for apples: GF for bananas: GF for oranges: GF for pears: GF for fruits: By convolution rule

Choosing Fruits Generating function for fruits: How many ways can we fill a bag with n fruits with the following constraints? The answer is exactly n+1! We solve an impossible counting problem in a routine way…

Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve recurrences 5.Catalan number 6.Counting Spanning Trees

Solving Recurrences with Generating Functions The Rabbit Population A mature boy/girl rabbit pair reproduces every month. Rabbits mature after one month. w n ::= # newborn pairs after n months r n ::= # reproducing pairs after n months Start with a newborn pair: w 0 =1, r 0 = 0

w n ::= # newborn pairs after n months r n ::= # reproducing pairs after n months r 1 = 1 r n = r n-1 + w n-1 w n = r n-1 so r n = r n-1 + r n-2 It was Fibonacci who was studying rabbit population growth. Rabbit Populations How many rabbits after n months?

Fibonacci Sequence The Fibonacci sequence we want to analyze is: Define a generating function for this sequence: Remember First we want to obtain a closed form for R(x)

R(x)::= r 0 +r 1 x+r 2 x 2 +r 3 x 3 +… -xR(x) = - r 0 x-r 1 x 2 -r 2 x 3 -… -x 2 R(x) = -r 0 x 2 -r 1 x 3 -… 0 Remember Generating Function for Rabbits

R(x)::= r 0 +r 1 x+r 2 x 2 +r 3 x 3 +… -xR(x) = - r 0 x-r 1 x 2 -r 2 x 3 -… -x 2 R(x) = -r 0 x 2 -r 1 x 3 -… 0 0 …

Generating Function for Rabbits R(x)::= r 0 +r 1 x -xR(x) = - r 0 x -x 2 R(x) = R(x)-xR(x)-x 2 R(x) = r 0 +r 1 x-r 0 x = x

Closed Form for R(x) What is the closed form of r n ? So r n = coefficient of x n in R(x)

Closed Form for Coefficients So r n = coefficient of x n in R(x)

Move 1,2 (n)::= Move 1,3 (n-1); big disk 1  2; Move 3,2 (n-1) Tower of Hanoi

s n ::=# steps by Move 1,2 (n) s n = 2s n s 0 = 0 Generating Function The sequence we want to analyze is: Define a generating function for this sequence: First we want to obtain a closed form for S(x)

S(x)::= s 0 + s 1 x+ s 2 x 2 + s 3 x 3 +… -2xS(x)= -2s 0 x-2s 1 x 2 -2s 2 x 3 -… -x/(1-x)= -1 ¢ x - 1 ¢ x ¢ x 3 -… 0 00 … Generating Function s n = 2s n-1 + 1

S(x) - 2xS(x) - x/(1-x) = s 0 = 0 Closed Form for S(x) What is the closed form of s n ? so s n = 2 n - 1

Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve recurrences 5.Catalan number 6.Counting Spanning Trees

Catalan Number Catalan number can be defined recursively by We are going to show this is equal to

Catalan Number Consider the generating function r(x) = r 0 + r 1 x + r 2 x 2 + … Recall that How to generate the right hand side? This is just the convolution rule! r 0 + r 1 x + r 2 x 2 + … = 1 + x(r 0 + r 1 x + r 2 x 2 + … )(r 0 + r 1 x + r 2 x 2 + … ) Notice that by the recursive formula, LHS = RHS!

Catalan Number r 0 + r 1 x + r 2 x 2 + … = 1 + x(r 0 + r 1 x + r 2 x 2 + … )(r 0 + r 1 x + r 2 x 2 + … ) Let R(x) = r 0 + r 1 x + r 2 x 2 + … Then the above equation implies that R(x) = 1 + x(R(x)) 2 Solving the quadratic equation x(R(x)) 2 - R(x) + 1 = 0 We get R(x) =

Catalan Number We get R(x) = We know that when x tends to 0, then R(x) should tend to r 0 = 1. So we must have R(x) = Now it remains to calculate the coefficients of this polynomial. Note that

Catalan Number Therefore R(x) = Note that So r n =

Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve recurrences 5.Catalan number 6.Counting Spanning Trees

Counting Spanning Trees (Optional) A numbered tree is a tree whose vertex set is {1, 2,..., n} for some n >= 2. Given a complete graph of n vertices, how many spanning trees are there?

A numbered tree is a tree whose vertex set is {1, 2,..., n} for some n >= 2. Given a complete graph of n vertices, how many spanning trees are there? A ::= all the spanning trees of a complete graph of n vertices B::= all sequences of n-2 integers from 1 to n There is a bijective function between A and B !!! Counting Spanning Trees (Optional)

A ::= all the spanning trees of a complete graph of n vertices B::= all sequences of n-2 integers from 1 to n How to map a spanning tree to a sequence? 1.If n = 2, stop—the code is the empty sequence. 2.Otherwise, find the largest numbered leaf v. 3.Write down the only neighbour of v. 4.Delete v, and continue the process on the resulting smaller tree.

1.If n = 2, stop—the code is the empty sequence. 2.Otherwise, find the largest numbered leaf v. 3.Write down the only neighbour of v. 4.Delete v, and continue the process on the resulting smaller tree. Counting Spanning Trees (Optional) Tree Code 43 2

1.If n = 2, stop—the code is the empty sequence. 2.Otherwise, find the largest numbered leaf v. 3.Write down the only neighbour of v. 4.Delete v, and continue the process on the resulting smaller tree. Counting Spanning Trees (Optional) Tree Code One tree maps to one code.

How to map a sequence back to a tree? Counting Spanning Trees (Optional) Code Key observation: A number does not appear is a leaf! Tree One code is mapped by one tree.