Unformatted text preview: xample input I: You show that, for this particular input I, the output from A is not the intended solution. Strictly speaking, all algorithms need correctness proof. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 12 / 49 Correctness Proof of Algorithms
An algorithm A is correct, if it works on all inputs. If A works on some inputs, but not on some other inputs, then A is incorrect. To show A is correct, you must argue that for all inputs, A produces intended solution. To show A is incorrect, you only need to give a counter example input I: You show that, for this particular input I, the output from A is not the intended solution. Strictly speaking, all algorithms need correctness proof. For DaC, it's often so straightforward that the correctness proof is unnecessary/omitted. (Example: MergeSort) c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 12 / 49 Correctness Proof of Algorithms
An algorithm A is correct, if it works on all inputs. If A works on some inputs, but not on some other inputs, then A is incorrect. To show A is correct, you must argue that for all inputs, A produces intended solution. To show A is incorrect, you only need to give a counter example input I: You show that, for this particular input I, the output from A is not the intended solution. Strictly speaking, all algorithms need correctness proof. For DaC, it's often so straightforward that the correctness proof is unnecessary/omitted. (Example: MergeSort) For dynamic programming algorithms, the correctness proof is less obvious than the DaC algorithms. But in most time, it is quite easy to convince people (i.e. informal proof) the algorithm is correct. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 12 / 49 Correctness Proof of Algorithms
An algorithm A is correct, if it works on all inputs. If A works on some inputs, but not on some other inputs, then A is incorrect. To show A is correct, you must argue that for all inputs, A produces intended solution. To show A is incorrect, you only need to give a counter example input I: You show that, for this particular input I, the output from A is not the intended solution. Strictly speaking, all algorithms need correctness proof. For DaC, it's often so straightforward that the correctness proof is unnecessary/omitted. (Example: MergeSort) For dynamic programming algorithms, the correctness proof is less obvious than the DaC algorithms. But in most time, it is quite easy to convince people (i.e. informal proof) the algorithm is correct. For greedy algorithms, the correctness proof can be very tricky.
c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 12 / 49 Elements of Greedy Algorithms
For a greedy strategy to work, it must have the following two properties. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 13 / 49 Elements of Greedy Algorithms
For a greedy strategy to work, it must have the following two properties. Optimal Substructure Property
An optimal solution of the problem contains within it the optimal solutions of subproblems. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 13 / 49 Elements of Greedy Algorithms
For a greedy strategy to work, it must have the following two properties. Optimal Substructure Property
An optimal solution of the problem contains within it the optimal solutions of subproblems. This is the same property required by the dynamic programming algorithms. Greedy Choice Property
A global optimal solution can be obtained by making a locally optimal choice that seems the best toward the optimization goal when the choice is made. (Namely: The choice is made based on the choices we have already made, not based on the future choices we might make.) This property is harder to describe exactly. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 13 / 49 Elements of Greedy Algorithms
For a greedy strategy to work, it must have the following two properties. Optimal Substructure Property
An optimal solution of the problem contains within it the optimal solutions of subproblems. This is the same property required by the dynamic programming algorithms. Greedy Choice Property
A global optimal solution can be obtained by making a locally optimal choice that seems the best toward the optimization goal when the choice is made. (Namely: The choice is made based on the choices we have already made, not based on the future choices we might make.) This property is harder to describe exactly. Best way to understand it is by examples.
c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 13 / 49 Optimal Substructure Property for MST Example
Optimal Substructure Property for MST Let G = (V, E) be a connected graph with edge weight. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 14 / 49 Optimal Substructure Property for MST Example
Optimal Substructure Property for MST Let G = (V, E) be a connected graph with edge weight. Let e1 = (x, y) be the edge with t...
View
Full
Document
This note was uploaded on 02/27/2012 for the course CSE 431/531 taught by Professor Xinhe during the Fall '11 term at SUNY Buffalo.
 Fall '11
 XINHE
 Algorithms

Click to edit the document details