What is the time complexity for the following function? (the basic operation is the innermost loop body's assignment).
function f(n)
r ← 0
m ← 1
for i ← 1 to n do
m ← 3 × m
for j ← 1 to m do
r ← r + j
return r
Multiple Choices:
Θ(n^3)
Θ(3^n)
Θ(n*log(n))
Θ(n)
Θ(n^2)
Let me rewrite it a bit:
So we have $$ \sum_{i=1}^n 3^i = \frac{3^{n+1} - 1}{3 - 1 } - 1 $$ evaluations of the inner loop.