+ All Categories
Home > Documents > CSE 20 – Discrete Mathematics

CSE 20 – Discrete Mathematics

Date post: 23-Feb-2016
Category:
Upload: yered
View: 20 times
Download: 0 times
Share this document with a friend
Description:
- PowerPoint PPT Presentation
Popular Tags:
25
CSE 20 – Discrete Mathematics Dr. Cynthia Bailey Lee Dr. Shachar Lovett Peer Instruction in Discrete Mathematics by Cynthia Lee is licensed under a Creative Commons Attribution- NonCommercial - ShareAlike 4.0 International License . Based on a work at http://peerinstruction4cs.org . Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org .
Transcript
Page 1: CSE 20 – Discrete Mathematics

CSE 20 – Discrete MathematicsDr. Cynthia Bailey LeeDr. Shachar Lovett

                          Peer Instruction in Discrete Mathematics by Cynthia Leeis licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.Based on a work at http://peerinstruction4cs.org.Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org.

Page 2: CSE 20 – Discrete Mathematics

2

Today’s Topics:1. Mathematical Induction Proof

3-cents and 5-cents example Our first algorithm!

Page 3: CSE 20 – Discrete Mathematics

3

1. Mathematical Induction Proof

Examples, examples, examples

Page 4: CSE 20 – Discrete Mathematics

4

3-cent and 5-cent coins We will prove the following theorem

Theorem: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins

1851-1889

1866-today

Page 5: CSE 20 – Discrete Mathematics

5

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for price p=____. Inductive step:Assume [or “Suppose”] that

WTS that

So the inductive step holds, completing the proof.

Page 6: CSE 20 – Discrete Mathematics

6

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for price p=________. Inductive step:Assume [or “Suppose”] that

WTS that

So the inductive step holds, completing the proof.

A. 0 centsB. 1 centC. 2 centsD. 3 centsE. Other/none/

more than one

Page 7: CSE 20 – Discrete Mathematics

7

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for price p=8. Inductive step:Assume [or “Suppose”] that

WTS that

So the inductive step holds, completing the proof.

Page 8: CSE 20 – Discrete Mathematics

8

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for price p=8. Inductive step:Assume [or “Suppose”] that

WTS that

So the inductive step holds, completing the proof.

A. Theorem is true for p=8.B. Theorem is true for some

p>8.C. Theorem is true for some

p8.D. Theorem is true for some

p>0.E. Theorem is true for all p>8.

Page 9: CSE 20 – Discrete Mathematics

9

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for price p=8. Inductive step:Assume [or “Suppose”] that theorem is true for some p8.

WTS that

So the inductive step holds, completing the proof.

Page 10: CSE 20 – Discrete Mathematics

10

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for price p=8. Inductive step:Assume [or “Suppose”] that theorem is true for some p8.

WTS that

So the inductive step holds, completing the proof.

A. Theorem is true for p=8.B. Theorem is true for some

p>8.C. Theorem is true for p+1.D. Theorem is true for p+8.

Page 11: CSE 20 – Discrete Mathematics

11

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for price p=8. Inductive step:Assume [or “Suppose”] that theorem is true for some p8.

WTS that theorem is true for price p+1.

So the inductive step holds, completing the proof.

Page 12: CSE 20 – Discrete Mathematics

12

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for price p=8. Inductive step:Assume [or “Suppose”] that theorem is true for some p8.

WTS that theorem is true for price p+1.

So the inductive step holds, completing the proof.

???

Page 13: CSE 20 – Discrete Mathematics

13

3-cent and 5-cent coins Inductive step:

Assume price p8 can be paid using only 3-cent and 5-cent coins.

Need to prove that price p+1 can be paid using only 3-cent and 5-cent coints.

Main idea: “reduce” from price p+1 to price p.

Page 14: CSE 20 – Discrete Mathematics

14

Making change If we have 100 5-cent coins, and 100 3-

cent coins (for a total of p = $8.00), how can we modify the number of 5-cent and 3-cent coins so that we can make the p+1 price (p+1 = $8.01)? A. 40 5-cent coins + 200 3-cent coinsB. 39 5-cent coins + 202 3-cent coinsC. 99 5-cent coins + 102 3-cent coins

Page 15: CSE 20 – Discrete Mathematics

15

Turning our modification scheme into a generic algorithm

If we have n 5-cent coins, and m 3-cent coins (for a total of p = 5n+3m), how can we modify the number of 5-cent and 3-cent coins so that we can make the p+1 price (p+1 = 5n+3m+1)? A. n+1 5-cent coins + m-2 3-cent coinsB. n-1 5-cent coins + m+2 3-cent coinsC. n+1 5-cent coins + m+2 3-cent coinsD. No generic way

Page 16: CSE 20 – Discrete Mathematics

16

What if we don’t have any 5-cent coins to subtract??

If we have 0 5-cent coins, and m 3-cent coins (for a total of p = 3m), how can we modify the number of 5-cent and 3-cent coins so that we can make the p+1 price (p+1 = 3m+1)? A. You can’tB. You can [explain to your group how]

Page 17: CSE 20 – Discrete Mathematics

17

What if we don’t have any 5-cent coins to subtract??

If we have 0 5-cent coins, and m 3-cent coins (for a total of p = 3m), how can we modify the number of 5-cent and 3-cent coins so that we can make the p+1 price (p+1 = 3m+1)?

Remove three 3-cent coins, add two 5-cent So: two 5-cent coins, m-3 3-cent points, for a

total of 2*5+3*(m-3)=3m+1=p+1

Page 18: CSE 20 – Discrete Mathematics

18

That algorithm relies on being able to subtract three 3-cent coins. What if we don’t have that many? (only 1 or 2?)

A. Uh-oh, our proof can not work as we’ve done it so far

B. That could never happen [explain why not]

C. That could happen, and we need to make a 3rd (or more) case(s) to handle it

Page 19: CSE 20 – Discrete Mathematics

19

Thm: For all prices p >= 8 cents, the price p can be paid using only 5-cent and 3-cent coins.Proof (by mathematical induction):Basis step: Show the theorem holds for p=8 (by example, e.g. p=3+5) Inductive step:Assume [or “Suppose”] that the theorem holds for some p8.WTS that the theorem holds for p+1.p8.

So the inductive step holds, completing the proof.

Assume that p=5n+3m where n,m0 are integers. We need to show that p+1=5a+3b for integers a,b0.Partition to cases:

Case I: n1. In this case, p+1=5*(n-1)+3*(m+2).Case II: m3. In this case, p+1=5*(n+2)+3*(m-3).Case III: n=0 and m2. Then p=5n+3m6 which is a contradiction to p8.

Page 20: CSE 20 – Discrete Mathematics

20

We created an algorithm! Our proof actually allows us to

algorithmically find a way to pay p using 3-cent and 5-cent coins

Algorithm for price p: start with 8=3+5 For x=8...p, in each step adjust the

number of coins according to the modification rules we’ve constructed to maintain price x

Page 21: CSE 20 – Discrete Mathematics

21

Algorithm pseudo-codePayWithThreeCentsAndFiveCents:

Input: price p8.Output: integers n,m0 so that p=5n+3m

1. Let x=8, n=1, m=1 (so that x=5n+3m).2. While x<p:

a) x:=x+1b) If n1, set n:=n-1, m:=m+2c) Otherwise, set n:=n+2, m:=m-3

3. Return (n,m)

Page 22: CSE 20 – Discrete Mathematics

22

Algorithm pseudo-codePayWithThreeCentsAndFiveCents:

Input: price p8.Output: integers n,m0 so that p=5n+3m

1. Let x=8, n=1, m=1 (so that x=5n+3m).

2. While x<p:a) x:=x+1b) If n1, set n:=n-1, m:=m+2c) Otherwise, set n:=n+2, m:=m-3

3. Return (n,m)

Invariant: x=5n+3m

Invariant: x=5n+3mWe proved that n,m0 in this process always; this is not immediate from the algorithm code

Page 23: CSE 20 – Discrete Mathematics

23

Algorithm run example 8=

9=

10 =

11=

12 =

x=8: n=1, m=1While x<p:

a) x:=x+1b) If n1, set n:=n-1, m:=m+2c) Otherwise, set n:=n+2, m:=m-

3

Invariant: x=5n+3m

Page 24: CSE 20 – Discrete Mathematics

24

Algorithm properties Theorem: Algorithm uses at most two

nickels(i.e n2)

Proof: by induction on p Try to prove it yourself first!

x=8: n=1, m=1While x<p:

a) x:=x+1b) If n1, set n:=n-1, m:=m+2c) Otherwise, set n:=n+2, m:=m-

3

Invariant: x=5n+3m

Page 25: CSE 20 – Discrete Mathematics

25

Algorithm properties Theorem: Algorithm uses at most two nickels (i.e n2).

Proof: by induction on pBase case: p=8. Algorithm outputs n=m=1.

Inductive hypothesis: p=5n+3m where n2.WTS p+1=5a+3b where a2.

Proof by cases: Case I: n1. So p+1=5(n-1)+3(m+2) and a=n-12. Case II: n=0. So p+1=5*2+3(m-3). a=2.

In both cases p+1=5a+3b where a2. QED

x=8: n=1, m=1While x<p:

a) x:=x+1b) If n1, set n:=n-1, m:=m+2c) Otherwise, set n:=n+2, m:=m-

3

Invariant: x=5n+3m


Recommended