gpt4 book ai didi

java - 我如何编写伪代码的递归函数?

转载 作者:行者123 更新时间:2023-12-01 14:41:01 34 4
gpt4 key购买 nike

实际代码更容易,但我也很难找到基本情况。我能够编写相当不错的伪代码,但我遇到了麻烦。我不知道我是否可以在这里问作业问题,但这是一个我无法回答的问题:

Let f(n) be the number of additions performed by this computation. Write a recurrence equation for f(n). (Note that the number of addition steps should be exactly the same for both the non-recursive and recursive versions. In fact, they both should make exactly the same sequence of addition steps.)

如果我不被允许问作业问题,任何帮助都会很棒。

   int sum(int A[], int n ):
T=A[0];
for i = 1; to n-1
T=T+A[i];
return T;}

最佳答案

使用 sum 函数的以下属性:

   sum(A[], n) == sum(A[], n-1) + A[n]

并考虑到:

   sum(A[], 1) == A[1]

关于java - 我如何编写伪代码的递归函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15958777/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com