Question: Problem 3 (25 points) Code analysis // A[l...n] is an array of n elements function fun (A[]) 1. Create new array temp [n] 2.

Problem 3 (25 points) Code analysis // A[1...n] is an array of n elements function fun (A[]) 1. Create new

Problem 3 (25 points) Code analysis // A[l...n] is an array of n elements function fun (A[]) 1. Create new array temp [n] 2. temp [1] A [1]; k=2; 3. for (i-2; i = sum (A, i)) temp [k] -A[i]; k++; 5. 6. 7. return temp [] 1. [15 points] Consider the algorithm shown above. a) (2 pts) What does the algorithm do? Justify your answer. b) (2 pts) What is the output of the algorithm on input array A = [1, 3, 5, 7, 15, 2, 4, 40, 50, 100]? c) (4 pts) Analyze the algorithm and determine its running time as a function of n. Use the Big-O() notation and consider the behavior of the algorithm on the worst possible input. d) (7 pts) Come up with a better algorithm for the same problem. For example if your algorithm in part (c) was (say) O(n), you should produce an algorithm that is strictly less than O(n), like O(n) or O(n), etc... while (i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

1 Given Algorithm Analysis a What does the algorithm do Explanation The algorithm processes an input array A of n elements and creates a new array tem... View full answer

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!