Need help on C and D. Thank you!
4:264
piazza-resources.s3.amazonaws.com
5 of 5
6. Consider the algorithm func6i(n) which in turn calls functions fz(n), f4(n), and fs(n) which have actual running times of (n^2), (n^3), (n), and (n) respectively.
def func6in:
if 0 == (n mod 4):
return fn
# Do something (n^2)
end if
if 1 == (n mod 4):
return fsn
# Do something n
end if
if 2 == (n mod 4):
return fn
# Do something (n*)
end
if 3 == (n mod 4):
return fn
# Do something (n/)
end
end
In the above function, (n mod 4) denotes the remainder after dividing n by 4.
(a) What is the best-case asymptotic running time for the above function? Note that since I am asking for the best case, you may assume n is restricted to the class of input that makes the above algorithm run the fastest. For this class of input, the algorithm runs in time (something). Explain your answer.
(b) Analogously, what is the worst-case asymptotic running time?
(c) Give the best possible upper bound on the asymptotic running time for arbitrary n. This should be denoted with O(), Θ(), or Ω() (as appropriate). Explain your answer.
(d) Analogously, give the best possible lower bound on the asymptotic running time for arbitrary n.