Question: Q1. [10 marks] Consider the algorithm BUBBLESORT shown below, where arr[i 1] arr[i] swaps the values of the given array elements and takes constant number
![Q1. [10 marks] Consider the algorithm BUBBLESORT shown below, where arr[i](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3d7457bb78_38866f3d744e2e62.jpg)
Q1. [10 marks] Consider the algorithm BUBBLESORT shown below, where arr[i 1] arr[i] swaps the values of the given array elements and takes constant number of basic operations. What is the worst case time complexity (using Big-Oh) of this algorithm? Justify your answer. Algorithm BUBBLESORT(arr, n) 1: if n arr[i] 5: arr[i-1] arr[i] 6: bubbleSort(arr, n - 1) = . Q2. [26 marks] Answer the following questions related to O(.), 2(.) and (.). (i). [8 marks] Let f(n) = 3 log2 n and g(n) Vn. Using the basic definition of O- notation, prove f(n) = O(g(n)) and g(n) # (f(n)). - (ii). [5 marks] What is the asymptotic (Big-Oh) complexity of the function g(n) = (na + nyn) (n + log n)? - (iii). [5 marks] What is the asymptotic (Big-Theta) complexity of the function g(n) = (n + 2n? + 3) (n + n^)? (iv). [8 marks] Let f(n) be an asymptotically nonnegative function. Using the basic definitions, prove that f(n) + Of(n)) = (f(n))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
