Question: 3. This problem is about analyzing the runtime of iterative algorithms. Consider the following algorithms, which both take a positive integer n as input: ALG1(n):

 3. This problem is about analyzing the runtime of iterative algorithms.

3. This problem is about analyzing the runtime of iterative algorithms. Consider the following algorithms, which both take a positive integer n as input: ALG1(n): counter :=0 for i=1,...,n for j = i,...,1 counter := counter +1 for k= 1,...,3n counter := counter + 1 return counter ALG2(n): counter :=0 for i = 0,...,n for j = 1, ...,2 counter := counter +1 return counter that it basically keeps track of the runtime of The idea behind the counter variable the algorithm. For each algorithm: (a) First, give an exact formula for the return value, and then simplify it using big-O notation] (b) Next, give a big-O estimate of the runtime by first giving big-O estimates for the number of iterations of each loop and using identities involving big-O notation. Do you get the same answer? (Hint: for Alg2, you don't)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!