• 2021-04-14
    28 有如下递归函数fact(n),其时间复杂度为()。 int fact (i...turn(n*fact(n-1)); }
  • O(n)

    内容

    • 0

      已知函数Fact的程序如下,Fact(4)的值为_____。 1. Long Int Fact(int n) 2. { Long Int x; 3. If (n > 1) 4. { x = Fact(n-1); 5. return n*x; } 6. else return 1; 7. }

    • 1

      ()设有一个递归算法如下 int fact(int n) { //n大于等于0 ...fact(n)需要调用该函数的次数为(

    • 2

      已知函数Fact的程序如下,在执行Fact(4)的过程中,Fact函数被调用的次数为_____。1. Long Int Fact(int n)2. { Long Int x;3. If (n > 1)4. { x = Fact(n-1);5. return (n+x)*2; }6. else return 1;7. }

    • 3

      【填空题】下面程序段执行后,fact、sum的值分别是 、 int i,n,fact,sum; n=4; fact=1; sum=0; for(i=1;i<=n;i++) { fact=fact*i; sum+=fact; }

    • 4

      以下计算阶乘n!的函数fact,正确还是错误?def fact(n) if n == 0 : return 1 else: return n * fact(n-1)