5 5 votes Which of the following statements is/are correct?A.Merge sort always has more number of swaps that comparisonsNumber of comparisons in partition algorithm are same for best case and worst case.C.Quick sort is an inplace algorithm while merge sort is an out place algorithm.D.None of these Algorithms algorithms goclasses goclasses-algorithms-practice-questions usermod + – Akash t 607 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes both the oprtions B and C are correct Vikash 1 answered Jun 17 Vikash 1 comment Share Follow See 1 comment 1 1 comment reply Akash t commented Jun 17 reply Follow flag Thanks for answering the question, but it would have been better if you had provided a detailed reason. 0 0 replyShare Please log in or register to add a comment.
0 0 votes A) Merge sort processes elements by diving and merging. It does not always perform more swaps than comparison. In fact, standard merge sort moves elements to another array rather than performing traditional element swaps. So A is False.B) The total number of comparisons in the partition process depends entirely on how evenly the array is partitioned. In best case, array can be partitioned into two equal halves, creating balanced tree that require very few total comparisons (O(nlogn)).In worst case, the array may get split unevenly that forces the entire array to compared over and over again.(O($n^{2}$)). So B is False.Note that if single partition routine is performed, then the number of comparisons remains same in best and worst case.C) Merge sort uses an extra array to combine two subarrays. So it is not an inplace algorithm. Quicksort just picks a pivot and place it into its right position (no extra space). So C is True. divakshusharma answered Aug 3 • edited Aug 3 by divakshusharma divakshusharma comment Share Follow See 1 comment 1 1 comment reply sanskarlsverma commented Sep 5 reply Follow flag To partition an array of size n, you have to compare every single element against the pivot to see which side it belongs on. That always takes exactly n - 1 comparisons, whether that split ends up being a perfect best-case or a terrible worst-case. The partition step itself does the exact same amount of work either way. 0 0 replyShare Please log in or register to add a comment.