Sie sind auf Seite 1von 3

Proof by Contradiction Look for a contradiction in the proof We start by assuming the hypothesis and the logical negation

on of the conclusion. Continue any other proof technique until a contradiction is found. Example Theorem: There are infinitely many prime numbers. Proof: Assume the contrary, that there is a finite number of prime numbers. Since there is a finite number, we can list them, p1, p2, pn. Consider the number q=p1 p2 pn + 1. q is either prime or composite. If we divide q by any of its prime factors, it will give a nonzero remainder. Thus, q is not composite. We conclude that q must be prime, was not listed in our list of finite prime numbers, and contradicts our assumption that primes are finite.

Proof By Induction Relies on a defined base case and then generating iterations of the problem ad infinitum Prove the first statement at an initial case, e.g. n=0 Assume true at n=m, prove true at n=m+1. Example Prove Prove true for n=1, then 1(1+1)/2 = 1. Assume true for n=m, Prove for n=m+1

1 2 3 m (m 1) m(m 1) 2(m 1) 2 2 m(m 1) 2(m 1) 2 (m 1)(m 2) 2 (m 1)((m 1) 1) 2

Proof by Loop Invariant Method of proof using Loop Invariants Loop Invariant - a statement that is always true before and after each iteration of a loop; although may be false inside the loop Provides a formal method for proving the correctness of a loop body Three things must be shown about a loop invariant: Initialization : It is true prior to the first iteration of the loop Maintenance: If it is true before an iteration of a loop, it remains tre before the next iteration. Termination: When the loop terminates, the invariant gives us a useful property that shows that the algorithm is correct.

When the first two properties hold, the invariant holds prior to every iteration of the loop (c.f. inductive base case) When the last property holds, we establish correctness of algorithm

Das könnte Ihnen auch gefallen