edited by
2,711 views
0 votes
0 votes

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 turned out to be B but D should the answer because it does not have any swap operatoin.?

edited by

2 Answers

1 votes
1 votes
Here The answer depends on the which algorithm has minimum number of swaps among these

And Among these ,selection sort has the minimum  number of swaping complexity =O(n) always

so Selection sort is preferable here

 

answer B
1 votes
1 votes
Brother, in that question, they are interested in No.of Swaps but not on Time Complexity...

Selection sort performs, one swap for each pass ===> For n passes, it performs only n swaps

MergeSort always copy the elements in to temp Array right ? Copying means one type of swap.

Related questions

0 votes
0 votes
0 answers
1
0 votes
0 votes
2 answers
2
dhruba asked Jun 5, 2023
1,150 views
Binary search is performed on a sorted array of n elements. The search key is not in the array and falls between the elements at positions m and m+1 (where 1 ≤ m < n). ...
0 votes
0 votes
0 answers
3
mdboi asked Oct 29, 2022
302 views
Hello, i have a algorithm and i want to prove it with induction how can i do that ?Also i want to worst case run time analyze but i am not very good please help me please...
1 votes
1 votes
1 answer
4