Section 2.4
Section Summary Sequences. o Examples: Geometric Progression, Arithmetic Progression Recurrence Relations o Example: Fibonacci Sequence Summations Special Integer Sequences (optional)
Sequences Definition1: A sequence is a function from a subset of the integers (usually either the set {0, 1, 2, 3, 4,..} or {1, 2, 3, 4,.} ) to a set S. The notation a n is used to denote the image of the integer n. We can think of a n as the equivalent of f(n) where f is a function from {0,1,2,..} to S. We call a n a term of the sequence. o A sequence is a discrete structure used to represent an ordered list. o 1,2,3,5,8 is a finite sequence, 1,3,9,27,,3 n, is an finite sequence Example: consider the sequence {a n }, where a n =1/n, list the first four items of the sequence. Solution: o 1,1/2,1/3,1/4
Geometric Progression Definition 2: A geometric progression is a sequence of the form: where the initial term a and the common ratio r are real numbers. Examples: 1. Let a = 1 and r = 1. Then: 2. Let a = 2 and r = 5. Then: 3. Let a = 6 and r = 1/3. Then:
Arithmetic Progression Definition 3: A arithmetic progression is a sequence of the form: where the initial term a and the common difference d are real numbers. Examples: 1. Let a = 1 and d = 4: 2. Let a = 7 and d = 3: 3. Let a = 1 and d = 2:
Strings Strings : Sequences of the form a 1, a 2,..., a n used in computer science are also called strings. This string is also denoted by a 1 a 2... a n. ( e.g. bit strings, which are finite sequences of bits) The length of a string is the number of terms in this string. The empty string, denoted by λ, is the string that has no terms. The empty string has length zero. Example: the string abcd is a string of length four.
Recurrence Relations Definition 4: A recurrence relation for the sequence {a n } is a equation that expresses a n in terms of one or more of the previous terms of the sequence, namely, a 0, a 1,, a n-1, for all integers n with n n 0, where n 0 is a nonnegative integer. A sequence is called a solution of a recurrence relation if its terms satisfy the recurrence relation. A recurrence relation is said to recursively define a sequence. The initial conditions for a sequence specify the terms that precede the first term where the recurrence relation takes effect.
Questions about Recurrence Relations Example 1: Let {a n } be a sequence that satisfies the recurrence relation a n = a n-1 + 3 for n = 1,2,3,4,. and suppose that a 0 = 2. What are a 1, a 2 and a 3? [Here a 0 = 2 is the initial condition.] Solution: We see from the recurrence relation that a 1 = a 0 + 3 = 2 + 3 = 5 a 2 = 5 + 3 = 8 a 3 = 8 + 3 = 11
Questions about Recurrence Relations Example 2: Let {a n } be a sequence that satisfies the recurrence relation a n = a n-1 a n-2 for n = 2,3,4,. and suppose that a 0 = 3 and a 1 = 5. What are a 2,a 3 and a 4? [Here the initial conditions are a 0 = 3 and a 1 = 5. ] Solution: o We see from the recurrence relation that o a 2 = a 1 - a 0 = 5 3 = 2 o a 3 = a 2 a 1 = 2 5 = 3 o a 4 = a 3 a 3 = 3 2= 5
Fibonacci Sequence Definition 5: Define the Fibonacci sequence, f 0,f 1,f 2,, by: o Initial Conditions: f 0 = 0, f 1 = 1 o Recurrence Relation: f n = f n-1 + f n-2 for n=2,3,4. Example: Find f2,f3,f4, f5 and f6. Answer: o f2 = f1 + f0 = 1 + 0 = 1, o f3 = f2 + f1 = 1 + 1 = 2, o f4 = f3 + f2 = 2 + 1 = 3, o f5 = f4 + f3 = 3 + 2 = 5, o f6 = f5 + f4 = 5 + 3 = 8.
Questions about Recurrence Relations Example : Determine whether the sequence {a n }, where a n = 3n for every nonnegative integer n, is a solution of the recurrence relation a n = 2 an 1 a n 2 for n = 2, 3, 4,.... Answer the same question where a n = 2 n and where a n = 5. Solution: o Suppose that a n = 3n for every nonnegative integer n. Then, for n 2, we see that 2a n 1 a n 2 = 2(3(n 1)) 3(n 2) = 3n = a n. Therefore, {a n }, where a n = 3n, is a solution of the recurrence relation. o Suppose that a n = 2 n for every nonnegative integer n. Note that a 0 = 1, a 1 = 2, and a 2 = 4. Because 2a 1 a 0 = 2 2 1 = 3 a 2, we see that {a n }, where a n = 2 n, is not a solution of the recurrence relation. o Suppose that a n = 5 for every nonnegative integer n. Then for n 2, we see that a n = 2a n 1 a n 2 = 2 5 5 = 5 = a n. Therefore, {a n }, where a n = 5, is a solution of the recurrence relation.
Solving Recurrence Relations Finding a formula for the nth term of the sequence generated by a recurrence relation together with the initial conditions is called solving the recurrence relation. Such a formula is called a closed formula.
Iterative Solution Example Method 1: Working upward, forward substitution Starting with the initial condition, and working upward until we reach a n to deduce a closed formula for the sequence. Example : Let {a n } be a sequence that satisfies the recurrence relation a n = a n-1 + 3 for n = 2,3,4,. and suppose that a 1 = 2. a 2 = 2 + 3 a 3 = (2 + 3) + 3 = 2 + 3 2 a 4 = (2 + 2 3) + 3 = 2 + 3 3... a n = a n-1 + 3 = (2 + 3 (n 2)) + 3 = 2 + 3(n 1)
Iterative Solution Example Method 2: Working downward, backward substitution starting with the term a n and working downward until we reach the initial condition to deduce this same formula. Example : Let {a n } be a sequence that satisfies the recurrence relation a n = a n-1 + 3 for n = 2,3,4,. and suppose that a 1 = 2. a n = a n-1 + 3 = (a n-2 + 3) + 3 = a n-2 + 3 2 = (a n-3 + 3 )+ 3 2 = a n-3 + 3 3... = a 2 + 3(n 2) = (a 1 + 3) + 3(n 2) = 2 + 3(n 1)
Financial Application Example: Suppose that a person deposits $10,000.00 in a savings account at a bank yielding 11% per year with interest compounded annually. How much will be in the account after 30 years? Solution : o Let P n denote the amount in the account after 30 years. P n satisfies the following recurrence relation: o P n = P n-1 + 0.11P n-1 = (1.11) P n-1 with the initial condition P 0 = 10,000 o P 1 = (1.11)P 0 o P 2 = (1.11)P 1 = (1.11) 2 P 0 o P 3 = (1.11)P 2 = (1.11) 3 P 0 o : o P n = (1.11)P n-1 = (1.11) n P 0 = (1.11) n 10,000 o P n = (1.11) n 10,000 o P 30 = (1.11) 30 10,000 = $228,992.97
Special Integer Sequences Given a few terms of a sequence, try to identify the sequence. Conjecture a formula, recurrence relation, or some other rule. Some questions to ask? o Are there repeated terms of the same value? o Can you obtain a term from the previous term by adding an amount or multiplying by an amount? o Can you obtain a term by combining the previous terms in some way? o Are they cycles among the terms? o Do the terms match those of a well known sequence?
Questions on Special Integer Sequences Example 1: Find formulae for the sequences with the following first five terms: 1, 1/2, 1/4, 1/8, 1/16 Solution: Note that the denominators are powers of 2. The sequence with a n = 1/2 n is a possible match. This is a geometric progression with a = 1 and r = ½. Example 2: Consider 1,3,5,7,9 Solution: Note that each term is obtained by adding 2 to the previous term. A possible formula is a n = 2n + 1. This is an arithmetic progression with a =1 and d = 2.
Questions on Special Integer Sequences Example 3: How can we produce the terms of a sequence if the first 10 terms are 5, 11, 17, 23, 29, 35, 41, 47, 53, 59? Solution: Note that each of the first 10 terms of this sequence after the first is obtained by adding 6 to the previous term. Consequently, the nth term could be produced by starting with 5 and adding 6 a total of n 1 times; that is, a reasonable guess is that the nth term is 5 + 6(n 1) = 6n 1. This is an arithmetic progression with a = 5 and d = 6.
Useful Sequences
Questions on Special Integer Sequences Example : Conjecture a simple formula for an if the first 10 terms of the sequence {a n } are 1, 7, 25, 79, 241, 727, 2185, 6559, 19681, 59047. Solution: Comparing these terms with the corresponding terms of the sequence {3 n }, we notice that the nth term is 2 less than the corresponding power of 3. We see that a n = 3 n 2 for 1 n 10 and conjecture that this formula holds for all n.
Summations Sum of the terms from the sequence The notation: represents The variable j is called the index of summation. It runs through all the integers starting with its lower limit m and ending with its upper limit n.
Summations Example: What is the value of? Solution: Example : What is the value of? Solution :
Summations More generally for a set S: Example: What is the value of? Solution: o the sum of the values of s for all the members of the set {0, 2, 4},
Product Notation (optional) Product of the terms from the sequence The notation: represents
Geometric Series THEOREM 1: Sums of terms of geometric progressions
Double summations Double summations arise in many contexts (as in the analysis of nested loops in computer programs) o first expand the inner summation and then continue by computing the outer summation Example : Solution :
Section 2.6
Section Summary Definition of a Matrix Matrix Arithmetic Transposes and Powers of Arithmetic Zero-One matrices
Matrix Definition 1: A matrix is a rectangular array of numbers. A matrix with m rows and n columns is called an m n matrix. o The plural of matrix is matrices. o A matrix with the same number of rows as columns is called square. o Two matrices are equal if they have the same number of rows and the same number of columns and the corresponding entries in every position are equal. 3 2 matrix
Notation Let m and n be positive integers and let The i th row of A is the 1 n matrix [a i1, a i2,,a in ]. The j th column of A is the m 1 matrix: The (i,j) th element or entry of A is the element a ij. We can use A = [a ij ] to denote the matrix with its (i,j) th element equal to a ij.
Matrix Arithmetic: Addition Definition 3: Let A = [a ij ] and B = [b ij ] be m n matrices. The sum of A and B, denoted by A + B, is the m n matrix that has a ij + b ij as its (i,j)th element. In other words, A + B = [a ij + b ij ]. Example: Note that matrices of different sizes can not be added.
Matrix Multiplication Definition 4: Let A be an m k matrix and B be a k n matrix. The product of A and B, denoted by A B, is the m n matrix that has its (i,j) th element equal to the sum of the products of the corresponding elments from the i th row of A and the j th column of B. In other words, if AB = [c ij ] then c ij = a i1 b 1j + a i2 b 2j + + a kj b 2j. Example: = The product of two matrices is undefined when the number of columns in the first matrix is not the same as the number of rows in the second.
Illustration of Matrix Multiplication The Product of A = [a ij ] and B = [b ij ]
Matrix Multiplication is not Commutative Example: Let Does AB = BA? Solution: AB BA
Identity Matrix and Powers of Matrices Definition 5: The identity matrix of order n is the n n matrix I n = [ ij ], where ij = 1 if i = j and ij = 0 if i j. when A is an m n matrix, AI n = I m A = A Powers of square matrices can be defined. When A is an n n matrix, we have: A 0 = I n A r = AAA A r times
Transposes of Matrices Definition 6: Let A = [a ij ] be an m n matrix. The transpose of A, denoted by A t,is the n m matrix obtained by interchanging the rows and columns of A. If A t = [b ij ], then b ij = a ji for i =1,2,,n and j = 1,2,...,m.
Transposes of Matrices Definition 7: A square matrix A is called symmetric if A = A t. Thus A = [a ij ] is symmetric if a ij = a ji for i and j with 1 i n and 1 j n. Square matrices do not change when their rows and columns are interchanged.
Zero-One Matrices A matrix all of whose entries are either 0 or 1 is called a zeroone matrix. Algorithms operating on discrete structures represented by zero-one matrices are based on Boolean arithmetic defined by the following Boolean operations:
Zero-One Matrices Definition 8: Let A = [a ij ] and B = [b ij ] be an m n zero-one matrices. o The join of A and B is the zero-one matrix with (i,j)th entry a ij b ij. The join of A and B is denoted by A B. o The meet of of A and B is the zero-one matrix with (i,j)th entry a ij b ij. The meet of A and B is denoted by A B.
Joins and Meets of Zero-One Matrices Example: Find the join and meet of the zero-one matrices Solution: o The join of A and B is o The meet of A and B is
Boolean Product of Zero-One Matrices Definition 9: Let A = [a ij ] be an m k zero-one matrix and B = [b ij ] be a k n zero-one matrix. The Boolean product of A and B, denoted by A B, is the m n zero-one matrix with(i,j)th entry c ij = (a i1 b 1j ) (a i2 b 2j ) (a ik b kj ). Example: Find the Boolean product of A and B, where
Boolean Powers of Zero-One Matrices Definition 10: Let A be a square zero-one matrix and let r be a positive integer. The rth Boolean power of A is the Boolean product of r factors of A, denoted by A [r]. Hence, We define A [0] to be In. The Boolean product is well defined because the Boolean product of matrices is associative.
Boolean Powers of Zero-One Matrices Example: Let Find A n for all positive integers n. Solution: