CS 04 Problem Solvig i Computer Sciece OOC Assigmet 6: Recurreces You may work i pairs or purely idividually for this assigmet. Prepare your aswers to the followig questios i a plai ASCII text file or MS Word documet. Submit your file to the Curator system by the posted deadlie for this assigmet. No late submissios will be accepted. If you work i pairs, list the ames ad email PIDs of both members at the begiig of the file, ad submit your solutio uder oly oe PID. No other formats will be graded. For this assigmet, you may (ad are ecouraged to) work i pairs; if you do so, you must also write your solutios i such a way that it is clear how each member cotributed to derivig the solutio. You will submit your aswers to the Curator System (www.cs.vt.edu/curator) uder the headig OOC06.. [60 poits] Solve each of the followig recurrece relatios: a =, a = 3a + 4 for > 0 a) 0 This is a ohomogeeous liear recurrece; apply the result from the first sectio of the mathematical otes to see that the solutio will be give by: 4 4 4 4 a = 3 + + + + + 3 3 3 3 3 Note: with referece to the otes, the coefficiets of the liear relatioship are costats, 3 ad 4, respectively. Now we eed to simplify this result: a 4 4 4 4 = 3 + + + + + 3 3 3 3 3 = + + + + + 3 3 4 3 4 3 4 3 4 3 ( ) = 3 + 4 3 + 3 + 3 + + Now we eed a basic algebraic idetity: Ad so: for all. a 3 = 3 + 4 3 = 3 + 3 = + 3
CS 04 Problem Solvig i Computer Sciece b =, b =, b = 3b + 4 b for > b) 0 OOC Assigmet 6: Recurreces This is a homogeeous recurrece with costat coefficiets; apply the result from the secod sectio of the mathematical otes. The characteristic equatio is: τ = 3τ + 4 Solvig this, we get the distict roots - ad 4, ad therefore the geeral solutio of the recurrece will be of the form: b = α ( ) + β 4 Now we must fid values for the coefficiets, α ad β, so that the iitial coditios are also satisfied: 0 0 b0 = α ( ) + β 4 = α+ β = so β = α Ad: Substitutig yields: So, the specific solutio is: for all. b α β α β = ( ) + 4 = + 4 = α+ 4( α) = 5α = 3 α = 3 / 5, β = / 5 3 b = ( ) + 4 5 5
CS 04 Problem Solvig i Computer Sciece =, =, = for > c c c c c c) 0 OOC Assigmet 6: Recurreces This is also a homogeeous recurrece with costat coefficiets; apply the result from the secod sectio of the mathematical otes. The characteristic equatio is: τ = τ Solvig this, we get the repeated roots ad, ad therefore the geeral solutio of the recurrece will be of the form: c = α + β = α+ β Now we must fid values for the coefficiets, α ad β, so that the iitial coditios are also satisfied: c = α = ad c = α+ β = + β =, so β = 0 0 So, the specific solutio is: for all. c = 3
CS 04 Problem Solvig i Computer Sciece =, =, = + for > d d d d d d) 0 OOC Assigmet 6: Recurreces This is also a homogeeous recurrece with costat coefficiets; apply the result from the secod sectio of the mathematical otes. The characteristic equatio is: τ = τ + Solvig this, we get the distict roots: ± 4+ 8 τ = = ± 3 Therefore the geeral solutio of the recurrece will be of the form: ( 3) β( 3) d = α + + Now we must fid values for the coefficiets, α ad β, so that the iitial coditios are also satisfied: From this, we see that: d d 0 = α+ β = ( 3) β( 3) ( 3) ( α)( 3) = α + + = α + + = 3α + + 3= 3 3 α = ad β = + 3 3 So, the specific solutio is: for all. d ( 3) ( 3) 3 3+ = + + 3 3 = + + 3 3 ( 3) ( 3) + + 4
CS 04 Problem Solvig i Computer Sciece OOC Assigmet 6: Recurreces. [0 poits] Suppose that you deposit $000 i a savigs accout o Jauary, 03, ad that you deposit a additioal $00 i to the accout o each subsequet Jauary. The bak pays a fixed aual rate of 5%, deposited at the ed of each year. I other words, o December 3 of each year, the bak deposits 5% of the value of the accout o the precedig Jauary (icludig your ew deposit of $00). Fid a recurrece relatio for the value of the accout, P, after years. The solve that recurrece relatio to obtai a o-recursive formula for P. The calculate P 0. We are give directly that P 0 = 000. Ad, from the descriptio of how the accout is updated we see that: P =.05P + 00, for This is a liear recurrece with costat coefficiets, similar to questio a. Applyig the same techique, we obtai: P 00 00 00 00 = (.05) 000+ + + + +.05.05.05 3.05 3 ( ) = 000(.05) + 00.05 +.05 +.05 + +.05 = 000(.05) + 00.05 = 000(.05) + 000(.05) 000 = 3000(.05) 000 From this, we ca calculate that 0 P 0 = 3000(.05) 000= 5959.89. 5
CS 04 Problem Solvig i Computer Sciece OOC Assigmet 6: Recurreces 3. [0 poits] Fid, but do ot solve, a recurrece relatio for the umber of differet ways to make a stack of chips, usig red, white, ad blue chips, such that o two red chips are adjacet i the stack. LetS be the umber of ways form a stack of chips that does ot cotai two adjacet red chips. Trivially, S 0 = 0, ad S = 3 sice there are three ways to form a -chip stack, ad oe of those ca possibly cotai two adjacet red chips: R B W Now, what's S? We ca easily eumerate the 8 possibilities: W B R B W W B R R R W W W B B B Now, is there a patter? Yes. We ca take ay stack of chip ad exted it to a stack of chips by addig either a B or a W chip to the top, without violatig the rules. Ad, we ca take ay stack of 0 chips ad exted it to a stack of chips by addig either of the followig combiatios to the top, without violatig the rules ad without duplicatig ay of the -chip stacks we created i the first maer: R R W B Note that whe we exted a stack of - chips, the result always has a red chip o top, ad whe we exted a stack of - chips, the result ever has a red chip o top. Hece, we ca create two valid stacks of chips from every valid stack of - chips, ad create two valid stacks of chips from every valid stack of - chips, without creatig ay duplicates. So, we get the followig recurrece: S = 0 = 3 = a + a > 6