10 In the following program segment, the sentence frequency of x = x + 1; is (). for( i=1;i<=n;i++) for( j=1;j<=n;j++) x=x+1;
A. O(2n)
B. O(n)
C. O(n^2)
D. O(log2n)
查看答案
11 The time complexity of the following function sum (n) is ( ). sum (int n) { int sum=0; for(i=1;i<=n;i++) { p=1; for(j=1;j<=i;j++) p*=j; sum+=p; } return(sum); }
A. O(2n)
B. O(n)
C. O(n^2)
D. O(log2n)
12 There is the following recursive function fact (n), whose time complexity is( ). int fact (int n) { if(n<=1) return 1; else return(n*fact(n-1)); }
A. O(2n)
B. O(n)
C. O(n^2)
D. O(log2n)
13 After the following statement segment is executed, the value of i is () int f(int x) { return ((x>0) ? x* f(x-1):2); } int i ; i =f(f(1));
A. 2
B. 4
C. 8
D. Infinite recursion
4. If the address of the first element in a sequence table is base (index starts from 1), and each node accounts for M units, then the address of the ith node is ()
A. Base+(i-1)×m
B. Base+(i+1)×m
C. Base+i×m
D. Base-i×m