Question: ( 1 5 pts ) ( Running time complexity ) Find the running time complexity of the functions f ( n ) with nonnegative integer

(15 pts)(Running time complexity) Find the running time complexity of the functions f(n) with
nonnegative integer input n in the following pseudocode. Give the complexity in the form O(g(n))
for some function g(n), and choose a bound as tight as possible (e.g., if it is O(n3), then you
should write O(n3) instead of O(n4)). Justify your answers. Note that "a %b? computes the
remainder of a when divided by b, and "ab" returns whether ab.(Also note that the
time complexity of f(n) may or may not be the same as the value of f(n).)
(a)(5pts)
function f(n):
for i =1,,., n:
for j}=1,,i
print(i + j)
(b)(5pts)
function f(n):
if n=1:
return 1
else:
return (f(n-1)+f(n-1)+f(n-2))%10
(c)(5pts)
function f(n):
if n=1:
return 1
else:
a =0
for i =1,, n:
a =(a+i)%10
return (a + f(floor(n/2)))%10
Note that floor(n2 computes |??n2??|.
(Hint: Let the running time of f(n) be Tn. First compute T2k for integer k0. Then
prove by induction that Tn is nondecreasing, i.e.,TnTm for nm. Finally, we have
TnT2k where k=|~log2n~|log2n+1.)
( 1 5 pts ) ( Running time complexity ) Find the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!