Question
Below is a snippet of code that relies on three methods: execA, execB, and execC. The worst, best, and average time complexity is given for
Below is a snippet of code that relies on three methods: execA, execB, and execC. The worst, best, and average time complexity is given for each of these functions.
int exec = random.nextInt(6); switch(exec) { case 0: execA(n); // O(n4), Omega(log n), Theta(n) break;
case 5: execB(n); // O(n4), Omega(n), Theta(n) break;
default: execC(n); // O(n3), Omega(n2), Theta(n*log n) }
Please answer the following: 1. [2 marks] What is the worst case Big-O for this code? Justify your answer. 2. [2 marks ] What is the best case Omega? Justify your answer. 3. [1 marks] Estimate average case Theta using your answer from 1 and 2. 4. [1 mark ] For answering question 3 you probably assumed an arithmetic mean (an average you are most familiar with). However, there are different kinds of averages. One alternative average is a geometric mean and is actually better suited for non-linear functions. Estimate average case Theta again but this time using a geometric mean. If you are unfamiliar with this formula you can get it here (click). 5. [2 marks] In this example, averaging Theta using best/worst isn't the preferred choice because you can analyze this code and get an exact answer for theta. What is the real average time complexity (Theta) for this code? Justify your answer.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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