14, Toad's data structure note of the 14 stack application stack and the recursive Ackerman function
This is the famous saying: " today is Life ----- is the only life you can know." "
Continue the recursive application, the Ackermann function.
Welcome reprint, Reproduced please indicate the source:
1. Ackermann functions
The Ackermann function (Ackermann) is an example of a non-primitive recursive function. It takes two natural numbers as input values and outputs a natural number. Its output value is growing at a very high rate, only the output of (4,3) is too large to be accurately calculated.
The Ackermann function is defined as follows:
If m=0, return to n+1.
If M>0 and n=0, return to Ackermann (m-1,1).
If M>0 and n>0, return to Ackermann (M-1,ackermann (m,n-1)).
In the late 1920, the mathematician David · Hilbert 's students Gabrielsudan and William Ackermann , at that time, was working on the basis of computation. Sudan invented a recursive, but not primitive, recursive Sudan function . In 1928, Ackerman came up with another recursive but not primitive recursive function.
His initial idea was a three variable function a (m,n,p), using the Conway chain Arrow notation to be m→n→p. Ackerman proves that it is a recursive function. Hilbert on the infinite conjecture that this function is not primitive recursion. Ackermann demonstrated this in on Hilbert's construction of the Real numbers.
Later Rozsa Peter and Raphael Robinson defined a similar function, but used only two variables.
2. Source Code
The implementation is as shown in 1:
#include <stdio.h>
#include <stdlib.h>
int Ackmann (intm,intn)
{
if (m==0)
return n+1;
Else if (m>0&&n==0)
return Ackmann (m-1,1);
Else
return Ackmann (m-1,ackmann (m,n-1));
}
int Main ()
{
intm,n,r;
printf (" input m and n:\ n");
scanf ("%d%d", &m,&n);
R =ackmann (m,n);
printf (" result is:%d\n", R);
System ("pause");
return0;
}
14, Toad's data structure note of the 14 stack application stack and the recursive Ackerman function