Date: Thu, 5 Feb 2004 12:08:02 -0500 From: Amittai Aviram To: Marco Valtorta Subject: Rules for testing algorithm correctness <...> Here is how I would summarize the rules we have learned about testing algorithm correctness. <...> I. Test to make sure that algorithm will terminate. II. Define a precondition (allowable input and state) and a postcondition (correct output). III. Test that, given precondition, algorithm will fulfill postcondition. In many cases, the algorithm is either recursive or iterative. Determine which one applies. A. Recursive algorithms. Use induction to show correct fulfillment of postcondition in (1) basis case(s) (2) case where input is of size n+1, assuming that postcondition is fulfilled when input is of size n. B. Iterative algorithms. (1) Determine an appropriate invariant. (2) (a) Show that invariant is true for basis case. (b) Show that, if invariant is always true, postcondition is fulfilled. (c) Show, by induction, that, if invariant is true for input of size n, it is also true for input of size n+1. Thank you! Best wishes, Amittai