Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following segments of code, determine their asymptotic (bigTheta) runtimes in terms of n. For part c, only give the runtime of mysteryThree(int n)

Given the following segments of code, determine their asymptotic (bigTheta) runtimes in terms of n. For part c, only give the runtime of mysteryThree(int n)

(a) public void mysteryOne(int n) { int sum = 0;

 for (int i = n; i >= 0; i--) { if ((i % 5) == 0) { 
 break; } else { 
 for (int j = 1; j < n; j*=2) { sum++; 

} }

} }

(b) public void mysteryTwo(int n) { int x = 0;

 for (int i = 0; i < n; i++) { for (int j = 0; j < (n * (n + 1) / 3); j++) { 

x += j; }

} }

(c) public void mysteryThree(int n) { for (int i = 0; i < n; i++) {

 printCats(n); } 

}

 public void printCats(int n) { for (int i = 0; i < n; i++) { 
 System.out.println("catsmoop"); } 

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions