Lecture.5: Sequeces CS 50, Discrete Structures, Fall 015 Nitesh Saxea Adopted from previous lectures by Zeph Gruschlag Course Admi HW posted Covers Chapter Due Oct 0 (Tue) Mid Term 1: Oct 15 (Thursday) Review Oct 8 (Thu) Covers Chapter 1 ad Chapter Travelig ext week Presetig a paper at ACM CCS No lecture o Oct 13 Use it for exam preparatio 10/5/015 Lecture.4 -- Fuctios 1
Outlie Sequeces Summatio 10/5/015 Lecture.5 -- Sequeces 3 Sequeces Sequeces are a way of orderig lists of objects. Java arrays are a type of sequece of fiite size. Usually, mathematical sequeces are ifiite. To give a orderig to arbitrary elemets, oe has to start with a basic model of order. The basic model to start with is the set N = {0, 1,, 3, } of atural umbers (iclusive 0). For fiite sets, the basic model of size is: = {1,, 3, 4,, -1, } 10/5/015 Lecture.5 -- Sequeces 4
Sequeces Defiitio: Give a set S, a (ifiite) sequece i S is a fuctio N S. A fiite sequece i S is a fuctio S. Symbolically, a sequece is represeted usig the subscript otatio a i. This gives a way of specifyig formulaically Note: Other sets ca be take as orderig models. The book ofte uses the positive umbers Z + so coutig starts at 1 istead of 0. I ll usually assume the orderig model N. Q: Give the first 5 terms of the sequece defied by the formula π a i cos( i) 10/5/015 Lecture.5 -- Sequeces 5 Sequece Examples A: Plug i for i i sequece 0, 1,, 3, 4: a 0 1, a1 0, a 1, a 3 0, a 4 1 Formulas for sequeces ofte represet patters i the sequece. Q: Provide a simple formula for each sequece: a) 3,6,11,18,7,38,51, b) 0,,8,6,80,4,78, c) 1,1,,3,5,8,13,1,34, 10/5/015 Lecture.5 -- Sequeces 6 3
Sequece Examples A: Try to fid the patters betwee umbers. a) 3,6,11,18,7,38,51, a =6=3+3, a =11=6+5, a 3 =18=11+7, ad i geeral a i = a i-1 +(i +1). This is actually a good eough formula. Later we ll lear techiques that show how to get the more explicit formula: a i = i + (i =1, ) b) 0,,8,6,80,4,78, If you add 1 you ll see the patter more clearly. a i = 3 i 1 c) 1,1,,3,5,8,13,1,34, This is the famous Fiboacci sequece give by a i +1 = a i + a i-1 10/5/015 Lecture.5 -- Sequeces 7 Bit Strigs Bit strigs are fiite sequeces of 0 s ad 1 s. Ofte there is eough patter i the bit-strig to describe its bits by a formula. EG: The bit-strig 1111111 is described by the formula a i =1, where we thik of the strig of beig represeted by the fiite sequece a 1 a a 3 a 4 a 5 a 6 a 7 Q: What sequece is defied by a 1 =1, a =1 a i+ = a i a i+1 10/5/015 Lecture.5 -- Sequeces 8 4
Bit Strigs A: a 0 =1, a 1 =1 a i+ = a i a i+1 : 1,1,0,1,1,0,1,1,0,1, 10/5/015 Lecture.5 -- Sequeces 9 Summatios The symbol S takes a sequece of umbers ad turs it ito a sum. Symbolically: a a a i 0 1 i0 This is read as the sum from i =0 to i = of a i Note how S coverts commas ito plus sigs. Oe ca also take sums over a set of umbers: a x xs... a 10/5/015 Lecture.5 -- Sequeces 10 5
Summatios EG: Cosider the idetity sequece a i = i Or listig elemets: 1,, 3, 4, 5, The sum of the first umbers is give by: i1 a i 1 3... 10/5/015 Lecture.5 -- Sequeces 11 Summatio Formulas Arithmetic There is a explicit formula for the previous: i1 ( 1) i Ituitive reaso: The smallest term is 1, the biggest term is so the avg. term is (+1)/. There are terms. To obtai the formula simply multiply the average by the umber of terms. 10/5/015 Lecture.5 -- Sequeces 1 6
Summatio Formulas Geometric Geometric sequeces are umber sequeces with a fixed costat of proportioality r betwee cosecutive terms. For example:, 6, 18, 54, 16, Q: What is r i this case? 10/5/015 Lecture.5 -- Sequeces 13 Summatio Formulas, 6, 18, 54, 16, A: r = 3. I geeral, the terms of a geometric sequece have the form a i = a r i where a is the 1 st term whe i starts at 0. A geometric sum is a sum of a portio of a geometric sequece ad has the followig explicit formula: ar i a ar ar... ar a( r r 1 i0 1) 1 10/5/015 Lecture.5 -- Sequeces 14 7
Summatio Examples If you are curious about how oe could prove such formulas, your curiosity will soo be satisfied as you will become adept at provig such formulas a few lectures from ow! Q: Use the previous formulas to evaluate each of the followig 1. 103 i0 5( i 3). 13 i0 i 10/5/015 Lecture.5 -- Sequeces 15 A: Summatio Examples 1. Use the arithmetic sum formula ad additivity of summatio: 103 i0 5( i 3) 5 103 i0 ( i 3) 5 103 i0 i 5 103 i0 (103 0) 584 5384 4570 3 10/5/015 Lecture.5 -- Sequeces 16 8
A: Summatio Examples. Apply the geometric sum formula directly by settig a = 1 ad r = : 13 i0 i 14 1 1 14 1 16383 10/5/015 Lecture.5 -- Sequeces 17 Composite Summatio For example: i1 j1 a b i j What s 3 i1 j1 ij 10/5/015 Lecture.5 -- Sequeces 18 9
Today s Readig Rose.4 10/5/015 Lecture.5 -- Sequeces 19 10