The original formula seems to give us a natural example of recursion:
Algorithm 1:
int fib(int n)
{
if (n == 0) return 0
if (n <= 2) return 1 // fine since a method only returns once so it will not do both if's
else return fib(n-1) + fib(n-2)
}
stop states (n = m and m = 0). Why?
Also, binomial base:
How am I sure I will get to a stop state?
For fun, you could prove by induction. :-)
A(m,n) =
TRY YOURSELF!!!!!
powerset(S) = {(), (a), (b), (c), (a,b), (a,c), (b,c), (a,b,c)}
The first "trick" is to try to define recursively.
What would be a stop state?
S = () has what powerset(S)?
How get to it?
Reduce set by one element
Consider taking an element out - in the above example, take out {c}
S = (a,b) then powerset(S) = {(), (a), (b), (a,b), }
What is missing?
powerset(S) = { (c), (a,c), (b,c), (a,b,c)}
Ackerman's function: A recursive algorithm
n+1 if m=0
A(m-1,1) if n=0
A(m-1, A(m, n-1)) otherwise
Powerset: A recursive algorithm
If S = (a, b, c) then the powerset(S) is the set of all subsets