下列程序段的时间复杂度是( )。for (i=1; i<=m1; ++i) for (j=1; j<=n2; ++j) Q[i][j] = 0;for (i=1; i<=m1; ++i) for (j=1; j<=n2; ++j) for (k=1; k<=n1; ++k) Q[i][j] += M[i][k] * N[k][j];[/i][/i][/i]
A: O(m1*n2)
B: O(m1*n2*n1)
C: O(m1+n2*n1)
D: O(m1*n2+n1*n2)
E: O(m1*n2+n1*n2+m1*n1)
A: O(m1*n2)
B: O(m1*n2*n1)
C: O(m1+n2*n1)
D: O(m1*n2+n1*n2)
E: O(m1*n2+n1*n2+m1*n1)
举一反三
- 下面程序段的时间复杂度为( )。for(i=0;i<n;i++) for(j=0;j<m;j++) A[i][j]=0;[/i] A: O(n*m) B: O(n^2) C: O(m^2) D: O(1)
- 求时间复杂度:for(i=0;i<m; i++){ for(j=0; j<n; j++){ s+=B[i][j]; }}sum=s;[/i] A: O(1) B: O(m*n) C: O(n^2) D: O(√n )
- 请问以下方法的时间复杂度是多少?int n = 10;for (i = 1; i < n; ++i) { for (j = 1; j < n; j += n / 2) { for (k = 1; k < n; k = 2 * k) { x = x + 1; } }} A: O(n^3) B: O(n2logn) C: O(n(logn)*2) D: O(nlogn)
- 下列程序输出结果是:() int i,j,m,n; m=n=0; for(i=0;i[2;i++) for(j=0;j<2;j++) if(j]=i)m=1;n++; printf("n=%d\n",n); A: 4 B: 3 C: 2 D: 1
- 有如下程序段: Dim i%, j%, n%, m%, k% m = 0 : k = 0 For i = 1 To 5 k = k + 1 n = 0 For j = 1 To 2 n = n + 1 m = m + 1 Next j Next i MsgBox(k & " " & n & " " & m)运行该程序代码段后,消息对话框中显示的内容为( )。 A: 5 10 2 B: 5 10 10 C: 5 2 10 D: 5 2 2