CSE 2 Mathematics for Algorithm ad System Aalysis Summer, 2005 Outlie What a geeratig fuctio is How to create a geeratig fuctio to model a problem Fidig the desired coefficiet Partitios Expoetial geeratig fuctios Day 8 Geeratig Fuctios Istructor: Neil Rhodes 2 (Ordiary Geeratig Fuctios A differet way to solve problems ivolvig selectio ad arragemet problems with repetitio Ca easily support special costraits ot easy to do otherwise Fid the umber of ways to distribute 70 idetical objects ito 9 boxes with a odd umber betwee 3 ad 7 i the first box, a eve umber betwee 4 ad 20 i the secod box, ad at most 3 i the other boxes. Idea Create a geeratig fuctio g(x which models the problem of selectig r objects. The coefficiet of x r i g(x couts the umber of ways to select r objects g(x = a0 + ax + a2x 2 +...arx r +... + ax g(x = (+x models the umber of ways to select r objects from objects g(x = ( + x = x 0 + 0 x + + x r + + r x Let s look at the coefficiets of x 5 i (+x+x 2 4 Ways to create x 5 : x 0 x 2 x 2 x x x x x 2 etc. I geeral, x e x e 2 x e 3 x e 4 where 0 e, e2, e3, e4 2 Ca be looked at as the umber of iteger solutios to: e + e2 + e3 + e4 = 5 (where 0 e, e2, e3, e4 2 Which ca also be looked at as the umber of ways to place 5 balls i four boxes with at most 2 balls i each box Which ca also be looked at as the umber of ways to select 5 objects from a collectio of 4 differet types of objects (with two idetical objects of each type. g(x = (+x+x 2 4 is a geeratig fuctio for the above problems Actually, g(x is a geeratig fuctio for the problem with ay umber, r, of {balls, objects}, ot just 5 We always write a geeral geeratig fuctio for ay r 3 4
Fid a geeratig fuctio for ar, the umber of ways to select r balls from a pile of three gree, three white, three blue, ad three gold balls Same as umber of iteger solutios to: Fid a geeratig fuctio to model coutig all selectios of six objects chose from three types of objects with: repetitio of up to four objects of each type e + e2 + e3 + e4 = r 0 ei 3 ulimited repetitio 5 6 Fid a geeratig fuctio to model: the umber of ways to distribute r idetical objects ito five boxes with a eve umber of objects ot exceedig 0 i the first two boxes ad betwee 3 ad 5 i the other boxes. Fid a geeratig fuctio for ar, the umber of ways a roll of six distict dice ca show a sum of r if The first three dice are odd ad the secod three eve The ith die does ot show a value of i 7 8
Fidig the Desired Coefficiet Reduce complicated geeratig fuctio to simple fuctio or product of simple fuctios The simple fuctios: x m+ x = + x + x 2 + + x m x = + x + x2 + ( + x = 0 x 0 + x + + ( x m = x m + x r + + r x ( ( x 2m + + ( k 2 k x km + + x m If Product of Geeratig Fuctios f(x = a0 + ax + a2x 2 + g(x = b0 + bx + b2x 2 + ad h(x = f(xg(x the h(x = a0b0 + (a0b + ab0x + (a0b2 + ab + a2b0x 2 + + (a0br + abr- + + ar-b + arb0x r + ( x = + ( + x + ( 2 + 2 x 2 + + ( r + r x r + 9 0 Fid the coefficiet of x 6 i (x 2 + x 3 + x 4 + 5 Rewrite as product of simpler fuctios Fid the umber of ways to collect $5 from 20 distict people if each of the first 9 people ca give $0 or $ ad the 20th perso ca give either $0 or $ or $5 : g(x = Fial simplificatio: 2
How may ways to distribute 25 idetical balls ito seve distict boxes if the first box ca have o more tha 0 balls? How may ways are there to select 25 toys from seve types of toys with betwee two ad six of each type? 3 4 Defiitio Partitios A partitio of r idetical objects divides the group ito a collectio (uordered subsets of various sizes (Or, a group of positive itegers whose sum is r Partitios of 5 We ll be lookig at creatig geeratig fuctios for partitios Warig No easy way to calculate the coefficiets Geeratig Fuctio for Partitio for ar Wat to kow e: how may s e2: how may 2 s e + 2e2 + + rer = r Choose oes: ( + x + x 2 + x 3 + x + = /-x Choose twos ( + x 2 + x 4 + + x 2 + = /(-x 2 Choose threes ( + x 3 + x 6 + + x 3 + = /(-x 3 ad so o. g(x = product of all those = /(-x(-x 2 (-x 3 (-x r 5 6
Fid a geeratig fuctio for the umber of ways to express r as a sum of distict itegers Show with geeratig fuctios that every iteger ca be expressed as a uique sum of distict powers of 2 To show: g(x = + x + x 2 + x 3 + 7 8 Ferrers Diagram Graphically displays a partitio of r dots I a set of rows of decreasig size Show that the umber of partitios of a iteger r as a sum of m positive itegers is equal to the umber of partitios of r as a sum of positive itegers, the largest of which is m Cojugate: Rotate 90 degrees couter-clockwise 9 20
Expoetial Geeratig Fuctios Used to model problems ivolvig arragemets ad distributios of distict objects problem fid umber of differet arragemets of four letters, choosig from a s, b s, ad c s with at least two a s. Solutio Four letter combiatios: {a, a, a, a}: 4/400 {a,a,a,b}:4/30 {a,a,a,c}:4/30 {a,a,b,b}:4/220 {a,a,b,c}:4/2 {a,a,c,c}:4/20 Total is sum, so we wat that sum as the coefficiet of x 4 Ordiary geeratig fuctio ca solve umber of iteger solutios to: e + e2 + e3 = 4 e"2 e2, e3 "0 But, we wat each solutio to above problem to cotribute: (e+e2+e3/ee2e3 Expoetial Geeratig Fuctio Fuctio of form: g(x = a0 + ax + a2x 2 /2 + a3x 3 /3 + + arx r /r + g(x = (x 2 /2 + x 3 /3 + x 4 /4 + (+x+x 2 /2 + x 3 /3 + 2 Coefficiet of xr i g(x is equal to: e+e2+e3=r Coefficiet of xr/r i g(x is equal to: e+e2+e3=r e e 2 e 3 r e e 2 e 3 2 22 Fid the expoetial geeratig fuctio for ar, the umber of differet arragemets of r objects chose from four differet type of objects with each type of object appearig at least 2 ad o more tha 5 times Fid the umber of ways to place r (distict people ito three rooms with at least oe perso i each room 23 24
Useful idetities e x = + x + 2 x 2 Fidig Desired Coefficiets e x = + x + x2 2 + x3 xr + + 3 r + 2 + 3 x 3 3 + + r x r + r 2 (ex + e x = + x2 2 + x4 4 + x6 6 + + Fid the umber of differet r arragemets of objects chose from ulimited supplies of types of objects 2 (ex e x = x + x3 3 + x5 5 + x7 7 + + 25 26 Fid the umber of ways to place 25 people ito 3 rooms with at least oe perso i each room Fid the umber of r-digit quaterary sequeces (digits: 0,, 2, 3 with a eve umber of 0 s ad a odd umber of s 27 28