how to calculate the time and space complexity of this nested recursive function

☆樱花仙子☆ 提交于 2020-07-03 12:57:11

问题


#include <stdio.h>
int fun(int n)
{
 if(n>100)
 return n-10;
 return fun(fun(n+11));
}
int main()
{
 int r;
 r=fun(95);
 printf("%d\n",r);
 return 0;
}

the answer says time complexity is O(n), can anyone explain how?

来源:https://stackoverflow.com/questions/62381491/how-to-calculate-the-time-and-space-complexity-of-this-nested-recursive-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!