14, Toad's data structure note of the 14 stack application stack and the recursive Ackerman function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.