Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Estimate the running time for the following program fragment in terms of n . Ass

ID: 3585349 • Letter: E

Question

Estimate the running time for the following program fragment in terms of n. Assume that the value of n is determined elsewhere in the program. Make your upper bound and lower bound as tight as you can.

Please answer the following 1. State an upper bound on the running time of the program fragment using O0 notation Briefly justify your upper bound. 2. State a lower bound on the running time of the program fragment using notation 3. 4. Briefly justify your lower bound. Even in cases where the upper bound and lower bound are the same function, the justifications would be different. (For upper bounds, you are claiming that the code will run no slower than the upper bound. For lower bounds, you are claiming that the code will take at least that amount of time.) Question 1: In this question, the program fragment resides in the main) function. The program fragment calls a function loop (). In your running time estimates, include the time to execute the program fragment in main) and the time to execute the function calls int loop(int x) / function definition outside main() at something = 0 something+ return something 1/ in the main) function um-sum +loop (3)i um-sum +loop (5)i

Explanation / Answer

function loop's running time depends on the for loop which runs x times. Since, in main function, function loop is calling for constant values of x i.e., 3 and 5. therefore, time taken by the complete program is constant. i.e., big-oh = big-omega = big-theta = O(1).

Hope it helps, do give your valuable response.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote