请问谁有Ackermann函数的递归和非递归的源程序

TESTMYACM 2005-12-16 04:45:15
请问谁有Ackermann函数的递归和非递归的C语言源程序
谢谢
...全文
307 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mmmcd 2005-12-17
  • 打赏
  • 举报
回复
这个函数值增长如此迅速,想实现什么方面的计算问题?
TESTMYACM 2005-12-17
  • 打赏
  • 举报
回复
jp1984(compiler)
如果要用递归实现
double ack_recurve(int n,int m)
{
if (m == 0)
return n+1;
else if (n==0)
return ack_recurve(m-1,1);
else if(n!=0)
return ack_recurve(m-1,ack_recurve(m,n-1));
}
这样写不可以么
TESTMYACM 2005-12-17
  • 打赏
  • 举报
回复
jp1984(compiler)
如果要用非递归实现
怎么写代码呢
jp1984 2005-12-17
  • 打赏
  • 举报
回复
那样写一样的/


ackerman函数不是原始递归的,所以不要想通过找通式来构造非递归算法,
所说的非递归只是设个两维数组用循环模拟下. 类似于fibonacci
TESTMYACM 2005-12-17
  • 打赏
  • 举报
回复
mmmcd(超超0
只是偶尔看到这个题目
jp1984 2005-12-16
  • 打赏
  • 举报
回复
double ack_recurve(int n,int m)
{
if (n == 1 && m == 0)
return 2;
else if (n >= 2 && m == 0)
return n + 2;
else if (n == 0 && m >= 0)
return 1;
else if(n >= 1 && m >= 1)
return ack_recurve(ack_recurve(n-1,m),m -1);
}
递归的,算到ack(1,4)基本上不行了.
jp1984 2005-12-16
  • 打赏
  • 举报
回复
The significance of this function is that it can be proved to be a recursive
function of two variables. Thus, in particular, a(x,x) is recursive. But it
can also be shown that a(x,x) is not primitive recursive. (The difference
between recursive and primitive recursive is that computation of a recursive
function may, in general, involve a finite but unbounded search for a solution
to an equation involving recursive functions. In the case of primitive
recursive functions there must be an a priori primitive recursive upper bound
on the number of steps in the search.)

Ackermann's function grows so quickly, especially in the y variable, that it
is completely infeasible to calculate it for more than a few small values of
y. For example, things really begin to blow up in the calculation of a(1,4).

At the outset, it is not even clear that the above equations define a function,
i.e., that the recursions will ever end. Let us begin by proving by induction
that this will indeed occur. We induct on y, and then on x for each fixed y.
(This is typical of arguments involving a.) The case y = 0 is obvious, so
we assume the following outer inductive hypothesis:

(i) The recursive depth calculating a(x,y) is finite, for every x.

(By recursive depth, we mean the total number of times "a" must be written
in successive applications of the 3 rules until a call with y = 0 occurs.)

We wish to show: the recursive depth calculating a(x,y+1) is finite for every
x. This we do by induction on x. If x = 0, then a(x,y+1) = a(1,y), and the
result follows by inductive hypothesis (i). Let us now make inductive
hypothesis (ii):

(ii) The recursive depth calculating a(x,y+1) is finite, for a given x.

There remains to show: the recursive depth calculating a(x+1,y+1) is finite.
Now a(x+1,y+1) = a(a(x,y+1),y). By (ii), a(x,y+1) is computable. Call its value
N. Then a(N,y) is computable by (i), since (i) holds for every x, in particular
for x = N.
jp1984 2005-12-16
  • 打赏
  • 举报
回复
A(0, j)=j+1 for j ≥ 0
A(i, 0)=A(i-1, 1) for i > 0
A(i, j)=A(i-1, A(i, j-1)) for i, j > 0

33,028

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧