I have this subalgorithm on recursion and I know that it's called 5 times, but I don't understand why. The initial values are m=1, n=2.
I've thought the function is called for 7 times.
int Ack(int m, int n)
{
if (m==0)
return n+1;
else
{
if (m>0 && n==0)
return Ack(m-1,1);
else
return Ack(m-1,Ack(m,n-1));
}
}
I expect that it's called 7 times or even more, but the actual number is 5.
This how 7 is arrived at:
您重复计算了 2 个调用:#7 与 #4 相同,#8 与 #2 相同(仅显示Ack
返回的值):“回来”与调用不同。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.