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

标签 java discrete-mathematics

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

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/

相关文章:

java - 如何监视 Java EE 应用程序中的文件更改?

java - 在 Java 中解决我的快速排序算法的问题?

algorithm - 计算总组合

c - c如何计算余数?

java - 身份验证成功后,spring security HttpSession 为 null

java - 如何检查 JSONObject 中的值的类型?

java - 在多维数组中搜索字符串

lisp - 类似于图形但具有不同类型边的数学对象的名称是什么?

math - 哪里是复习数学的好地方?

math - 为什么 powerset 给出 2^N 的时间复杂度?