Question: Please Explain 2 1: sum 0 2: for 10 ton 3: prod = 1 4: for j = 1 to i 5: prod - a
2 1: sum 0 2: for 10 ton 3: prod = 1 4: for j = 1 to i 5: prod - a * prodx 6: sum = sum +prod 7: return sum All the questions in this exercise are related to the ComputeSumPowers (a,x,n) algorithm. The objective of this exercise is to explore whether the asymptotic time complexity will change if we count different "actions". A) (20 points) Comparison Action (Lines 2 and 4). In this case, we co the total number of comparisons performed by the "for loops statements" (Lines 2 and 4). Answer the following questions to determine the total number of comparisons performed by the algorithm a. (1 point) How many comparisons in total are performed by the "for loop" statement in Line 2 during the execution of the algorithm? The number of comparisons for the first loop should be n+1 b. (12 points) Let us call the number of comparsons performed by the "for loop" in Line 4 for a given value of L. Fill in this table (Justify how you find t only for i= 1 and i=n) ti 1 (n^2)+1 -the comparison is only going from 1 2 n+2 (n^2)+3 (n^2)+k (n^2)+n-this would be the same as the outer loop but for the n^2 loop -WN-- n c. (1 point) Based on b., express the total number of comparisons performed by the "for loop" in Line 4 only during the execution of the algorithm The total number of comparisons should be n because of second loop d. (5 points) Express the function f(n) that represents the overall total number of comparisons performed by the "for loops statements in Lines 2 and 4 during the execution of the algorithm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
