Consider the following computational problems on an array of integers (of size n
ID: 3831547 • Letter: C
Question
Consider the following computational problems on an array of integers (of size n). Write down the running time for each problem using O-notation. Answer choices are: O(1), O(n), O(log n), O(n log n), O(n^2). No or justification is needed. Calculate the average of the values in the array ____ Sort the array using Quick sort (worst case) ____ Sort the array using Bubble sort (best case) ____ Find a value using binary search (array sorted, best case) ____ Find a value using binary search (array sorted, worst case) ____Explanation / Answer
1. Calculate the average of the values in the array:- O(n)
2. Sort the array using quick sort(worst case) :- O(n2)
3. Sort the array using bubble sort(best case) :- O(n)
4. Find a value using binary search(array sorted, best case):- O(1)
5. Find a value using binary search(array sorted, worst case):- O(log n)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.