In: Computer Science
Find the computational complexity i.e. O(n) etc. for the
following four loops and explain why you...
Find the computational complexity i.e. O(n) etc. for the
following four loops and explain why you came to that answer:
- for (cnt1 = 0, i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
cnt1++;
- for (cnt2 = 0, i = 1; i <= n; i++)
for (j = 1; j <= i; j++)
cnt2++;
- for (cnt3 = 0, i = 1; i <= n; i*=2)
for (j = 1; j <= n; j++)
cnt3++;
- for (cnt4 = 0, i = 1; i <= n; i*=2)
for (j = 1; j <= i; j++)
cnt4++