(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 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
Step: 1
Solution To prove a tight upper bound on the runtime o...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started