0% found this document useful (0 votes)
10 views13 pages

Lecture 3 Correctness Proof Techniques

Correctness proof

Uploaded by

sknasimuddin179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

Lecture 3 Correctness Proof Techniques

Correctness proof

Uploaded by

sknasimuddin179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

SPC 2302 Design and Analysis

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

Suppose we have a formula F(n) which we wish to show is true


for all values n ≥ n0
• Usually n0 = 0 or n0 = 1

For example, we may wish to show that


n
n ( n + 1)
F (n) =  k =
k =0 2

for all n ≥ 0
Definition

We then proceed by:


• Demonstrating that F(n0) is true
• Assuming that the formula F(n) is true for an
arbitrary n
• If we are able to demonstrate that this
assumption allows us to also show that the
formula is true for F(n + 1), the inductive
principle allows us to conclude that the
formula is true for all n ≥ n0
Definition

Thus, if F(n0) is true, F(n0 + 1) is true


and, if F(n0 + 1) is true, F(n0 + 2) is true
and, if F(n0 + 2) is true, F(n0 + 3) is true
and so on, and so on, for all n ≥ n0
Formulation
Often F(n) is an equation:
• For example, F(n) may be an equation such as:

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

It may also be a statement:


• The integer n3 – n is divisible by 3 for all n ≥ 1
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
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

n first n odd integers is n2:


Prove that the sum of the
 2k − 1 = n2 for n  1
k =1
1

• When n = 1:  2k − 1 = 1 = 1
k =1
2

• Assume that the statement is true for a given n:  2k − 1 = n


k =1
2

• We now show:
n +1 n

 2k − 1 = 2 ( n + 1) − 1 +  2k − 1
k =1 k =0
Example 2

n first n odd integers is n2:


Prove that the sum of the
 2k − 1 = n2 for n  1
k =1
1

• When n = 1:  2k − 1 = 1 = 1
k =1
2

• Assume that the statement is true for a given n:  2k − 1 = n


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

• Assume that the statement is true for a given n: 2


k =0
k
= 2n +1 − 1
• We now show:
n +1 n

2
k =0
k
=2 n +1
+  2k
k =0
Justification

The induction principle can either be assumed in a


mathematical system as an axiom, or it can be derived from
other axioms

Alternatively, it can be deduced from other axioms, such as:


• The natural numbers (0, 1, 2, 3, …) are linearly ordered
• Every natural number is either 0 or the successor of another natural
number
• The successor is by definition greater than what it succeeds
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

You might also like