in Algorithms
1,771 views
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
in Algorithms
1.8k views

2 Comments

merge sort ????
0
0
reason ?
0
0

1 Answer

2 votes
2 votes

4 Comments

can u explain the behaviour ?
0
0
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
0
A​nswer is Heap Sort..

And how r u taking  n/2 comparisons at each level in merge sort ?
0
0
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
0