Lecture 3 Correctness Proof Techniques
Lecture 3 Correctness Proof Techniques
of Computer Algorithm
Lecture 3 Correctness Proof
Methods of Proof
• Proof by Contradiction
– Assume a theorem is false; show that this assumption implies a
property known to be true is false -- therefore original hypothesis
must be true
• Proof by Counterexample
– Use a concrete example to show an inequality cannot hold
• Mathematical Induction
– Prove a trivial base case, assume true for k, then show hypothesis is
true for k+1
– Used to prove recursive algorithms
Definition
for all n ≥ 0
Definition
n
n ( n + 1)
k =0
k=
2
for n 0
n
2 k
k =1
− 1 = n 2
for n 1
n
2 k
k =0
= 2 n +1
− 1 for n 0
k = ( n + 1) + k
k =0 k =0
Example 1
n
n ( n + 1)
k =
Prove that k =0 2 is true for n ≥ 0
0
0 ( 0 + 1)
• When n = 0:
k =0=
k =0 2
n
n ( n + 1)
• Assume that the statement is true for a given n: k =
k =0 2
• We now show:
n +1 n
k = ( n + 1) + k
k =0 k =0
n ( n + 1)
= ( n + 1) +
2
2 ( n + 1) + n ( n + 1)
=
2
=
( n + 2 )( n + 1) = ( n + 1)( n + 2 )
2 2
Example 2
• When n = 1: 2k − 1 = 1 = 1
k =1
2
• We now show:
n +1 n
2k − 1 = 2 ( n + 1) − 1 + 2k − 1
k =1 k =0
Example 2
• When n = 1: 2k − 1 = 1 = 1
k =1
2
• We now show:
n +1 n
2k − 1 = 2 ( n + 1) − 1 + 2k − 1
k =1 k =1
= 2 ( n + 1) − 1 + n 2
= 2n + 2 − 1 + n 2
= n 2 + 2n + 1
= ( n + 1)
2
Example 3
n
2
Prove that k =0
k
= 2 n +1
−1
for n ≥ 0
0
• When n = 0:
2
k =0
k
= 20 = 1 = 20+1 − 1
2
k =0
k
=2 n +1
+ 2k
k =0
Justification
You may ask: “Suppose you’ve proved some formula F(n) for
by induction to be true for all n = 0, 1, 2, …; all we really showed
was that F(0) is true—could it not fail for some larger value
F(k)?
Suppose that there is a k such that F(k) is false
• There must be a smallest value k > 0 such that
F(k – 1) is true but
F(k) is false
• But the inductive step showed that if F(k – 1) is true, it must also be
true that F(k) is true!
• Thus, no such smallest k can exist
• Thus, no subset of N can have F(n) be false