patternMinor
Why is this a proof by contradiction for this algorithm? Isn't this a direct proof instead?
Viewed 0 times
thiswhycontradictionalgorithmdirectinsteadforisnproof
Problem
First Slide: Find Max(A)
Second Slide: Proof By Contradiction
Proof: Suppose the algorithm is incorrect. Then for some input A, either:
Max is initialized to and assigned to elements of A - so (1) is impossible.
After the j-th iteration of the for loop (lines 4 - 6), max >= A[j]. From lines 5,6 max only increases. Therefore upon termination, max >= A[j] which contradicts (2).
End Of Slides
This algorithm (first slide) finds the max element in the array. This is a proof by contradiction. Isn't this algorithm already proved when it gets to max >= A[j] in the last line of the second slide. Is which contradicts (2) even necessary? Because in the second slide you showed max is in the array, and then you met the condition of a maxium m: an element m of A such
that m >= A[j] for all 1 <= j <= A.length.
This seems to be two proofs in one. And since it seems to me that the direct proof happens first, then the proof by contradiction is redundant and therefore not necessary. Am i missing something here? Is this only a proof by contradiction? Or is it a direct proof instead?
The image below is just the slides 1 and 2 that I transcribed above. From York University.
- // INPUT: A[1..n] - an array of integers
- // OUTPUT: an element m of A such that m >= A[j], for all 1
- max = A[j==1]
- for j = 2 to A.length
- if max
- max = A[j]
- return max
Second Slide: Proof By Contradiction
Proof: Suppose the algorithm is incorrect. Then for some input A, either:
- max is not an element of A or
- A has an element A[j] such that max
Max is initialized to and assigned to elements of A - so (1) is impossible.
After the j-th iteration of the for loop (lines 4 - 6), max >= A[j]. From lines 5,6 max only increases. Therefore upon termination, max >= A[j] which contradicts (2).
End Of Slides
This algorithm (first slide) finds the max element in the array. This is a proof by contradiction. Isn't this algorithm already proved when it gets to max >= A[j] in the last line of the second slide. Is which contradicts (2) even necessary? Because in the second slide you showed max is in the array, and then you met the condition of a maxium m: an element m of A such
that m >= A[j] for all 1 <= j <= A.length.
This seems to be two proofs in one. And since it seems to me that the direct proof happens first, then the proof by contradiction is redundant and therefore not necessary. Am i missing something here? Is this only a proof by contradiction? Or is it a direct proof instead?
The image below is just the slides 1 and 2 that I transcribed above. From York University.
Solution
You seem to think the structure of the proof is:
That's almost, but not quite true. Step 2 doesn't prove that the returned value $\mathrm{max}$ is bigger than every element of the array, which is what would be required to prove that the algorithm is correct. It just proves that $\mathrm{max}$ is bigger than the specific array value that was supposed to be a counterexample in step 1.
But, as Yuval has pointed out, the proof is much easier if you forget about contradiction completely and prove that $\mathrm{max}$ is in the array (identical to the given proof) and then show that $\mathrm{max}$ is at least as big as every array element (identical to the proof except "for all $j$" instead of just for one supposed counterexample.
- suppose the algorithm is incorrect;
- prove that the algorithm is, in fact, correct;
- this contradicts 1., so the algorithm is correct.
That's almost, but not quite true. Step 2 doesn't prove that the returned value $\mathrm{max}$ is bigger than every element of the array, which is what would be required to prove that the algorithm is correct. It just proves that $\mathrm{max}$ is bigger than the specific array value that was supposed to be a counterexample in step 1.
But, as Yuval has pointed out, the proof is much easier if you forget about contradiction completely and prove that $\mathrm{max}$ is in the array (identical to the given proof) and then show that $\mathrm{max}$ is at least as big as every array element (identical to the proof except "for all $j$" instead of just for one supposed counterexample.
Context
StackExchange Computer Science Q#106019, answer score: 4
Revisions (0)
No revisions yet.