Tutorial Week1 Thursday
Tutorial Week1 Thursday
Tutorial title: Running time of the loop execution of functions, Growth of functions
CO Mapping
Q2. For the following functions, determine how many times will the print() statement be executed? Give
your answer in terms of n.
(a)
fun(n)
{
for (i=n/2; i>=1; i--)
for (j=2; j<=n; j=j*2)
print(“Nested loop execution”);
}
(b)
fun(n)
{
for(i =1; i<=n2; i++)
for (j=n; j>=1; j=j/2)
print(“Nested loop execution”);
}
Q3. Let algorithms A and B have asymptotic running times TA(n) = 20n and TB(n) = 0.1nlog2n. For which
value of n does A outperform B?