handouts4_seq_ind_rec

handouts4_seq_ind_rec - Sequences and Recursion Mariusz...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sequences and Recursion Mariusz Bajger COMP2781/8781 School of Computer Science, Engineering and Mathematics April 4, 2011 1/ 35 Reading and Exercises Reading Epp, Chapter 5 Exercises Start with the blue ones in Sec. 5.1 to 5.8 Good learning strategy: BE ACTIVE! I Regularly revise lectures I Solve the suggested exercises I Be critical when reading textbook/lectures I Ask your colleagues, ask the lecturer, dont be shy! I It is OK to ask for help any time 2/ 35 Sequences Definition A sequence is a function whose domain is either all the integers between two given integers or all the integers greater than or equal to a given integer. A sequence can be finite a m , a m +1 , a m +2 ,..., a n n m terms or infinite a m , a m +1 , a m +2 ,... infinite number of terms EXAMPLE (explicitly defined sequence) Let s n = 2 n + 4 3 n , n Z , n 2. Then s n 1 = 2 n 1 + 4 3 n 1 . Find s n 2 ? 3/ 35 Summation notation Summation from k ( summation index ) equals m ( lower limit ) to n ( upper limit ) of a-sub- k : n k = m a k = a m + a m +1 + a m +2 + + a n For example, 5 i =0 ( 1) i i + 1 = 0 1 2 + 2 3 3 4 + 4 5 5 6 EXAMPLE (Telescoping sum) Use the formula 1 k ( k +1) = 1 k 1 k +1 to show that n k =1 1 k ( k + 1) = 1 1 n + 1 4/ 35 Product notation Product from k equals m to n of a-sub- k : n k = m a k = a m a m +1 a m +2 a n For example, 5 i =1 i i +1 = 1 2 2 3 3 4 4 5 5 6 = 1 6 Theorem (properties of sums and products) n k = m a n + n k = m b k = n k = m ( a k + b k ) c n k = m a k = n k = m c a k ( n k = m a k ) ( n k = m b k ) = n k = m ( a k b k ) 5/ 35 Change of variable in sums Similar to changing variable in integrals. For example, replace the index i by k in the sum n i =1 i 2 r n i where i = k + 1. Steps: I find the lower and upper limits of the new summation when i = 1 , k = 0 and when i = n , k = n 1 I find the general term of the new summation (replace i by the new index k ) i 2 r n i = ( k + 1) 2 r n k 1 I put it together n i =1 i 2 r n i = n 1 k =0 ( k + 1) 2 r n k 1 6/ 35 n Choose r notation ( n r ) Reminder: (factorial definition), for n Z + n ! = n ( n 1) 3 2 1 = n k =1 k and 0! = 1 Definition For n , r Z : 0 r n we define n choose r ( n r ) which represents the number of subsets of size r that can be selected from a set of n elements. Later, we will prove that ( n r ) = n ! r !( n r )! 7/ 35 Sequences in computer programming One-dimensional arrays a [0] , a [1] , a [2] ,..., a [10] are finite sequences....
View Full Document

Page1 / 9

handouts4_seq_ind_rec - Sequences and Recursion Mariusz...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online