Consider the following algorithm. First, explain what exactly it computes. Then, use the 5 steps in the General Plan to analyze the time efficiency of the algorithm.
Algorithm 1: A pseudocode of an algorithm whose time efficiency is of interest
Data: a non-negative integer n
Result: to be answered by you
s ← 0;
for i ← 1 to n do
s ← s + i * i
end
return s
(Hint: Note that this is a non-recursive algorithm. So, follow the procedure in the General Plan for non-recursive algorithms.)
For each of the following recurrence relations, first, write down explicitly what sequence they represent, and then solve them.
a. x(n) = 3x(n − 1) for n > 1, with the initial condition x(1) = 5
b. x(n) = x(n/2) + n, for n > 1, with the initial condition x(1) = 1 (solve for n = 2^k)