算法设计与分析作业2 🌻🌻🌻
学号:2020011181
The first question🍀🍀
1. 采用特征方程方法求解以下递归方程:
H (0)=0 H (1)=1 H (2)=2
H ( n )= H ( n - 1)+9 H ( n - 2) - 9 H ( n - 3) 当 n >2
解析:
参考链接:http://t.csdn.cn/uEiYl
The second question:🍀🍀
分析求斐波那契 f(n) 的时间复杂度。
解析:
The third question:🍀🍀
对于一个采用字符数组存放的字符串 str,设计一个递归算法求其字符个数(长度)。
代码:🌝🌝🌝
#include <stdio.h>
int length(char *a){
if(*a == '\0')
return 0;
else
return 1+length(a+1);
}
void main(){
char a[]="abcd";
int len;
len=length(a);
printf("字符串长度为:%d\n",len);
}
结果:👀👀
Tha's the end~thank you for reading it ~wish you good luck*