410 likes | 426 Views
CSE15 Discrete Mathematics 03/01/17. Ming-Hsuan Yang UC Merced. 2.4 Recurrence relations.
E N D
CSE15 Discrete Mathematics03/01/17 Ming-Hsuan Yang UC Merced
2.4 Recurrence relations Definition: A recurrence relation for the sequence {an}is an equation that expresses an in terms of one or more of the previous terms of the sequence, namely, a0, a1, …, an-1, for all integers n with n ≥ n0, where n0 is a nonnegative integer. • A sequence is called a solution of a recurrence relation if its terms satisfy the recurrence relation. • 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 {an}be a sequence that satisfies the recurrence relation an = an-1 + 3for n = 1,2,3,4,…. and suppose that a0 = 2. What are a1,a2 and a3? [Here a0 = 2is the initial condition.] Solution: We see from the recurrence relation that a1= a0 + 3 = 2 + 3 = 5 a2=5 + 3 = 8 a3= 8 + 3 = 11 …
Questions about Recurrence Relations Example 2: Let {an} be a sequence that satisfies the recurrence relation an = an-1 – an-2for n = 2,3,4,…. and suppose that a0 = 3and a1 = 5. What are a2 and a3? [Here the initial conditions are a0 = 3and a1 = 5. ] Solution: We see from the recurrence relation that a2 = a1 - a0 = 5 – 3 = 2 a3 = a2 – a1 = 2– 5=–3 …
Recurrence relation • Express an in terms of one or more of the previous terms of the sequence • Example: an=an-1+3 for n=1,2,3,… and a1=2 • a2=a1+3=2+3=5, a3=a2+3=(2+3)+3=2+3x2=8 , a4=a3+3=(2+3+3)+3=2+3+3+3=2+3x3=11, … • Can write out an=2+3(n-1) with forward substitution • Alternatively can use backward substitution, an=an-1+3=(an-2+3)+3=an-2+3x2 =(an-3+3)+3x2=an-3+3x3=… =a2+3(n-2)=(a1+3)+3(n-2)=2+3(n-1)
Fibonacci sequence • f0=0, f1=1, fn=fn-1+fn-2, for n=2, 3, 4 • f2=f1+f0=1+0=1 • f3=f2+f1=1+1=2 • f4=f3+f2=2+1=3 • f5=f4+f3=3+2=5 • f6=f5+f4=5+3=8 • … • Many applications: coding, sort, pseudo random number generator, economy, etc.
Compound interest • Deposit $10,000 in a savings account yielding 11% per year with interest compounded annually, how much will it be in 30 years? • Pn=Pn-1+0.11Pn-1=(1.11)Pn-1 • P0=10,000 • P1=(1.11)P0 • P2=(1.11)P1=(1.11)2P0 • P3=(1.11)P2=(1.11)3P0 • … • Pn=(1.11)Pn-1=(1.11)nP0 • P30=(1.11)30 10,000=228,922.97
Closed formula • Closed formula: When we can find an explicit formula for a recurrence relation together with initial conditions • Determine whether the sequence {an}, an=3n for every nonnegative integer n, is a solution of the recurrence relation an=2an-1-an-2 for n=2,3,4, • For n>=2, an=2an-1-an-2=2(3(n-1))-3(n-2)=3n=an • Suppose an=2n, Note that a0=1, a1=2, a2=4, but 2a1-a0=2x2-1=3 ≠a2, thus an=2n is not a solution of the recurrence relation
Special integer sequences • Finding some patterns among the terms • Are terms obtained from previous terms • by adding the same amount or an amount depends on the position in the sequence? • by multiplying a particular amount? • By combining previous terms in a certain way? • In some cycle?
Example • Find formulate for the sequences with the following 5 terms • 1, ½, ¼, 1/8, 1/16 • 1, 3, 5, 7, 9 • 1, -1, 1, -1, 1 • The first 10 terms: 1, 2, 2, 3, 3, 3, 4, 4, 4, 4 • The first 10 terms: 5, 11, 17, 23, 29, 35, 41, 47, 53, 59
Example • Conjecture a simple formula for {an} where the first 10 terms are 1, 7, 25, 79, 241, 727, 2185, 6559, 19681, 59047
Summations • The sum of terms: am, am+1, …, an from {an} that represents • Here j is the index of summation (can be replaced arbitrarily by i or k) • The index runs from the lower limit m to upper limit n • The usual laws for arithmetic applies
Example • Express the sum of the first 100 terms of the sequence {an} where an=1/n, n=1, 2, 3, … • What is the value of • What is the value of • Shift index:
Geometric series • Geometric series: sums of geometric progressions
Double summations • Often used in programs • Can also write summation to add values of a function of a set
Example • Find • Let x be a real number with |x|<1, Find • Differentiating both sides of
2.5 Cardinality • The sets A and B have the same cardinality, |A|=|B|, if and only if there is a one-to-one correspondence from A to B • Countable: A set that is eitherfiniteorhas the same cardinality as the set of positive integers • A set that is not countable is called uncountable • When an infinite set S is countable, we denote the cardinality of S by ℕ0, i.e., |S|= ℕ0
Example • Is the set of odd positive integers countable? • To show it is countable, we need to exhibit a one-to-one correspondence between this set and the set of positive integers • f(n)=2n-1 from Z+ to the set of odd positive integers • One-to-one: suppose that f(n)=f(m) then 2n-1=2m-1, so n=m • Onto: suppose t is an odd positive integer, then t is 1 less than an even integer 2k where k is a natural number. Hence t=2k-1=f(k)
Infinite set • An infinite set is countable if and only if it is possible to list the elements of the set in a sequence • The reason being that a one-to-one correspondence f from the set of positive integers to a set S can be expressed by a1, a2, …, an, …where a1=f(1),a2=f(2),…an=f(n) • For instance, the set of odd integers, an=2n-1
Example • Show the set of all integers is countable • We can list all integers in a sequence by 0, 1, -1, 2, -2, … • Or f(n)=n/2 when n is even and f(n)=-(n-1)/2 when n is odd (n=1, 2, 3, …)
Example • Is the set of positive rational numbers countable? • Every positive rational number is p/q • First consider p+q=2, then p+q=3, p+q=4, … 1, ½, 2,3,1/3, ¼, 2/3, 3/2, 4, 5,… Because all positive rational numbers are listed once, the set is countable
Example • Is the set of real numbers uncountable? • Proof by contradiction • Suppose the set is countable, then the subset of all real numbers that fall between 0 and 1 would be countable (as any subset of a countable set is also countable) • The real numbers can then be listed in some order, say, r1, r2, r3, …
Example • So • Form a new real number with • Every real number has a unique decimal expansion • The real number r is not equal to r1, r2, … as its decimal expansion of ri in the i-th place differs from others • So there is a real number between 0 and 1 that is not in the list • So the assumption that all real numbers can between 0 and 1 can be listed must be false • So all the real numbers between 0 and 1 cannot be listed • The set of real numbers between 0 and 1 is uncountable
2.6 Matrix • Matrices are useful discrete structures that can be used in many ways. For example, they are used to: • describe certain types of functions known as linear transformations. • Express which vertices of a graph are connected by edges (see Chapter 10). • In later chapters, we will see matrices used to build models of: • Transportation systems. • Communication networks. • Algorithms based on matrix models will be presented in later chapters. • Here we cover the aspect of matrix arithmetic that will be needed later.
Matrix Definition: A matrix is a rectangular array of numbers. A matrix with m rows and n columns is called an m×nmatrix. • The plural of matrix is matrices. • A matrix with the same number of rows as columns is called square. • 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 2matrix 3 by 2 matrix
Notation • Let m and n be positive integers and let • The i-th row of A is the 1×n matrix[ai1, ai2,…,ain].The j-th column of A is the m×1 matrix: • The (i,j)-th element or entry of A is the element aij. We can use A = [aij ] to denote the matrix with its (i,j)-thelement equal to aij.
Matrix addition Defintion: Let A = [aij] andB = [bij]be m×nmatrices. The sum of A and B, denoted by A + B, is the m×nmatrix that has aij + bij as its (i,j)-th element. In other words, A + B = [aij + bij]. Example: Note that matrices of different sizes can not be added.
Matrix multiplication Definition: Let Abe an n×kmatrix and B be a k × nmatrix. The product of A and B, denoted by AB, is the m×nmatrix 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 = [cij] then cij= ai1b1j + ai2b2j + … + akjb2j. 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 = [aij] and B = [bij]
Matrix multiplication is not commutative Example: Let Does AB = BA? Solution: AB≠BA
Identity matrix and powers of matrices Definition: The identity matrix of order n is the n x n matrix In = [ij], where ij = 1 if i = j and ij = 0 if i≠j. AIn = ImA = A when A is an m×n matrix Powers of square matrices can be defined. When A is an nn matrix, we have: A0 = InAr = AAA∙∙∙A
Transposes of matrices Definition: Let A = [aij] be an m×n matrix. The transpose of A, denoted by AT ,is the n×m matrix obtained by interchanging the rows and columns of A. If AT = [bij], then bij = aji for i =1,2,…,n and j = 1,2, ...,m.
Transposes of matrices Definition: A square matrix A is called symmetric if A = AT. Thus A = [aij] is symmetric if aij = aji 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 Definition: A matrix all of whose entries are either 0 or 1 is called a zero-one matrix. (These will be used in Chapters 9 and 10.) 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: Let A = [aij] and B = [bij] be an mn zero-one matrices. • The joinof A and B is the zero-one matrix with (i,j)-th entry aij ∨ bij. The joinof A and B is denoted by A ∨B. • The meet of of A and B is the zero-one matrix with (i,j)-thentryaij ∧ bij. The meetof 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: The join of A and B is The meet of A and B is
Boolean product of zero-one matrices Definition: Let A = [aij] be an m×k zero-one matrix and B = [bij] be a k×n zero-one matrix. The Boolean productof A and B,denoted by A ⊙B, is the m×nzero-one matrix with(i,j)-th entry cij= (ai1 ∧ b1j)∨ (ai2 ∧ b2j) ∨ … ∨ (aik ∧ bkj). Example: Find the Boolean product of A and B, where
Boolean product of zero-one matrices Solution: The Boolean product A⊙B is given by
Boolean product of zero-one matrices Definition: Let A be a square zero-one matrix and let r be a positive integer. The r-th Boolean power of Ais the Boolean product of r factors of A, denoted by A[r] . Hence, We define A[r] to be In. (The Boolean product is well defined because the Boolean product of matrices is associative.)
Boolean product of zero-one matrices Example: Let Find An for all positive integers n. Solution: