CSE 353 Discrete Computatioal Structures Sprig 08 Sequeces, Mathematical Iductio, ad Recursio (Chapter 5, Epp) Note: some course slides adopted from publisher-provided material
Overview May mathematical processes have repeated patters. These processes ca be characterized by sequeces, ad verified usig mathematical iductio. Sprig 08 CSE 353 Discrete Computatioal Structures 3 Outlie 5. Sequeces 5. Mathematical Iductio I 5.6 Defiig Sequeces Recursively 5.7 Solvig Recurrece Relatios by Iteratio Sprig 08 CSE 353 Discrete Computatioal Structures 4
Sequeces Imagie that a perso decides to cout his acestors. He has two parets, four gradparets, eight great- gradparets, ad so forth, These umbers ca be writte i a row as, 4, 8, 6, 3, 64, 8, The symbol is called a ellipsis. It is shorthad for ad so forth. To express the patter of the umbers, suppose that each is labeled by a iteger givig its positio i the row. (idex) Sprig 08 CSE 353 Discrete Computatioal Structures 5 Sequeces We ote that each successive umber doubles i size, or is a power of For a geeral value of, let A be the umber of acestors i the th geeratio bac. We ote that A, A 4, A 3 8 3, A 4 6 4. I geeral, we ote that the patter suggests that A This patter is called a sequece Sprig 08 CSE 353 Discrete Computatioal Structures 6
Sequece Formal Defiitio A sequece is a fuctio whose domai is either: All the itegers betwee two give itegers, or All the itegers greater tha or equal to a give iteger Sprig 08 CSE 353 Discrete Computatioal Structures 7 Sequece Notatio We typically represet a sequece as a set of elemets writte i a row. I the sequece deoted where each idividual elemet a (read a sub ) is called a term.. The i a is called a subscript or idex,. m (which may be ay iteger) is the subscript of the iitial term, 3. (which must be greater tha or equal to m) is the subscript of the fial term. Sprig 08 CSE 353 Discrete Computatioal Structures 8
Sequece Notatio deotes a ifiite sequece. A explicit formula or geeral formula for a sequece is a rule that shows how the values of a deped o. Sprig 08 CSE 353 Discrete Computatioal Structures 9 Example Assume we have the followig sequece of umbers: 3, 5, 7, 9,, 3, 5,.. Ca we determie a geeral term of the sequece a? Note: a 3, a 5,.. These are odd itegers: recall the defiitio of odd itegers: "a iteger m is odd if m + for ay iteger " Sprig 08 CSE 353 Discrete Computatioal Structures 0
Example If, a 3 + * + 3 a 5; *+ 5 a 3 7; *3+ 7 So it appears that a + for all itegers Sprig 08 CSE 353 Discrete Computatioal Structures Example 5.- Write the first four terms of the followig sequece: a," itegers 0 + ³ Sprig 08 CSE 353 Discrete Computatioal Structures
Summatio Notatio For our previous example, a +, what is the sum of all a for to 3? First 3 terms are: 3, 5, 7 Sum of these terms is 3+5+7 5 How about for to Sum 3 + 5 + 7 +. + a A shorthad otatio is to use summatio otatio Sprig 08 CSE 353 Discrete Computatioal Structures 3 Summatio Notatio Give itegers m ad where m, the symbol å m a is the sum of all the terms a m, a m+,., a is the idex of the summatio m is the lower limit of the summatio is the upper limit of the summatio Sprig 08 CSE 353 Discrete Computatioal Structures 4
Summatio Notatio We ca also express the summatio as å am + am + +! m a + a where the right-had side (RHS) of the equatio is called the expaded form of the sum Sprig 08 CSE 353 Discrete Computatioal Structures 5 Summatio Notatio for our Example Revisitig our previous example, a +, what is the sum of all a for to? For our example, the summatio otatio is: å m å( + ) a Sprig 08 CSE 353 Discrete Computatioal Structures 6
Example 5.- Compute the followig summatio: 5 ( ) å + Sprig 08 CSE 353 Discrete Computatioal Structures 7 Applicatio to C/C++/Java Code to compute sum? it sum, ; 5 ( ) å + sum 0; for (; <5; ++) sum sum + ( + ); Sprig 08 CSE 353 Discrete Computatioal Structures 8
å Summatio Notatio for our Example Expaded Form The expaded form of the summatio otatio for our example is the followig: ( + ) (() + ) + (() + ) + ((3) + ) +! + ( + ) 3+ 5 + 7 +! + ( + ) Sprig 08 CSE 353 Discrete Computatioal Structures 9 Separatig Off the Fial Term We ca also write our sum as the followig: å - ( ) ( + ) + ( + ) + å This is ow as separatig off the fial term. HINT: THIS MAY BE USEFUL LATER! Sprig 08 CSE 353 Discrete Computatioal Structures 0
Product Notatio Summatio adds terms of a sequece To multiply terms of a sequece, use product otatio Sprig 08 CSE 353 Discrete Computatioal Structures Product Notatio Give itegers m ad where m, the symbol Õ m a is the product of all the terms a m, a m+,., a is the idex of the product m is the lower limit of the product is the upper limit of the product Sprig 08 CSE 353 Discrete Computatioal Structures
Product Notatio We ca also express the product as Õ am am +! m a a where the right-had side (RHS) of the equatio is called the expaded form of the product Sprig 08 CSE 353 Discrete Computatioal Structures 3 Examples Let m, 3, a +. The we have: 3 å ( + ) 3+ 5 + 7 5 3 Õ( + ) (() + ) + (() + ) + ((3) + ) 3 5 7 05 Sprig 08 CSE 353 Discrete Computatioal Structures 4
Example 5.-3 Compute the followig product: 4 Õ Sprig 08 CSE 353 Discrete Computatioal Structures 5 Applicatio to C/C++/Java Code to compute product? it product, ; 4 Õ product ; for (; <4; ++) product product * ( * ); Sprig 08 CSE 353 Discrete Computatioal Structures 6
Properties of Summatios ad Products Sprig 08 CSE 353 Discrete Computatioal Structures 7 Assume that we have the followig sequeces of real umbers:. a m, a m+,..,a. b m, b m+,..,b Also assume that we have a real umber c The, we have the followig equatios that hold for ay iteger m Properties of Summatios ad Products Sprig 08 CSE 353 Discrete Computatioal Structures 8 ( ) Õ( ) Õ Õ å å å å å ø ö ç è æ ø ö ç è æ + + m m m m m m m m b a b a a c a c b a b a
Chage of Variable Suppose we have the followig two summatios: 3 å 3 åi i + + + 3 + 3 These two summatios are clearly the same, thus 3 å 3 åi i Sprig 08 CSE 353 Discrete Computatioal Structures 9 Chage of Variable If we ow that there are differet ways to express the same summatio, we may be able to simplify a give summatio usig chage of variable. For example, assume that we are give the followig summatio: 3 ( ) å - Sprig 08 CSE 353 Discrete Computatioal Structures 30
Chage of Variable Ca we simplify with chage of variable? What if we let j -? What are ew upper ad lower limits of summatio? For : j - - 0 For 3: j - 3-3 ( ) å - Sprig 08 CSE 353 Discrete Computatioal Structures 3 This becomes: Chage of Variable 3 ( ) å å - j 0 j Sprig 08 CSE 353 Discrete Computatioal Structures 3
Factorials Assume we have the product of cosecutive itegers from to, or Õ j j 3! ( -) This may loo familiar this is also the factorial of Õ j j! Zero factorial (0!) is defied to be : 0! Sprig 08 CSE 353 Discrete Computatioal Structures 33 Factorials Note that this umber ca become very large very quicly: 5! 5x4x3xx 0 6! 6x5x4x3xx 70 Thus, we ca also use a recursive defiitio for factorial (for all 0): ì! í î ( - ) Thus, 6! 6x5! 6 x 0 70! if if 0 ³ Sprig 08 CSE 353 Discrete Computatioal Structures 34
Factorials We ca use the recursive defiitio of factorials to simplify certai factorial expressios: 6! 6 5! 6 5! 5! 6! 6 5 4!!4!!4! 6 5 30 5 Sprig 08 CSE 353 Discrete Computatioal Structures 35 Outlie 5. Sequeces 5. Mathematical Iductio I 5.6 Defiig Sequeces Recursively 5.7 Solvig Recurrece Relatios by Iteratio Sprig 08 CSE 353 Discrete Computatioal Structures 36
Mathematical Iductio Type of direct proof method Used to chec cojectures about the outcomes of processes that occur repeatedly ad accordig to defiite patters (i.e., sequeces) Geeral approach: prove that a property defied for itegers is true for all values of that are greater tha or equal to some iitial iteger Sprig 08 CSE 353 Discrete Computatioal Structures 37 Priciple of Mathematical Iductio Let P() property defied for itegers Also let a fixed iteger Suppose the followig statemets are true. P(a) is true. itegers a, if P() is true the P(+) is true The the followig statemet is also true itegers a, P() Sprig 08 CSE 353 Discrete Computatioal Structures 38
Method of Proof by Mathematical Iductio Cosider a statemet of the form: itegers a, a property P() is true To prove this statemet, perform the followig steps. Basis Step. Iductive Step Sprig 08 CSE 353 Discrete Computatioal Structures 39 Proof by Mathematical Iductio Basis Step Origial statemet form is itegers a, a property P() is true Basis Step: Show that P(a) is true Show that the property holds for the first iteger i the sequece (a) If we ca prove this step, the proceed to the Iductive Step Sprig 08 CSE 353 Discrete Computatioal Structures 40
Proof by Mathematical Iductio Iductive Step Show that itegers a, if P() is true the P(+) is true How? Suppose that P() is true, where is ay particular but arbitrarily chose iteger with a (this suppositio is called the iductive hypothesis) The, show that P(+) is true Sprig 08 CSE 353 Discrete Computatioal Structures 4 Mathematical Iductio Example Show that the followig is true: Proof (by mathematical iductio): Let the property P() be the equatio { Left-had side (LHS) of equatio { Right-had side (RHS) of equatio Sprig 08 CSE 353 Discrete Computatioal Structures 4
Mathematical Iductio Example BASIS STEP: Show that P() is true: To establish P(), we must show that LHS ; RHS is For P(), LHS RHS, so the BASIS STEP has bee proved Sprig 08 CSE 353 Discrete Computatioal Structures 43 Mathematical Iductio Example INDUCTIVE STEP: Show that for all itegers, if P() is true the P( + ) is also true: [Suppose that P() is true for a particular but arbitrarily chose iteger ³.That is:] Suppose that is ay iteger with ³ such that [We must show that P( + ) is true. That is:] We must show that Sprig 08 CSE 353 Discrete Computatioal Structures 44
Mathematical Iductio Example Ca also be writte as: [We will show that the left-had side ad the right-had side of P( + ) are equal to the same quatity ad thus are equal to each other.] Sprig 08 CSE 353 Discrete Computatioal Structures 45 Mathematical Iductio Example The left-had side (LHS) of P( + ) is: + + 3 +! + ( + ) + + 3 +! + + ( + ) Note that we have separated off the fial term why? Recall our iductive hypothesis we assumed the followig was true: Thus, we ca rewrite our LHS equatio as ( ) é + ù [ + + 3 +! + ] + ( + ) ê + + ë ú û ( ) Sprig 08 CSE 353 Discrete Computatioal Structures 46
Mathematical Iductio Example We ca simplify our LHS equatio as follows: ( ) é + ê ë ù ú + û ( + ) + + + ( + ) + 3 + ( + ) + Sprig 08 CSE 353 Discrete Computatioal Structures 47 Mathematical Iductio Example Now, develop our RHS of P(+). Recall that origial P(+) was: So, RHS is: ( )( + ) + + 3 + But ote that this is the same as for our LHS i the previous slide! Sprig 08 CSE 353 Discrete Computatioal Structures 48
Mathematical Iductio Example Thus the two sides of P( + ) are equal to the same quatity ad so they are equal to each other. Therefore the equatio P( + ) is true [as was to be show]. [Sice we have proved both the basis step ad the iductive step, we coclude that the theorem is true.] Sprig 08 CSE 353 Discrete Computatioal Structures 49 Example 5.- Usig Proof by Mathematical Iductio, show that the followig is true: For all itegers, + 3 ( + )( ) + + +! + 6 Sprig 08 CSE 353 Discrete Computatioal Structures 50
Closed Form of a Equatio Recall our earlier example sum: The RHS of the equatio is called the closed form (the LHS is called the expaded form) Why is this useful? If we wat to ow the value of a sum for a give, the closed form is easier to compute Sprig 08 CSE 353 Discrete Computatioal Structures 5 Geometric Sequeces I a geometric sequece, each term is obtaied from the precedig oe by multiplyig by a costat factor. If the first term is ad the costat factor is r, the the sequece is, r, r, r 3,..., r,.... The sum of the first terms of this sequece is give by the formula for all itegers ³ 0 ad real umbers r ot equal to. Sprig 08 CSE 353 Discrete Computatioal Structures 5
Outlie 5. Sequeces 5. Mathematical Iductio I 5.6 Defiig Sequeces Recursively 5.7 Solvig Recurrece Relatios by Iteratio Sprig 08 CSE 353 Discrete Computatioal Structures 53 Defiig Sequeces Recursively We have see that there are various ways to defie a sequece Oe iformal way is to write the first few terms with the expectatio that the geeral patter will be obvious. We might say, for istace, cosider the sequece, 4,.... Ufortuately, misuderstadigs ca occur whe this approach is used. The ext term of the sequece could be 6 if we mea a sequece of eve itegers, or it could be 8 if we mea the sequece of powers of. Sprig 08 CSE 353 Discrete Computatioal Structures 54
Defiig Sequeces Recursively A secod way to defie a sequece is to give a explicit formula for its th term. For example, we ca defie a sequece of eve itegers a, a. as a, " itegers ³ Sprig 08 CSE 353 Discrete Computatioal Structures 55 Defiig Sequeces Recursively We ca defie the sequece of powers of as a," itegers ³ The advatage of defiig a sequece by such a explicit formula is that each term of the sequece is uiquely determied ad ca be computed i a fixed, fiite umber of steps, by substitutio. Sprig 08 CSE 353 Discrete Computatioal Structures 56
Defiig Sequeces Recursively A third way to defie a sequece is to use recursio. This requires givig both a equatio, called a recurrece relatio, that defies each later term i the sequece by referece to earlier terms ad also oe or more iitial values for the sequece. Sprig 08 CSE 353 Discrete Computatioal Structures 57 Recurrece Relatio Assume we have a sequece a 0, a, a, A recurrece relatio for this sequece is a formula that relates each term a to predecessor terms (a -, a -, ) The iitial coditios for this relatio specify iitial values of the sequece (a 0, a, ) Sprig 08 CSE 353 Discrete Computatioal Structures 58
Example We have the followig recurrece relatio: a a +, for all itegers ³ - We are give the iitial coditio a What are the first 4 terms i this sequece? We are give a Term (): a a + () + 4 ( 3): a 3 a + 3 (4) + 3 8 + 3 ( 4): a 4 a 3 + 4 () + 4 + 4 6 Sprig 08 CSE 353 Discrete Computatioal Structures 59 Explicit Formulas ad Recurrece Relatios Let a 0, a, a be defied by the formula a 3 + for all itegers 0. Ca this sequece also be expressed as a recurrece relatio? Idetify first 5 terms: For 0, a 0 3(0) + For, a 3() + 4 For, a 3() + 7 For 3, a 3 3(3) + 0 For 4, a 4 3(4) + 3 Sprig 08 CSE 353 Discrete Computatioal Structures 60
Explicit Formulas ad Recurrece Relatios Let a 0 be the iitial coditio: a 0 3(0) + The, we eed a recurrece relatio for all itegers a 3 +, ad a - 3(-) + 3 3 + (3+) 3 a - 3 Thus, a a - + 3 for all itegers For, a + 3 4 For, a 4 + 3 7 For 3, a 3 7 + 3 0 For 4, a 4 0 + 3 3 Sprig 08 CSE 353 Discrete Computatioal Structures 6 Example 5.6- We are give a sequece t 0, t, t.. that is defied by the formula t + for all itegers 0. Ca we develop a recurrece relatio for this sequece? Sprig 08 CSE 353 Discrete Computatioal Structures 6
Recursive Defiitio of Sums ad Products We ca also use recurrece relatios to defie sums ad products. First, we ca defie a summatio as the followig: Iitial Coditio : Recurrece Relatio : å a i i å a i a i ( ) å a + a, if > - i i Sprig 08 CSE 353 Discrete Computatioal Structures 63 Recursive Defiitio of Sums ad Products Next, we ca defie a product as the followig: Iitial Coditio : Recurrece Relatio : Õa i i Õ a i a i ( ) Õa a, if > - i i Sprig 08 CSE 353 Discrete Computatioal Structures 64
Recursive Defiitio of Sums ad Products The effect of these defiitios is to specify a order i which sums ad products of more tha two umbers are computed. For example, The recursive defiitios are used with mathematical iductio to establish various properties of geeral fiite sums ad products. Sprig 08 CSE 353 Discrete Computatioal Structures 65 Outlie 5. Sequeces 5. Mathematical Iductio I 5.6 Defiig Sequeces Recursively 5.7 Solvig Recurrece Relatios by Iteratio Sprig 08 CSE 353 Discrete Computatioal Structures 66
Solvig Recurrece Relatios by Iteratio Suppose you have a sequece that satisfies a certai recurrece relatio ad iitial coditios. It is ofte helpful to ow a explicit formula for the sequece, especially if you eed to compute terms with very large subscripts or if you eed to examie geeral properties of the sequece. Sprig 08 CSE 353 Discrete Computatioal Structures 67 Solvig Recurrece Relatios by Iteratio Such a explicit formula is called a solutio to the recurrece relatio. The most basic method for fidig a explicit formula for a recursively defied sequece is iteratio. Sprig 08 CSE 353 Discrete Computatioal Structures 68
The Method of Iteratio Iteratio wors as follows: Give a sequece a 0, a, a,... defied by a recurrece relatio ad iitial coditios, you start from the iitial coditios ad calculate successive terms of the sequece util you see a patter developig At that poit you guess a explicit formula Sprig 08 CSE 353 Discrete Computatioal Structures 69 Example Let a, a,... be the sequece defied recursively as follows: Recurrece relatio is: a 3a - +, itegers Iitial coditio is: a Use iteratio to guess a explicit formula for the sequece. Start developig the sequece from the iitial coditio: Sprig 08 CSE 353 Discrete Computatioal Structures 70
Example a a 3a + 3() + 3 + a 3 3a + 3(3 + ) + 3 + 3 + a 4 3a + 3(3 + 3 + ) + 3 3 + 3 + 3 + a 5 3a 3 + 3(3 3 + 3 + 3 + ) + 3 4 + 3 3 + 3 + 3 + There seems to be a patter here! a 3 - + 3 - +. + 3 3 + 3 + 3 + 3 0 Sprig 08 CSE 353 Discrete Computatioal Structures 7 Specific Sequeces Whe solvig recurrece relatios by iteratio, we may ecouter oe of two commo sequece types:. Arithmetic Sequece. Geometric Sequece Sprig 08 CSE 353 Discrete Computatioal Structures 7
Arithmetic Sequece Assume we have a sequece a 0, a, a, If we have a costat d such that a a - + d for all itegers The this sequece is called a arithmetic sequece I this case, it follows that a a 0 + d for all itegers 0 Sprig 08 CSE 353 Discrete Computatioal Structures 73 a 0 d 5 a + 5 Example a + 5() 6 + 5 for recurrece relatio a + 5() 6 + 5 a 3 + 5(3) 6 + 5 Series is,6,,6, Sprig 08 CSE 353 Discrete Computatioal Structures 74
Geometric Sequece Assume we have a sequece a 0, a, a, If we have a costat r such that a ra - for all itegers The this sequece is called a geometric sequece I this case, it follows that a a 0 r for all itegers 0 Sprig 08 CSE 353 Discrete Computatioal Structures 75 a 0 r 3 a a 0 r Example a ()3 3 3() for recurrece relatio a ()3 9 3(3) a 3 ()3 3 7 3(9) Series is,3,9,7 Sprig 08 CSE 353 Discrete Computatioal Structures 76
Example 5.7- Our compay, Mustag Idustries, is producig a ew microprocessor, code amed Perua Our iitial productio ru yield 70 uits If we ca icrease our productivity by uits per day, how may uits ca we expect to produce i 30 days? Sprig 08 CSE 353 Discrete Computatioal Structures 77