COMP 2804 Solutios Assiget 1 Questio 1: O the first page of your assiget, write your ae ad studet uber Solutio: Nae: Jaes Bod Studet uber: 007 Questio 2: I Tic-Tac-Toe, we are give a 3 3 grid, cosistig of uared cells Two players, Xavier ad Olivia, tae turs arig the cells of this grid Whe it is Xavier s tur, he chooses a uared cell ad ars it with the letter X Siilarly, whe it is Olivia s tur, she chooses a uared cell ad ars it with the letter O The first tur is by Xavier The players cotiue aig turs util all cells have bee ared Below, you see a exaple of a copletely ared grid O X X O X X X O O What is the uber of copletely ared grids? Justify your aswer What is the uber of differet ways (ie, ordered sequeces) i which the grid ca be copletely ared, whe followig the rules give above? Justify your aswer Solutio: For the first part, observe that the grid cosists of ie cells, ad that a copletely ared grid cotais five X s ad four O s To copletely ar a iitially epty grid, we have to choose five cells (out of ie); i the chose cells, we write X, whereas we write O i the reaiig four cells Therefore, the uber of copletely ared grids is equal to the uber of ways to choose five eleets out of ie Thus, the aswer is ( ) 9 5 For the secod part, we uber the cells arbitrarily 1, 2, 3,, 9 Ay sequece to ar all cells is othig but a perutatio of these ie itegers For exaple, the perutatio idicates the followig sequece of oves: Xavier writes X i cell 7, 7, 3, 4, 1, 9, 6, 8, 2, 5 1
Olivia writes O i cell 3, Xavier writes X i cell 4, Olivia writes O i cell 1, Xavier writes X i cell 9, Olivia writes O i cell 6, Xavier writes X i cell 8, Olivia writes X i cell 2, Xavier writes X i cell 5 Thus the aswer is 9! Questio 3: A password is a strig of 100 characters, where each character is a digit or a lowercase letter A password is called valid if it does ot start with abc, ad it does ot ed with xyz, ad it does ot start with 3456 Deterie the uber of valid passwords Justify your aswer Solutio: We defie the followig sets: U is the set of all strigs of 100 characters, where each character is a digit or a lowercase letter A is the set of all strigs i U that start with abc B is the set of all strigs i U that ed with xyz C is the set of all strigs i U that start with 3456 The questio ass for the value of A B C Usig De Morga ad the Copleet Rule, we get A B C = A B C = U A B C 2
To deterie the size of U, we observe that each strig i U cosists of 100 characters, ad for each character, there are 10 + 26 = 36 choices By the Product Rule, we have U = 36 100 To deterie the size of A, we observe that each strig i U cosists of 100 characters The first three characters are fixed, whereas for each of the reaiig 97 characters, there are 10 + 26 = 36 choices By the Product Rule, we have A = 36 97 By siilar reasoig, we have ad B = 36 97, C = 36 96, A B = 36 94, B C = 36 93 Sice A C = ad A B C =, we have A C = 0 ad A B C = 0 By the Priciple of Iclusio ad Exclusio, we have A B C = A + B + C A B A C B C + A B C We coclude that = 36 97 + 36 97 + 36 96 36 94 0 36 93 0 = 56 36 94 A B C = U A B C = 36 100 56 36 94 = 673 36 94 Questio 4: Let ad be itegers with 0 There are + 1 studets i Carleto s Coputer Sciece progra The Carleto Coputer Sciece Society has a Board of Directors, cosistig of oe presidet ad vice-presidets The presidet caot be vice-presidet Prove that ( ) ( ) + 1 ( + 1) = ( + 1 ), 3
by coutig, i two differet ways, the uber of ways to choose a Board of Directors Solutio: First way: First tas: Choose a presidet; there are + 1 ways to do this Secod tas: Choose vice-presidets Sice the presidet has already bee chose, there are are ( ) ways to do this By the Product Rule, the uber of ways to choose a Board of Directors is equal to Secod way: First tas: Choose vice-presidets; there are ( +1 ( ) ( + 1) (1) ) ways to do this Secod tas: Choose a presidet Sice the vice-presidets have already bee chose, there are are + 1 ways to do this By the Product Rule, the uber of ways to choose a Board of Directors is equal to ( ) + 1 ( + 1 ) (2) The values of (1) ad (2) ust be equal, because both of the cout the uber of ways to choose a Board of Directors Questio 5: Let ad be itegers with 2, ad cosider the set S = {1, 2, 3,, 2} A ordered sequece of eleets of S is called valid if this sequece is strictly icreasig, or this sequece is strictly decreasig, or this sequece cotais oly eve ubers (ad duplicate eleets are allowed) Deterie the uber of valid sequeces Justify your aswer Solutio: We defie the followig sets: A is the set of all ordered sequeces of eleets of S that are strictly icreasig B is the set of all ordered sequeces of eleets of S that are strictly decreasig C is the set of all ordered sequeces of eleets of S that cotai oly eve ubers 4
The questio ass for the value of A B C What is the size of A? Ay sequece of A correspods to a uique subset of S havig size Coversely, ay subset of S havig size correspods to a uique sequece i A It follows that ( ) 2 A = By the sae reasoig, we have B = ( ) 2 What is the size of C? Each sequece i C is a ordered sequece of leth, ad each eleet is a eve eleet of S Sice S cotais ay eve ubers, it follows that that there are choices for each eleet i ay such sequece It follows that C = We observe that A B =, because we assue that 2 This also iplies that A B C = Thus, A B = A B C = 0 What is the size of A C? Ay sequece of A C correspods to a uique subset of {2, 4, 6,, 2} havig size Coversely, ay subset of {2, 4, 6,, 2} havig size correspods to a uique sequece i A C It follows that ( ) A C = By the sae reasoig, we have B C = By the Priciple of Iclusio ad Exclusio, we have ( ) A B C = A + B + C A B A C B C + A B C ( ) ( ) ( ) ( ) 2 2 = + + 0 + 0 (( ) ( )) 2 = 2 + Questio 6: Let,, ad be itegers with 0, ad let S be a set of size Prove that ( )( ) ( )( ) =, 5
by coutig, i two differet ways, the uber of ordered pairs (A, B) with A S, B S, A B, A =, ad B = Solutio: First way: First tas: Choose a subset A of S Sice A has size, there are ( ) ways to do this Secod tas: Choose a subset B of S; this subset has size ad it ust cotai all eleets of A This is the sae as choosig a subset of S \ A (which has size ) of size There are ( ) ways to do this By the Product Rule, the uber of ordered pairs (A, B) with A S, B S, A B, A =, ad B = is equal to ( )( ) (3) Secod way: First tas: Choose a subset B of S Sice B has size, there are ( ) ways to do this Secod tas: Choose a subset A of S; this subset has size ad it ust be a subset of B There are ( ) ways to do this By the Product Rule, the uber of ordered pairs (A, B) with A S, B S, A B, A =, ad B = is equal to ( )( ) (4) The values of (3) ad (4) ust be equal, because both cout the uber of ordered pairs (A, B) with A S, B S, A B, A =, ad B = Questio 7: Let ad be itegers with 0 How ay bitstrigs of legth + 1 have exactly ay 1s? Let be a iteger with 0 What is the uber of bitstrigs of legth + 1 that have exactly ay 1s ad that start with } 1 {{ 1} 0? Use the above two results to prove that =0 ( ) = ( ) + 1 6
Solutio: We have see the aswer to the first part i class: ( ) + 1 For the secod part, we wat to cout bitstrigs havig legth + 1, that have exactly ay 1s, that start with } 1 {{ 1} 0 This eas that the first + 1 positios are fixed, ad of these positios cotai 1, i the last ( + 1) ( + 1) = positios, we have to place ay 1s This eas that we have to cout the bitstrigs of legth havig exactly ay 1s We ow fro class that the aswer is ( ) For the third part, we are goig to cout, i two differet ways, the bitstrigs of legth + 1 that have exactly ay 1s The first way is give by the first part of this questio: ( ) + 1 (5) For the secod way, we observe the followig: Each bitstrig of legth + 1 that has exactly ay 1s is of oe of the followig types: it starts with 0, ie, with } 1 {{ 1} 0 Fro the secod part, the uber of these is equal =0 to ( ) it starts with 10, ie, with } 1 {{ 1} 0 Fro the secod part, the uber of these is equal =1 to ( ) 1 1 7
it starts with 110, ie, with } 1 {{ 1} 0 Fro the secod part, the uber of these is =2 equal to ( ) 2 2 it starts with 1110, ie, with } 1 {{ 1} 0 Fro the secod part, the uber of these is =3 equal to ( ) 3 3 Etc, etc it starts with } 1 {{ 1} 0 Fro the secod part, the uber of these is equal to = ( ) If we add up the uber of bitstrigs of all these types, we see that the uber of bitstrigs of legth + 1 that have exactly ay 1s is equal to ( ) ( ) ( ) ( ) ( ) ( ) 1 2 3 + + + + + = (6) 1 2 3 Sice the values of (5) ad (6) are equal, because both cout the sae bitstrigs, we are doe Questio 8: Let ad be itegers with 0 Use Questios 4, 6, ad 7 to prove that ( ) ) = + 1 + 1 =0 ( =0 Solutio: Usig Questio 6, we get ( ) ( ) ( = ( =0 ) =0 ) I the latter su, the ter ( ) does ot deped o the suatio variable Thus, we ca tae it out of the suatio ad get ( ) ) = ( 1 ( ) ) =0 ( 8 =0
Usig Questio 7, this becoes ( ) ( ) = 1 ( ) + 1 ( =0 ) Fially, usig Questio 4, this becoes ( ) ) = + 1 + 1 =0 Questio 9: I this exercise, we cosider the sequece of itegers ( 3 0, 3 1, 3 2,, 3 1000 Prove that this sequece cotais two distict eleets whose differece is divisible by 1000 That is, prove that there exist two itegers ad with 0 < 1000, such that 3 3 is divisible by 1000 Hit: Cosider each eleet i the sequece odulo 1000 ad use the Pigeohole Priciple Use the first part to prove that this sequece cotais a eleet whose decial represetatio eds with 001 I other words, the last three digits i the decial represetatio are 001 Solutio: For the first part, cosider the sequece 3 0 od 1000, 3 1 od 1000, 3 2 od 1000,, 3 1000 od 1000 Each uber i this sequece is a iteger belogig to the set {0, 1, 2, 3,, 999}; this set has size 1000 Sice the sequece cosists of 1001 ubers, the Pigeohole Priciple tells us that there ust be at least two ubers i the sequece that are equal I other words, there exist two itegers ad with 0 < 1000, such that This eas that ie, 3 3 is divisible by 1000 3 od 1000 = 3 od 1000 (3 3 ) od 1000 = 0, For the secod part: I the first part, we have foud two itegers ad with 0 < 1000, such that 3 3 is divisible by 1000 Observe that 3 3 = 3 ( 3 1 ) 9
Thus, sice 3 3 is divisible by 1000, 3 ( 3 1 ) is divisible by 1000 Sice the greatest coo divisor of 3 ad 1000 is equal to 1, the uber 3 1 is divisible by 1000 Thus, there is a positive iteger such that 3 1 = 1000, ie, 3 = 1 + 1000 This eas that the last three digits i the decial represetatio of 3 are 001 10