Introduction Algorithms are procedures to accomplish a specific task. They are ideas. Algorithms have three main attributes: correctness, simplicity, and efficiency Correctness is tricky to prove: Many have proposed algorithms that were later proven to be incorrect. Algorithms are always correct; heuristic solutions may give a suitable answer most of the time, but not always. Correctness Specify the input Specify the output Make sure output is well-defined Beware of a compound goals. Each part might be a good goal, but trying satisfy all at the same time can make things overly complicated. If in doubt, restrict the problem. It will make proving correctness easier. Counter-examples: the easiest way to prove incorrectness, but failing to find counter-examples does not prove correctness. A counter-example should be verifiable. Show what the proposed algorithm gives as output. Then show that there’s is a better answer. They should be simple, no extra bits. Finding good counter-examples is similar to writing good tests. But finding good counter-examples is not about exploring the whole domain. Think small. Confine the input space and exhaust all options. Look for weaknesses (e.g. If algorithm relies on finding the maximum, what happens if all values are equal?). Look for ties. Look at extreme cases: large, small, clustered, diffuse. Proof by induction is the most common way to prove an algorithm, especially recursively defined ones. Specify a boundary or base case Assuming several things are true, show that incrementally breaking the problem into related sub-problems, the output is true. Two common errors are bad base cases or assuming a proven algorithm can be applied to input that has not been proven yet. Summations are used often in algorithm analysis Arithmetic progressions e.g. The sum of the first n positive integers is $n(n+1)/2$ In general, if the term is quadratic, the sum will have a cubic order; a cubic term will have a sum that is a quartic order, etc. If the terms have a negative exponent, the sum converges to a constant. Geometric progressions If the base of each term is less than one, the summation always converges to a number. If the base is one or more, it diverges. When proving a summation by induction, the main step is to usually factor out the largest term, so that the inductive hypothesis can be substituted into the equation. Modeling problems Modeling your application in terms of well-defined data structures and algorithms is the most important step to finding a solution.
...