CS173: Discrete Math

Download Report

Transcript CS173: Discrete Math

CSE115/ENGR160 Discrete Mathematics 04/21/11

Ming-Hsuan Yang UC Merced 1

7.1 Recurrence relations

• • • Many counting problems can be solved with recurrence relations Example: The number of bacteria doubles every 2 hours. If a colony begins with 5 bacteria, how many will be present in n hours?

Let a n =2a n-1 a 0 =5 where n is a positive integer with 2

Recurrence relations

• • A recurrence relation for the sequence {a n } is an equation that expresses an in terms of 1 or more of the previous terms of the sequence, i.e., 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 3

Recursion and recurrence

• • A recursive algorithm provides the solution of a problem of size n in terms of the solutions of one or more instances of the same problem of smaller size When we analyze the complexity of a recursive algorithm, we obtain a recurrence relation that expresses the number of operations required to solve a problem of size n in terms of the number of operations required to solve the problem for one or more instance of smaller size 4

Example

• • 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 and a 3 ?

Using the recurrence relation, a 2 =a 1 -a 0 =5-3=2 and a 3 =a 2 -a 1 =2-5=-3 5

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 =2a n-1 – a n-2 for n=2, 3, 4, … Suppose a n =3n for every nonnegative integer n. Then for n ≥2, we have 2a n-1 -a n-2 =2(3(n 1))-3(n-2)=3n=a n . Thus, {a n } where a n =3n is a solution for the recurrence relation 6

Modeling with recurrence relations

• • Compound interest: Suppose that a person deposits $10,000 in a savings account at a bank yielding 11% per year with interest compounded annually. How much will it be in the account after 30 years?

Let P n denote the amount in the account after n years. The amount after n years equals the amount in the amount after n-1 years plus interest for the n th year, we see the sequence {P n } has the recurrence relation P n =P n-1 +0.11P

n-1 =(1.11)P n-1 7

Modeling with recurrence relations

• • • • • • • The initial condition P 0 =10,000, thus 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 … P n =(1.11)P n-1 =(1.11) n P 0 We can use mathematical induction to establish its validity 8

Modeling with recurrence relations

• • • • We can use mathematical induction to establish its validity Assume P n =(1.11) n 10,000. Then from the recurrence relation and the induction hypothesis P n+1 =(1.11)P n =(1.11)(1.11) n 10,000=(1.11) n+1 10, 000 n=30, P 30 =(1.11) 30 10,000=228,922.97

9

7.5 Inclusion-exclusion

• • The principle of inclusion-exclusion: For two sets A and B, the number of elements in the union is defined by |A ⋃B|=|A|+|B|-|A⋂B| Example: How many positive integers not exceeding 1000 are divisible by 7 or 11?

|

A

B

|  |

A

|  |

B

|  |

A

B

|     1000 142 7    90    1000 11    12   220   1000 7  11   10

Principle of inclusion-exclusion

• • Consider union of n sets, where n is a positive integer Let n=3 |

A

B

C

|  |

A

|  |

B

|  |

C

|  |

A

B

|  |

B

C

|  |

C

A

|  |

A

B

C

| 11

Principle of inclusion-exclusion

• • • • Let A 1 , A 2 , …, A n |

A

1 

A

2    be finite sets. Then

A n

|  1 

i

 

n

|

A i

|  1 

i

, 

j

 |

n A i

1 

i

,

j

 ,

k

| 

n A i

A j

A k

|    (  1 )

n

 1 |

A

1 

A

2

A j

|    

A n

| Proof: Prove it by showing that an element in the union is counted exactly once by the right-hand side of the equation Suppose that a is a member of exactly r of the sets A 1 , A 2 , …, A n where 1 ≤r ≤n This element is counted C(r,1) times by ∑|A i | 12

Principle of inclusion-exclusion

• • • • • It is counted C(r,2) times by ∑|A i ⋂ A j | In general, it is counted C(r,m) times by the summation involving m of the sets A i . Thus, this element is counted exactly C(r,1)-C(r,2)+C(r,3)-…+(-1) r+1 C(r,r)

n

  (  1 )  

n

 C(r,0)-C(r,1)+C(r,2)-C(r,3)-…+(-1) r C(r,r)=0 0

k k

Thus, C(r,1)-C(r,2)+C(r,3)-…+(-1) r+1 C(r,r)=C(r,0)=1 Thus, this element a is counted exactly once by the right hand side 13

Principle of inclusion-exclusion

• • Gives a formula for the number of elements in the union of n sets for every positive integer n There are terms in this formula for the number of elements in the intersection of every nonempty subset of the collection of the n sets. Hence there are 2 n -1 terms in the formula 14

Example

• For the union of 4 sets, there are 15 different terms, one for each nonempty subset of {A 1 , A 2 , A 3 , A 4 } | 

A

1 | 

A

1  |

A

1

A

  2 

A

2

A

2  |

A

1 

A

2 |

A

3   | 

A

1

A

4  |  |

A

3

A

1 |  | |  |

A

1

A

2 

A

3 |  |

A

1 

A

2 

A

4 | | 

A

4 |

A

3 |  |

A

4 | |   | |

A

1

A

2  

A

3

A

3  | 

A

4 | |

A

2  | 

A

2

A

4  | 

A

3 |

A

 3 

A

4 |

A

4 

A

3 

A

4 | | 15