Give an analysis of the running time BigO for the following
Give an analysis of the running time (Big-O) for the following code snippets: sum = 0; for (i = 0; i
Solution
A)O(n).
B)O(n2 )
C)O(n3 )
D)outer loop runs for n times, inner loop runs for 1,2,3,..n times. Time complexity is O(n2 ).
E)Outer loop1 runs for n times
Outer loop runs for 1,4,9,..n2 times.
Innerloop runs for1,4,9,...n2 times.
Therefore the time complexityO(n5 )
