Determine the running time of the following algorithm by analyzing each statement.…
- User
Determine the running time of the following algorithm by analyzing each statement. Express your final answer as a polynomial. Show work!
codeCost #Times executed Func1(n)1 s ← 0; ____ ______________________ 2 for i ← 2 to 6n^2 do ____ ______________________ 3 for j ← 3 to n do ____ ______________________ 4 for k ← 2 to n+1 do ____ ______________________ 5 s ← s + i - j + k; ____ ______________________ 6 end 7 end 8 end 9 return (s); ____ ______________________
Total Running Time:
- Assistant
Let's analyze the cost and the number of times each line of the algorithm is executed.
-
s ← 0;Cost: c1 (for the assignment operation) #Times executed: 1 Total Cost:c1 * 1 -
for i ← 2 to 6n^2 doCost: c2 (for the comparison and increment operations in the loop) #Times executed: (the loop runs from 2 to 6n^2, inclusive) Total Cost:
-