'Selection versus Merge Sorting Trouble
Suppose we have inefficient implementation of swap(a,b)(very costly) function and we are given the choice of four sorting algorithms to choose from, namely:
- merge-sort
- selection-sort
- insertion-sort
- heap-sort
Which one of the following four will perform the best ?
Now according to me as the swap is a costly operation we need to minimise the number of swaps. so technically the answer should be merge sort as it performs no swapping in its general implementation. But the answer-key suggests that it must be selection-sort instead ? I fail to understand why, please help.
Selection sort first finds the correct index and then swaps which is economical but doesn't merge sort perform better still ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
