Recursion
Consider the following algorithm:
RPM(n, m, sum)
- if n = 1 then
- return m+sum
- elseif n is even then
- return RPM(n/2, m*2, sum)
- else
- return RPM((n-1)/2, m*2, sum+m)
- [2 points] What does this algorithm do?
- [2 points] What is the measure of the input size for this algorithm?
- [2 points] What is the critical operation for this algorithm?
- [3 points] Provide a timing function directly related to the algorithm. (Include line numbers).
- [3 points] Derive a closed form of the timing function. (Show steps)
- [2 points] What is the performance class of this algorithm?