View the step-by-step solution to:

Question

Screen Shot 2019-02-19 at 01.50.30.png

For this question, I am

mainly struggling with how to account for runtime with ticker.tick. Would one call of for loop need a ticker.tick statement before as well as within the loop? For example for part b, I thought about adding ticker.tick() to (C), however, the bottom line which has ticker.tick(n) would be wrong because it would only need one call of ticker.tick().


Thank you for help in advance!!

Screen Shot 2019-02-19 at 01.50.30.png

5. (17 points) Consider the following two Java methods, each of which contains ticker . tick () or
ticker . tick (int k) calls similarto those available in our class code infrastructure: void ftint n) {
ticker.tick();
for(int izo; i < n; i++) {
fortint j=0; j < n; j++) {
// (A)
ticker.tick();
} void gtint n) {
ticker.tick(); // (B)
for(int i=0; i < n; i++) {
// (C) }
ticker.tick(n); a. (8 pts) Which of the two methods' asymptotic runtimes are correctly accounted for by its
calls to ticker. tick? Mark one of the options below. Only method f is correctly accounted for.
Only method g is correctly accounted for.
Both runtimes are correctly accounted for.
Neither runtime is correctly accounted for. b. (6 pts) Consider each proposed change to the method g listed below. If the change
were made, would the asymptotic runtime of g be correctly accounted for? Mark all for
which the answer is yes. _ Delete the statement marked by comment (B).
_ Add the statement ticker . tick (n) in place of comment (C) . _ Add the statement ticker . tick () in place of comment (C) . c. (3 pts) What would be the asymptotic runtime of method f if comment (A) were replaced
by the statement gin);
? Answer: 0( )

Top Answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question