Discrete Maths: Verifying Recursive Algorithms (MO4, 5): you will repeat the same ideas as subsection 5.5.2 (list preconditions and postconditions, base case, inductive hypothesis, need to show, proof) for one or two of the following algorithms (please specify which one, notice that they are not the best algorithms for their problems but the idea is to illustrate recursion, not to get the best solution):
Algorithm for testing whether or not a number x is a natural number
Algorithm 4: Natural(a number x)
Input: A number x
Output: "Yes" if x is a natural number, else "No"
Algorithm:
if x < 1, then return "No"
else if x = 1, then return "Yes"
else return Natural(x - 1)
Preconditions:
Postconditions:
Base case:
Inductive hypothesis:
Need to show:
Proof: