Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Below is a snippet of code that relies on three methods: execA, execB, and exec. The worst, best, and average time complexity is given for
Below is a snippet of code that relies on three methods: execA, execB, and exec. 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); break; // O(n), Omega(log n), Thetan) case 5: execB(n); break; // O(n), Omega(n), Theta(n) default: exec(n); // O(n), Omega(n), 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
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