Homework 3: Running Times
Due: Thursday, October 5, 8:59:59pm
Instructions: In each of the five questions below, you are given a program fragment. Estimate the running time for each program fragment in terms of n. Assume that the value of n is determined elsewhere in the program. You should make your upper bound and lower bound as tight as you can. Upper bounds that are too big and lower bounds that are too small will receive deductions during grading.
For each question:
- State an upper bound on the running time of the program fragment using O( ) notation.
- Briefly justify your upper bound.
- State a lower bound on the running time of the program fragment using Ω( ) notation.
- 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.)
What to turn in: Type in your responses in a single plain text file called hw3.txt and place it in your hw3 submission directory on GL. Remember that flex days do not apply to homework assignments. Type Omega() for Ω() and n^2 for n2.
Question A
In this question, the program fragment resides in the main() function. The program fragment calls a function dothis(). In your running time estimates, include the time to execute the program fragment in main() and the time to execute the function calls.
Question B
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.