retagged by
10,383 views
1 1 vote

Q) Consider a situation where swap operation is very costly.

Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general?

(A) Heap Sort

(B) Selection Sort

(C) Insertion Sort

(D) Merge Sort

The Answer Given for This Question is (B). But My question is Why not (D) Since There is not a Single Swap operation is performed in Merge Sort.

1 Answer

1 1 vote
In general , to minimise the number of swaps we use the selection sort bcoz everytime when we compare the elements of the array with the initial element we find the minimum element than the initial and do only one time swap it with the previous initial one.therefore the number of swaps is O(1) for every element and O(n) for n elements

whereas in merge sort there could be more than one swap at a time when we combine the two sorted arrays there could be possibility of getting more than one swap eg:{2,4,6} and {3,5,8}
Position:
Show:

Related questions

1 1 vote
1 1 answer
965
965 views
thor asked Nov 23, 2016
965 views
0 0 votes
1 1 answer
2.2k
2.2k views
ARUN KUMAR 3 asked Sep 6, 2017
2,169 views
Let G be the CFG, l be the number of left most derivations, r be the number of right most derivations and P be the number of parse trees. Assume l , r and P are computed ...
0 0 votes
2 answers 2 answers
1.5k
1.5k views
Rustam Ali asked Sep 3, 2018
1,452 views
Find time complexity of below Program?A(n){if(n<=1) return;elsereturn $A(\sqrt{n})$ ;}
2 2 votes
1 answers 1 answer
3.8k
3.8k views
Rishav Kumar Singh asked Jun 15, 2018
3,774 views
Which data structure is most efficient to find the top 10 largest items out of 1 million items stored in file?AMin heapBMax heapCBSTDSorted array