CSE 15 Discrete Mathematics 030117 MingHsuan Yang UC

  • Slides: 41
Download presentation
CSE 15 Discrete Mathematics 03/01/17 Ming-Hsuan Yang UC Merced 1

CSE 15 Discrete Mathematics 03/01/17 Ming-Hsuan Yang UC Merced 1

2. 4 Recurrence relations Definition: A recurrence relation for the sequence {an} is an

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, a 0, a 1, …, an-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. • 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

Questions about Recurrence Relations Example 1: Let {an} be a sequence that satisfies the recurrence relation an = an-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 {an} be a sequence that satisfies the

Questions about Recurrence Relations Example 2: Let {an} be a sequence that satisfies the recurrence relation an = an-1 – an-2 for n = 2, 3, 4, …. and suppose that a 0 = 3 and a 1 = 5. What are a 2 and a 3 ? [Here the initial conditions are a 0 = 3 and a 1 = 5. ] Solution: We see from the recurrence relation that a 2 = a 1 - a 0 = 5 – 3 = 2 a 3 = a 2 – a 1 = 2 – 5 = – 3 …

Recurrence relation • Express an in terms of one or more of the previous

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 a 1=2 – a 2=a 1+3=2+3=5, a 3=a 2+3=(2+3)+3=2+3 x 2=8 , a 4=a 3+3=(2+3+3)+3=2+3+3+3=2+3 x 3=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+3 x 2 =(an-3+3)+3 x 2=an-3+3 x 3=… =a 2+3(n-2)=(a 1+3)+3(n-2)=2+3(n-1) 5

Fibonacci sequence • f 0=0, f 1=1, fn=fn-1+fn-2, for n=2, 3, 4 – f

Fibonacci sequence • f 0=0, f 1=1, fn=fn-1+fn-2, for n=2, 3, 4 – f 2=f 1+f 0=1+0=1 – f 3=f 2+f 1=1+1=2 – f 4=f 3+f 2=2+1=3 – f 5=f 4+f 3=3+2=5 – f 6=f 5+f 4=5+3=8 –… • Many applications: coding, sort, pseudo random number generator, economy, etc. 6

Compound interest • Deposit $10, 000 in a savings account yielding 11% per year

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. 11 Pn-1=(1. 11)Pn-1 • P 0=10, 000 • P 1=(1. 11)P 0 • P 2=(1. 11)P 1=(1. 11)2 P 0 • P 3=(1. 11)P 2=(1. 11)3 P 0 • … • Pn=(1. 11)Pn-1=(1. 11)n. P 0 • P 30=(1. 11)30 10, 000=228, 922. 97 7

Closed formula • Closed formula: When we can find an explicit formula for a

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=3 n for every nonnegative integer n, is a solution of the recurrence relation an=2 an-1 -an-2 for n=2, 3, 4, – For n>=2, an=2 an-1 -an-2=2(3(n-1))-3(n-2)=3 n=an – Suppose an=2 n, Note that a 0=1, a 1=2, a 2=4, but 2 a 1 -a 0=2 x 21=3 ≠a 2, thus an=2 n is not a solution of the recurrence relation 8

Special integer sequences • Finding some patterns among the terms • Are terms obtained

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? 9

Example • Find formulate for the sequences with the following 5 terms – 1,

Example • Find formulate for the sequences with the following 5 terms – 1, ½, ¼, 1/8, 1/16 – 1, 3, 5, 7, 9 – 1, -1, 1 • The first 10 terms: 1, 2, 2, 3, 3, 3, 4, 4 • The first 10 terms: 5, 11, 17, 23, 29, 35, 41, 47, 53, 59 10

Example • Conjecture a simple formula for {an} where the first 10 terms are

Example • Conjecture a simple formula for {an} where the first 10 terms are 1, 7, 25, 79, 241, 727, 2185, 6559, 19681, 59047 11

Summations • The sum of terms: am, am+1, …, an from {an} that represents

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 12

Example • Express the sum of the first 100 terms of the sequence {an}

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 • Shift index: 13

Geometric series • Geometric series: sums of geometric progressions 14

Geometric series • Geometric series: sums of geometric progressions 14

Double summations • Often used in programs • Can also write summation to add

Double summations • Often used in programs • Can also write summation to add values of a function of a set 15

16

16

Example • Find • Let x be a real number with |x|<1, Find •

Example • Find • Let x be a real number with |x|<1, Find • Differentiating both sides of 17

2. 5 Cardinality • The sets A and B have the same cardinality, |A|=|B|,

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 either finite or has 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 18

Example • Is the set of odd positive integers countable? – To show it

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)=2 n-1 from Z+ to the set of odd positive integers – One-to-one: suppose that f(n)=f(m) then 2 n-1=2 m-1, so n=m – Onto: suppose t is an odd positive integer, then t is 1 less than an even integer 2 k where k is a natural number. Hence t=2 k-1=f(k) 19

Infinite set • An infinite set is countable if and only if it is

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 a 1, a 2, …, an, …where a 1=f(1), a 2=f(2), …an=f(n) • For instance, the set of odd integers, an=2 n-1 20

Example • Show the set of all integers is countable • We can list

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, …) 21

Example • Is the set of positive rational numbers countable? • Every positive rational

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 22

Example • Is the set of real numbers uncountable? • Proof by contradiction •

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, r 1, r 2, r 3, … 23

Example • So • Form a new real number with • Every real number

Example • So • Form a new real number with • Every real number has a unique decimal expansion • The real number r is not equal to r 1, r 2, … 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 24

2. 6 Matrix • Matrices are useful discrete structures that can be used in

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

Matrix Definition: A matrix is a rectangular array of numbers. A matrix with m rows and n columns is called an m×n matrix. – 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 2 matrix 3 by 2 matrix

Notation • Let m and n be positive integers and let • The i-th

Notation • Let m and n be positive integers and let • The i-th row of A is the 1×n matrix [ai 1, ai 2, …, 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)-th element equal to aij.

Matrix addition Defintion: Let A = [aij] and B = [bij] be m×n matrices.

Matrix addition Defintion: Let A = [aij] and B = [bij] be m×n matrices. The sum of A and B, denoted by A + B, is the m×n matrix 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 A be an n×k matrix and B be a k

Matrix multiplication Definition: Let A be an n×k matrix and B be a k × n matrix. The product of A and B, denoted by AB, 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 = [cij] then cij = ai 1 b 1 j + ai 2 b 2 j + … + akjb 2 j. 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 =

Illustration of matrix multiplication • The Product of A = [aij] and B = [bij]

Matrix multiplication is not commutative Example: Let Does AB = BA? Solution: AB ≠

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

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 = Im. A = A when A is an m×n matrix Powers of square matrices can be defined. When A is an n n matrix, we have: A 0 = In Ar = AAA∙∙∙A

Transposes of matrices Definition: Let A = [aij] be an m×n matrix. The transpose

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 =

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

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 m

Zero-one matrices Definition: Let A = [aij] and B = [bij] be an m n zero-one matrices. – The join of A and B is the zero-one matrix with (i, j) -th entry aij ∨ bij. The join of A and B is denoted by A ∨ B. – The meet of of A and B is the zero-one matrix with (i, j)-th entry aij ∧ bij. 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

Joins and meets of zero-one matrices Example: Find the join and meet of the zeroone 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 ×

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 product of A and B, denoted by A ⊙ B, is the m×n zero-one matrix with(i, j)-th entry cij = (ai 1 ∧ b 1 j)∨ (ai 2 ∧ b 2 j) ∨ … ∨ (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

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

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 A is 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.

Boolean product of zero-one matrices Example: Let Find An for all positive integers n. Solution: