Question: (a) Consider the following pseudocode: 1 // Assume n is a positive integer 2 for i:= 1 to n do 3 for j=1 to

(a) Consider the following pseudocode: 1 // Assume n is a positive integer 2 for i:=1 to n do 3 for j = 1 to(b) Prove a tight upper bound on the following pseudocode using summations, as above: 1 // Assume n is a

(a) Consider the following pseudocode: 1 // Assume n is a positive integer 2 for i:= 1 to n do 3 for j=1 to n do // ... Some constant time operations... To formally prove a tight upper bound on the runtime of this code, we can represent the number of steps it executes as a function of the input size n with summations. Say the total cost of the constant time operations in the inner loop is some positive constant c. The total runtime of this code will then be 1=1c. We can simplify this summation as 1 =1= =1 en = cn?. If no = 1 and c is our constant, then clearly cn = O(n), so this gives us a tight upper bound on the runtime of this nested loop. Prove a tight upper bound on the following pseudocode using summations, as above: 1 // Assume n is a positive integer 2 for i:= 1 to n do 3 for j=1 to i do // ...Some constant time operations... (b) Prove a tight upper bound on the following pseudocode using summations, as above: 1 // Assume n is a positive integer 2 for i:= 1 to n do 3 for j = i to n do // ...Some constant time operations... Note that j now goes from i to n.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Solution To prove a tight upper bound on the runtime o... 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!