Top Banner
Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC
27

Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

Dec 18, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

Discrete Structures & Algorithms

More on Methods of Proof / Mathematical Induction

EECE 320 — UBC

Page 2: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

2

Announcements

First assignment due Friday• drop-box

Quiz during next lecture

Page 3: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

3

Quiz sample

1.) Show that the following statement: For every positive integer n,

2n n2

is false

2.) Show that if x is irrational, then sqrt(x) is irrational.

Page 4: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

4

What have we explored so far?

Propositional logicRules of inferenceMethods of proofProofs by induction

Page 5: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

5

The essential elements of mathematical induction are:

•The proposition of interest

•The base case•The inductive step

Page 6: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

6

Example

Prove that 2 n < n! for all n > 3

Page 7: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

7

Example

Prove that n3-n is divisible by 3 for all integers n

Do you need to use ‘strong induction’?

Page 8: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

8

ExampleConsider the following game:•Two players. •Players take turns removing any positive number of matches from one of two piles of matches.

•The player who takes the last match(es) wins.

Show that if the two piles contain the same number of matches, the second player has a guaranteed winning strategy

Page 9: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

9

What’s wrong with the following proof using ‘strong induction’?

For all non-negative integer n, 5n=0

Proof:

Base case: 5*0=0

Induction step: Suppose that 5j = 0 for all non-negative integers j, 0j k.

Aim to show that 5(k+1)=0.

We can write k+1=i+j with 0i,j k. 5(k+1)=5(i+j)=5i+5j=0+0=0.

Page 10: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

10

Recursive definitions

Series: Sn = 1 + 2 + 3 + … + n

Can be defined as:S1 = 1

Sn+1 = Sn + (n+1)

Page 11: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

11

Recursive definitions

Sets: S3 = {n| n>0, n divisible by 3}

Can recursively be defined as:Base step: 3 S3

Recursive step: if x S3 and y S3 then x+y S3

Page 12: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

12

Recursive definitions

Structures: A list Ln …is formed by its cells

C1, C2 ,,, Cn

A list recursively be defined as:Base step: an empty list is a list. Recursive step: Ln+1 is a list if it is formed by adding a cell C to a list Ln

Page 13: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

13

Recursive algorithms

Naturally work on all recursive definitions!

Example: Insertion sort

Page 14: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

14

To insert 12, we need to make room for it by moving first 36 and then 24.6 10 24

12

36

Insertion sort

Page 15: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

15

6 10 24 36

12

Insertion sort

Page 16: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

16

6 10 24 36

12

Insertion sort

Page 17: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

17

Insertion sort

Procedure sort (List L):if length(L) 1

return Lelse

C = head (L)T = tail (L)return insert (C, sort(T))

Page 18: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

18

(auxiliary procedure: Insertion)

Procedure insert (Cell C, List L):if length(L) = 0

return list(C)else

if C < head (L) return list(C,L)

else return list(head(L), insert (C,

tail(L))

Page 19: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

19

Induction proofs and recursive procedures

You can use proofs based on induction to prove:• Correctness invariants • Complexity limits

Page 20: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

20

Insertion sort – correctness

Procedure sort (List L):if length(L) 1

return Lelse

C = head (L)T = tail (L)return insert (C, sort(T))

L1 sorted

if LN

sorted then LN+1 sortedTo prove: LN sorted for all lengths N

Page 21: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

21

Insertion sort – complexity

Procedure sort (List L):if length(L) 1

return Lelse

C = head (L)T = tail (L)return insert (C, sort(T))

P1 = 0

PN+1 = PN + complexity(insertN)

To find: PN – the average number of operations to sort LN

Page 22: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

22

In class exercise

Give a recursive algorithm to find the maximum of a list of non-negative integers.• Use structural induction to prove

correctness

• Analyze complexity

Page 23: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

23

Better sorting

Page 24: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

24

Procedure mergesort (L=a1, a2, ….an):

if n>1 then

m:= n/2

L1 = a1, a2, …. am

L2 = am+1, …. an L = merge (mergesort(L1),mergesort(L2))

return L

Recursive proof Correctness Complexity

Page 25: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

25

The essential elements of mathematical induction are:

•The proposition of interest

•The base case•The inductive step

Page 26: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

26

Various uses of induction•Normal•Strong induction

Recursive definitions •Induction: To prove correctness properties (invariants)

• Induction: To analyze algorithm complexity

Page 27: Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.

27

To understand how to perform computations efficiently, we need to know• How to count!• How to sum a sequence of steps.• Reason about the complexity/efficiency of an

algorithm.• Prove the correctness of our analysis.

– Logic– Methods of inference– Proof strategies– Induction– …

• (and eventually) How to create better algorithms.