Loading [MathJax]/extensions/TeX/newcommand.js
COM­P2804: Dis­crete Struc­tures II
\newcommand{\R}{\mathbb{R}}\DeclareMathOperator{\E}{\mathbf{E}}\DeclareMathOperator{\deg}{deg}\newcommand{\N}{\mathbb{N}}

As­sign­ment 1

In this as­sign­ment you may use any of the the­o­rems or lem­mas that we have proved in class (these are all also in the text­book).

Name and Stu­dent Num­ber

Make sure that the PDF file you sub­mit be­gins with your name and stu­dent num­ber on the first page.
Grad­ing (5 marks): An easy five marks just for in­clud­ing their name and stu­dent num­ber at the start of the first page. Zero if they omit it. ▶

Ex­ten­sion of the Erdős–Rényi–Sós Friend­ship The­o­rem

We have seen in Lec­ture 1 (The­o­rem 1.1.1 in the text­book) that if we colour the edges of the com­plete graph K_6 on six ver­tices using two colours, then there will al­ways be a mono­chro­matic tri­an­gle; a cycle of length 3 whose edges all have the same colour. For this ques­tion you will prove some­thing stronger.

A lollipop, a $K_{3,3}$, and a double $3$-cycle

Lol­lipops and com­plete bi­par­tite graphs

A lol­lipop is a graph with 4 ver­tices, 4 edges, and ex­actly one 3-cycle. A K_{3,3} is a graph with 6 ver­tices a_1,a_2,a_3,b_1,b_2,b_3 that con­tains the edge a_ib_j for each i,j\in\{1,2,3\}. Prove that if we colour the edges of the com­plete graph K_6 using two colours, then there will al­ways be a mono­chro­matic lol­lipop or a mono­chro­matic K_{3,3}.

Examples for Question 2.1

Hint: Since we al­ready proved this in class (The­o­rem 1.1.1 in the text­book), you can start by as­sum­ing that the graph con­tains a mono­chro­matic tri­an­gle a_1a_2a_3 and work from there.

So­lu­tion: Using the hint we as­sume that our graph con­tains a mono­chro­matic 3-cycle a_1a_2a_3. With­out loss of gen­er­al­ity, we can as­sume that the edges a_1a_2, a_2a_3, and a_3a_1 are blue. Call the other ver­tices of the graph b_1, b_2, and b_3. If some edge a_ib_j is blue for some i,j\in\{1,2,3\}, then the edges a_1a_2, a_2a_3, a_3a_1, and a_ib_j form a blue lol­lipop and we are done. The only other pos­si­bil­ity is that a_ib_j is red for each i,j\in\{1,2,3\}. But in this case, these 9 edges form a red K_{3,3}. ∎

Grad­ing (5 marks): This is an open-ended ques­tion and there are lots of pos­si­ble proofs. They don't have to use the hint. 5 marks for a com­plete and cor­rect proof. 34 marks for a proof that is mostly cor­rect but might have missed some de­tails. 02 marks for a proof that is in­cor­rect. ▶

Lol­lipops and dou­ble 3-cy­cles

A dou­ble 3-cycle is a graph with 6 ver­tices and 6 edges that form two ver­tex-dis­joint 3-cy­cles. Prove that if we colour the edges of the com­plete graph K_6 using two colours, then there will al­ways be a mono­chro­matic lol­lipop or a mono­chro­matic dou­ble 3-cycle.

Examples for Question 2.2

Hint: This builds on the proof you have found when an­swer­ing the pre­vi­ous ques­tion.

So­lu­tion: In solv­ing the the pre­vi­ous ques­tion we showed that we have a blue lol­lipop on the ver­tices a_1,a_2,a_3,b_j or we have par­ti­tion of the ver­tices into two sets A:=\{a_1,a_2,a_3\} and B:=\{b_1,b_2,b_3\} where a_1a_2a_3 is a blue 3-cycle and the edges be­tween A and B form a red K_{3,3}. In the for­mer case, there is noth­ing more to prove since we have a blue lol­lipop. In the lat­ter case, con­sider the edges of the 3-cycle b_1b_2b_3. There are two cases to con­sider:

Grad­ing (5 marks): This is an open-ended ques­tion and there are lots of pos­si­ble proofs. They don't have to use the hint. 5 marks for a com­plete and cor­rect proof. 34 marks for a proof that is mostly cor­rect but might have missed some de­tails. 02 marks for a proof that is in­cor­rect. ▶

What, no Sticky Fin­gers?

Be­fore at­tempt­ing this ques­tion, make sure that you've watched Lec­ture 2 on the Prod­uct Rule.

Pat is going to the Rolling Stones con­cert. To get him in the mood, he wants to lis­ten to three tracks from the 'Stones three best al­bums:

One song from each, in order

If Pat wants to lis­ten to one song from Album 1, one song from Album 2, and one song from Album 3—in that order—how many op­tions does Pat have?

So­lu­tion: This is an easy ap­pli­ca­tion of the Prod­uct Rule: Pat has 18 choices for the first song, 10 choices for the sec­ond song, and 11 choices for the third song, so the an­swer is 18\times 10\times 11. ∎

Grad­ing (5 marks): 5 for a cor­rect an­swer with a lit­tle ex­pla­na­tion. 4 for a cor­rect an­swer with no ex­pla­na­tion. 0 for an in­cor­rect an­swer. ▶

One song from each, in any order

If Pat wants to lis­ten to one song from Album 1, one song from Album 2, and one song from Album 3—not nec­es­sar­ily in that order—how many op­tions does Pat have? (Lis­ten­ing to the same three songs in dif­fer­ent or­ders counts as two dif­fer­ent op­tions.)

So­lu­tion: Pat can first choose the three songs in one of 18\times 10\times 11 ways and then choose which order to lis­ten to these songs to in one of 3! ways, for a total of 18\times 10\times 11\times 3! pos­si­bil­i­ties. ∎

Grad­ing (5 marks): 5 for a cor­rect an­swer with a lit­tle ex­pla­na­tion. 4 for a cor­rect an­swer with no ex­pla­na­tion. 0 for an in­cor­rect an­swer. There's more than one cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

Three dif­fer­ent songs

If Pat just wants to lis­ten to three dif­fer­ent songs then how many op­tions does he have? (For ex­am­ple, he might lis­ten to three songs from Album 2)

So­lu­tion: There are a total of 18+10+11=39 songs on these three al­bums. Pat has 39 choices for his first song, 38 for his sec­ond, and 37 for his third, for a total of 39\times 38\times 37 op­tions. ∎

Grad­ing (5 marks): 5 for a cor­rect an­swer with a lit­tle ex­pla­na­tion. 4 for a cor­rect an­swer with no ex­pla­na­tion. 0 for an in­cor­rect an­swer. There's more than one cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

Three songs

If Pat just wants to lis­ten to three songs and doesn't mind hear­ing the same song twice, or even three times, then how many op­tions does he have?

So­lu­tion: Pat has 39 op­tions for each of the three songs he lis­tens to, so he has 39\times39\times39=39^3 op­tions in total. ∎

Grad­ing (5 marks): 5 for a cor­rect an­swer with a lit­tle ex­pla­na­tion. 4 for a cor­rect an­swer with no ex­pla­na­tion. 0 for an in­cor­rect an­swer. There's more than one way cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

Kids buy­ing food

Use the Prod­uct Rule (Lec­ture 2) to an­swer the first three of these ques­tions (the last one may need some­thing extra).

A group of n dis­tinct kids k_1,\ldots,k_n ar­rive at the amuse­ment park and head straight for the food court. There are four op­tions for food: one pizza stand, one taco stand, one ham­burger stand, and one cot­ton-candy stand. Since it's only 9am no one is work­ing at these stands, but each kid chooses their favourite food and joins the queue at their cho­sen stand.

For each of the fol­low­ing ques­tions we care about which kids are in which queues and what the order of the kids within each queue is.

Well-be­haved kids

Sup­pose there was only one gate at the amuse­ment park and the kids came through the gate in the order k_1,\ldots,k_n. The kids walk calmly through the park from the gate to the food court and ar­rive in the same order they came through the gate. In this way, their order within each of the four queues matches the order they got off the plane. How many ways are there to as­sign the kids to queues?

So­lu­tion: When each kid ar­rives, they choose one of the 4 queues to choose from, so there are 4^n op­tions for as­sign­ing the kids to queues. ∎

Grad­ing (5 marks): 5 for a cor­rect an­swer with a clear ex­pla­na­tion. 4 for a cor­rect an­swer with an un­clear ex­pla­na­tion. 3 for a cor­rect an­swer with no ex­pla­na­tion. 0-2 for an in­cor­rect an­swer. There's more than one way cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

Well-be­haved im­pa­tient kids

What if, when each kids ar­rives at the food court, they al­ways choose a queue with the fewest num­ber of kids al­ready in it?

So­lu­tion: Here the kids ar­rive in rounds of four kids each. For each round i\in\{0,\ldots,\lfloor n/4\rfloor-1\}, in round i, k_{4i+1} sees four queues each hav­ing i kids in it, so has four choices. Then k_{4i+2} sees three queues with i kids and one queue with i+1 kids so only has three op­tions. Sim­i­larly, k_{4i+3} only has two op­tions, and k_{4i+4} is forced to join the only queue of length i so only has one op­tion. Thus, each group of four kids has 4\times 3\times 2\times 1=4! op­tions. If n is a mul­ti­ple of 4, then the an­swer is (4!)^{n/4}. Oth­er­wise, the last group is a lit­tle bit dif­fer­ent. There are (4!)^{\lfloor n/4\rfloor} op­tions for the first \lfloor n/4\rfloor groups, and the final group has 4!/(4-n\bmod 4)! op­tions. This gives a total of (4!)^{\lfloor n/4\rfloor}\times 4!/(4-n\bmod 4)!

Grad­ing (5 marks): 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion that deals with the case where n is not a mul­ti­ple of 4. 34 for any an­swer of the form (4!)^{n/4}, even if it's not quite cor­rect when n is not di­vis­i­ble by 4. 0-2 for an in­cor­rect an­swer. There's more than one way cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

Lit­tle sav­ages

What if the kids are re­ally hun­gry, all break through the gate to­gether, and race each down to the food court, so they don't nec­es­sar­ily join the queues in the order they ar­rived at the park gates? Since they're rac­ing, they don't have time to choose the short­est queue, so they pick one ar­bi­trar­ily.

Hint: The eas­i­est so­lu­tion to this ques­tion uses The­o­rem 3.9.1 in the text­book, which is not cov­ered until Lec­ture 5.

Quick So­lu­tion: At least one stu­dent has no­ticed that this ques­tion is equiv­a­lent to the prob­lem of plac­ing m books on a set of n shelves (The­o­rem 3.1.4 in the text­book), which can be solved with a clever ap­pli­ca­tion of the Prod­uct Rule. In this case we are plac­ing n kids (books) onto 4 queues (shelves). Stu­dents should be given full marks if they ex­plain this clearly or if they adapt the proof tech­nique used to prove The­o­rem 3.1.4.

So­lu­tion: This is a trick­ier ques­tion, and there are lots of ways to go wrong. The final out­come of this process is an as­sign­ment of kids to each of the four food stalls and four per­mu­ta­tions, one for the kids as­signed to each stall.

The eas­i­est way to count this is to first de­cide how many kids go to each of the queues. The num­ber of ways to do this is the num­ber of non-neg­a­tive in­te­ger so­lu­tions to x_1+x_2+x_3+x_4=n. In one of our Lec­ture 5, we have seen The­o­rem 3.9.1, which shows that the num­ber of so­lu­tions to this equa­tion in \binom{n+3}{3}. Next we choose one of the n! per­mu­ta­tions \pi of the n kids and send the first x_1 kids in \pi to the first food stall in the same order they ap­pear in \pi. Then we send the next x_2 kids in \pi to the sec­ond food stall in the same order they ap­pear in \pi, and so on. It's easy to check that if we change the per­mu­ta­tion or the val­ues of x_1,x_2,x_3,x_4 then we fin­ish with a dif­fer­ent out­come. It's also easy to check that for any out­come we can count the num­ber of kids in each queue to get a so­lu­tion to x_1+\cdots+x_4=n and con­struct the per­mu­ta­tion \pi by con­cate­nat­ing the four queues. So there is a bi­jec­tion be­tween ex­e­cu­tions of this two step pro­ce­dure and pos­si­ble out­comes. So the total num­ber of pos­si­ble out­comes is \binom{n+3}{3}n!. ∎

Grad­ing (5 marks): 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion. 34 for a cor­rect an­swer with an un­clear ex­pla­na­tion. 0-2 for an in­cor­rect an­swer. There's more than one way cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

Stu­dents writ­ing exams

Each of the fol­low­ing ques­tions can be an­swered using the rules (Bi­jec­tion, Com­ple­ment, Sum, or In­clu­sion-Ex­clu­sion) in­tro­duced in Lec­ture 3.

100 COM­P2804 stu­dents c_1,\ldots,c_{100} and 100 dif­fer­ent PSY­C1000 stu­dents p_1,\ldots,p_{100} are writ­ing an exam. (All stu­dents are dis­tinct, even if they are writ­ing the same exam.)

Plenty of desks

Sup­pose the stu­dent are writ­ing their exam in a room with m\ge 200 dis­tinct desks d_1,\ldots,d_m. How many ways are there to as­sign the stu­dents to desks so that each stu­dent gets their own desk?

So­lu­tion: This the num­ber of in­jec­tive func­tions from a set of size 200 onto a set of size m\ge 200. We've seen in Lec­ture 2 (The­o­rem 3.1.3 in the text­book) that the num­ber of such func­tions is m!/(m-200)!. ∎

Grad­ing (5 marks): 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion. 34 for a cor­rect an­swer with an un­clear ex­pla­na­tion. 0-2 for an in­cor­rect an­swer. There's more than one way cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. Many stu­dents will likely use the Prod­uct Rule to solve this di­rectly, with­out ap­peal­ing to The­o­rem 3.1.3. ▶

A short­age of desks, avoid­ing cheat­ing

Sup­pose the exam room has ex­actly 100 dis­tinct stand­ing desks d_1,\ldots,d_{100} and no chairs. How many ways are there to as­sign stu­dents to desks so that each desk has ex­actly one COM­P2804 stu­dent and ex­actly one PSY­C1000 stu­dent?

So­lu­tion: This is an ap­pli­ca­tion of the Prod­uct Rule. First as­sign each COMP stu­dent a dis­tinct desk. There are 100! ways to do this (This is the num­ber of per­mu­ta­tions of stu­dents and is also a spe­cial case of The­o­rem 3.1.3 in the text­book). Then do the same for each PSYC stu­dent. There are 100! ways to do this, so the an­swer is (100!)^2. ∎

Grad­ing (5 marks): 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion. 34 for a cor­rect an­swer with an un­clear ex­pla­na­tion. 0-2 for an in­cor­rect an­swer. There's more than one way cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

A short­age of desks, avoid­ing dis­trac­tions

Like the pre­vi­ous ques­tion, sup­pose the exam room has ex­actly 100 dis­tinct stand­ing desks d_1,\ldots,d_{100} and no chairs. How many ways are there to as­sign the COM­P2804 stu­dents to desks d_1,\ldots,d_{50} and the PSY­CH1000 stu­dents to desks d_{51},\ldots,d_{100} so that each desk has ex­actly two stu­dents at it.

So­lu­tion: We can do the COMP stu­dents first and then the PSYC stu­dents. Start by choos­ing two COMP stu­dents and as­sign them to desk d_1. There are \binom{100}{2} ways to do this. From the re­main­ing 98 COMP stu­dents, choose 2 and as­sign them to desk d_2. There are \binom{98}{2} ways to do this. Con­tinue this way and fin­ish by as­sign­ing the last two COMP stu­dents to desk d_{50}. There are \binom{2}{2} ways to do this. By the Prod­uct Rule, the num­ber of ways to do these 50 steps is \prod_{i=0}^{49}\binom{100-2i}{2} = \left(\frac{100\times 99}{2}\right)\left(\frac{98\times 97}{2}\right)\cdots\left(\frac{4\times 3}{2}\right)\left(\frac{2\times 1}{2}\right) = \frac{100!}{2^{50}} Ex­actly the same ar­gu­ment shows that the num­ber of ways of as­sign­ing PSYC stu­dents to desks d_{51},\ldots,d_{100} is 100!/2^{50}. There­fore, by the Prod­uct Rule, the num­ber of ways of as­sign­ing all stu­dents to desks is (100!/2^{50})^2=(100!)^2/2^{100}. ∎

Grad­ing (5 marks): 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion. 34 for a cor­rect an­swer with an un­clear ex­pla­na­tion or an an­swer that cor­rectly fig­ured out how to as­sign COMP stu­dents to desks d_1,\ldots,d_{50} but for­got to do the sec­ond step of squar­ing the an­swer. 0-2 for an in­cor­rect an­swer. There's more than one way cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

Only three desks

Sup­pose the exam room has three re­ally large ta­bles, t_1,t_2,t_3, each of which can eas­ily ac­com­mo­date 200 stu­dents. How many ways are there to as­sign stu­dents to these ta­bles so that each table is as­signed at least one stu­dent?

So­lu­tion: For this, we will use the Com­ple­ment Rule to first count so­lu­tions in which at least one of the ta­bles is empty. The num­ber of ways of as­sign­ing stu­dents so that they all sit at one table (leav­ing two ta­bles empty) is 3; you just choose the table. The num­ber of ways of as­sign­ing stu­dents so that ex­actly one table is empty can be com­puted using the Prod­uct Rule. First choose one of the 3 ta­bles that will be empty. There are 3 ways to do this. Next, as­sign the stu­dents to the other two ta­bles so that nei­ther of those is empty. The num­ber of ways to do this is 2^n-2 since, of the 2^n pos­si­ble as­sign­ments of stu­dents to ta­bles, the two as­sign­ments that have all stu­dents sit­ting at a sin­gle table are not al­lowed. There­fore, the num­ber of as­sign­ments in which at least one table is empty is 3 + 3\times (2^n-2) = 3\times 2^{n} - 3 Now we use the Com­ple­ment Rule. The num­ber of ways to as­sign stu­dents to ta­bles with­out any re­stric­tions is 3^n. There­fore, the num­ber of ways to as­sign stu­dents to ta­bles in such a way that no table is empty is 3^n - (3\times 2^{n} - 3) = 3^n - 3\times 2^n + 3. ∎

Grad­ing (5 marks): 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion. 34 for a mostly cor­rect an­swer that has a small cal­cu­la­tion error. 0-2 for an in­cor­rect an­swer. There's more than one way cor­rect way to come up with or ex­plain this an­swer, so use your judge­ment. ▶

Prov­ing a bi­no­mial iden­tity

In this ques­tion we're going to prove a bi­no­mial iden­tity using a com­bi­na­to­r­ial proof (also known as count­ing two dif­fer­ent ways) dis­cussed in Lec­ture 4.

Let S be a set of n el­e­ments. Let S_0 be the set of all sub­sets of S that have even size. Let S_1 be the set of all sub­sets of S that have odd size.

Find­ing a bi­jec­tion

De­fine a bi­jec­tion f:S_0\to S_1 be­tween S_0 and S_1. You must prove that what­ever func­tion you de­fine is a one-to-one (in­jec­tive) and onto (sur­jec­tive).

So­lu­tion: Let x be any el­e­ment of S. Con­sider the func­tion f(X) = \begin{cases} X\setminus\{x\} & \text{if $x\in S$} \\ X\cup\{x\} & \text{if $x\not\in S$} \end{cases} No­tice that for any X\in S_0, f(X)\in S_1 since |f(X)|=|X|+1 or |f(X)|=|X|-1. By the same rea­son­ing, for any Y\in S_1, f(Y)\in S_0. Fi­nally, no­tice that f(f(X))=X for any X\subseteq S. There­fore f:S_0\to S_1 is onto be­cause for any Y\in S_1, there is an el­e­ment X=f(Y) in S_0 such that f(X)=Y. Fur­ther­more f:S_0\to S_1 is in­jec­tive be­cause if, for some X_1,X_2\in S_0, f(X_1)=f(X_2) then X_1=f(f(X_1))=f(f(X_2))=X_2. ∎

Grad­ing (5 marks): There are many pos­si­ble bi­jec­tions. 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion which shows that the func­tion is one-to-one (in­jec­tive) and onto (sur­jec­tive). 34 for a mostly cor­rect an­swer that misses one of those steps or is un­clear. 0-2 for an in­cor­rect an­swer. ▶

A bi­no­mial iden­tity

Prove that \sum_{k=0}^n (-1)^k\binom{n}{k} = 0. (You may use the re­sult from the pre­vi­ous ques­tion even if you weren't able to find the bi­jec­tion.)

Quick So­lu­tion: At least one stu­dent has no­ticed that this iden­tity is an easy con­se­quence of New­ton's Bi­no­mial The­o­rem with x=1 and y=-1, since 0 = 0^n = (1+(-1))^n = \sum_{k=0}^{n}1^{n-k}(-1)^k\binom{n}{k} = \sum_{k=0}^{n}(-1)^k\binom{n}{k} \enspace . A stu­dent who gives this so­lu­tion should re­ceive full marks.

So­lu­tion: Since -1^k=1 when k is even and -1^k=-1 when k is odd, we can rewrite \sum_{k=0}^n (-1)^k\binom{n}{k} as \sum_{k=0}^n (-1)^k\binom{n}{k} = \sum_{k=0}^{\lfloor n/2\rfloor} \binom{n}{2k} - \sum_{k=0}^{\lfloor (n-1)/2\rfloor} \binom{n}{2k+1} By the Sum Rule, \sum_{k=0}^{\lfloor n/2\rfloor} \binom{n}{2k} is the num­ber of ways of choos­ing a sub­set of S that con­tains an even num­ber of el­e­ments, so \sum_{k=0}^{\lfloor n/2\rfloor} \binom{n}{2k}=|S_0|. By the same rea­son­ing, \sum_{k=0}^{\lfloor (n-1)/2\rfloor} \binom{n}{2k+1}=|S_1|. By the pre­vi­ous ques­tion, |S_0|=|S_1| by the Bi­jec­tion Rule. There­fore, \sum_{k=0}^n (-1)^k\binom{n}{k} = \sum_{k=0}^{\lfloor n/2\rfloor} \binom{n}{2k} - \sum_{k=0}^{\lfloor (n-1)/2\rfloor} \binom{n}{2k+1} = |S_0|-|S_1| = 0 \enspace .

Grad­ing (5 marks): They just need to re­al­ize that the sum has a neg­a­tive part and a pos­i­tive part, and that these count odd and even-sized sub­sets. With­out re­al­iz­ing that, they're doomed. 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion. 34 for a mostly cor­rect an­swer that is un­clear. 0-2 for an in­cor­rect an­swer. ▶

Mak­ing loot bags

Pro­fes­sor M needs to make 10 loot bags b_1,\ldots,b_{10} for his son's birth­day party. Each loot bag has the name of one of his son's friends on it and Pro­fes­sor M has 80 iden­ti­cal pieces of candy. The candy is not very good so he doesn't want any left­over for him­self. He cares a bit about being fair, but not enough to bother count­ing 8 pieces of can for each bag. It's good enough if each bag con­tains at least 3 pieces of candy. How many ways are there for Pro­fes­sor~M to dis­trib­ute the candy among the loot bags so that each bag has at least three pieces of candy and all 80 pieces of candy is put into the bags.

So­lu­tion: The pro­fes­sor wants to solve the equa­tion \sum_{i=1}^{10} x_i = 80 with in­te­ger val­ued x_i with each x_i\ge 3. De­fine y_i = x_i-3, so that the con­straint x_i\ge 3 is equiv­a­lent to y_i\ge 0. Then this equa­tion be­comes \sum_{i=1}^{10} (y_i+3) = 80, which we can rewrite as \sum_{i=1}^{10} y_i = 50. The num­ber of ways to solve this equa­tion with non-neg­a­tive in­te­gers y_1,\ldots,y_{10} is \binom{50+9}{9}=\binom{59}{9}, by The­o­rem 3.9.1 in the text­book.

A mys­te­ri­ous func­tion

Con­sider the fol­low­ing Python func­tion:

def f(x,y):
    if y == 0: return 1
    s = 0
    while x > y:
        s = s + f(x-1, y-1)
        x = x - 1
    return s + 1

If x and y are two non-neg­a­tive in­te­gers with x\ge y, what does f(x,y) re­turn? Ex­plain your an­swer using one of the the­o­rems dis­cussed in class.

So­lu­tion: This func­tion re­turns \binom{x}{y}. The base case \binom{x}{0}=1 is han­dled by the first line. If x=y then the while loop doesn't ex­e­cute and the func­tion re­turns 1, cor­rectly, since \binom{x}{x}=1. Oth­er­wise, the func­tion com­putes f(x-1,y-1) (re­cur­sively) and then re­duces x by 1 and re­turns to the top of the loop so that the re­main­der of the code com­putes f(x-1,y). This im­ple­ments Pas­cal's Iden­tity \binom{x}{y} = \binom{x-1}{y-1}+\binom{x-1}{y} (The­o­rem 3.7.2 in the text­book).

Grad­ing (5 marks): There's no ex­cuse for not fig­ur­ing out that f(x,y)=\binom{x}{y} for x\ge y\ge 0. They can run the code. 5 for a cor­rect and com­plete an­swer with a clear ex­pla­na­tion that ref­er­ences Pas­cal's For­mula. 34 for a mostly cor­rect an­swer that is un­clear. 0-2 for an in­cor­rect an­swer. ▶