Name and ID This eram bon qar 1p I. Opts) The complexity of the merge procedure
ID: 3716150 • Letter: N
Question
Name and ID This eram bon qar 1p I. Opts) The complexity of the merge procedure used by Merge Sont is ?(nlogn) O(n") C. D. 2. Opts) When the input is already sorted the complexity of insertion sort is C. ?( n log n) D. ?(n2) 3. (3pts) When the input is already sorted the complexity of bubble sort is B. ?(n) C. ?(n log n) 4. (3pts) When the input is already sorted the complexity of Merge Sort is B. ?(n) D. ?(n2) 5. (3pts) When the input is already sorted, and we always use the last element as the pivot, the complexity of Quicksort is B. ?(n) C. ?(n log n)Explanation / Answer
1.Ans-:B).O(n),,The merge function does a constant O(1) number of operations for each element in the list. The list size is O(n) since there are n elements. Merge does a constant amount of work O(n) times, hence time complexity of merge procedure is O(n).
2..Ans-: B.)O(n),,Whenever a new element which will be greater than all the elements of the intermediate sorted sub-array ( as given array is sorted) is added, there won’t be any swap but a single comparison. In n-1 passes we will be having 0 swaps and n-1 comparisons.
Total time complexity for insertion sort if arrzay is sorted = O(n)
3.Ans-: B.)O(n) ,if Array is sorted order, we could modify Bubble Sort the Inner for loop which is responsible for bubbling the kth largest element to the end in kth iteration. Whenever there is no swap after the completion of inner for loop of bubble sort in any iteration, we can declare that array is sorted in case of Bubble Sort taking O(n) time in Best Case.
4.Ans-:C.)O(nlogn) as Merge Sort works on Divide and Conquer paradigm to sort an array and hence there is no such worst or best case input for merge sort. For any sequence, Time complexity is
T(n) = 2T(n/2) + ?(n) // In-Place Merge algorithm will take ?(n) due to copying an entire array.
= ?(nlogn)
5.Ans-:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.