

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


(a) for(i=0; i<n; i++) for(j=n/2; j>0; j -= 2) for(k=0; k<n; k++) A[i] = A[j] * A[k] (b) tmp = 0; while (tmp < n * n) { for (tmp2=0; tmp2<n; tmp2++) sum++; tmp++; } (c) for (i=1; i<nn i=i+2) for (j=1; j<nn; j=j+2) sum++; (d) for (i=1; i<nn i=i2) for (j=1; j<nn; j=j+2) sum++; (e) for (j=0; j < nn; j++) for(k=0; k<jj; k++) sum++; (f) tmp1 = n; while (tmp1 > 1) { tmp2 = 0; while (tmp2 < n/2) { tmp2++; } tmp1 = tmp1/ } (g) for (tmp1=0; tmp1<n; tmp1++) for(tmp2=0; tmp2 < tmp1; tmp2++) for(tmp3=1; tmp3<n; tmp3 = tmp33) sum++;
(a) int recursive1(int n) { sum = 0; for (int i = 1; i <= n; i++) sum++ if (n > 1) return sum + recursive1 (n-1); else return n; } (b) int recursive2(int n) { if (n > 1) return recursive2(n-1) + recursive2(n-1) + recursive2(n-1); else return n; } (c) int recursive3(int n) { if (n > 1) return 3 * recursive2(n-1); else return n; } (d) int recursive4(int n) { int no_op; if (n > 1) { for (i=1; i<=n; i++) { no_op++; } return recursive4(n/2) * recursive4(n/2); } else { return 1; } }