0 votes 0 votes If input is sorted in reverse order , then which sorting algorithm will perform best - A) Insertion Sort B) Merge Sort C) Heap Sort D) Quick Sort Algorithms sorting algorithms normal + – Himanshu1 asked Jan 17, 2016 Himanshu1 1.8k views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply shivanisrivarshini commented Jan 17, 2016 reply Follow Share merge sort ???? 0 votes 0 votes Himanshu1 commented Jan 17, 2016 reply Follow Share reason ? 0 votes 0 votes Please log in or register to add a comment.
2 votes 2 votes C) HeapSort Reference:http://www.sorting-algorithms.com/reversed-initial-order Prasanna answered Jan 17, 2016 Prasanna comment Share Follow See all 4 Comments See all 4 4 Comments reply Himanshu1 commented Jan 17, 2016 reply Follow Share can u explain the behaviour ? 0 votes 0 votes Deepesh Kataria commented Jan 21, 2016 reply Follow Share HERE THE ANALYSIS-ALL ARE COMPARISON BASED SORTING ....BEST CASE is n*logn... here its strict reverse order. 1.INSERTION SORT- would take O(n^2)...swapping the element take n^2 times . 2.QUICK sort - take here O(n^2)...due to unbalanced tree form at each step.tree would have height n with n(n-1)/2 comparisons in total 3 .HEAP sort - take always O(n*logn){balancing tree take logn and it happens for n elements} 4.MERGE sort - take here O(n/2*logn) at each level n/2 comparisons ...and its done for logn height of tree.... SO BEST HERE IS MERGE SORT 0 votes 0 votes Himanshu1 commented Jan 21, 2016 reply Follow Share Answer is Heap Sort.. And how r u taking n/2 comparisons at each level in merge sort ? 0 votes 0 votes Deepesh Kataria commented Jan 21, 2016 reply Follow Share https://www.youtube.com/watch?v=ZZuD6iUe3Pc ...WATCH IT and pause at 2:18 ...and see which is better in reversed order ....MERGE OR HEAP ....try ur brain ...man!! 0 votes 0 votes Please log in or register to add a comment.