retagged by
814 views
6 votes
6 votes
  • A Multinational software vendor needs to choose two sorting algorithm implementations $S1$ and $S2$ to built a software for it's offshore clients.
  • $S1$ will be used in situations where item exchanges cost nothing but item comparisons remain expensive. Conversely, $S2$ will be used in situations where item comparisons cost nothing but item exchanges remain expensive.
  • Suppose the vendor can only use the insertion, selection, or bubble sorts for these implementations,  and suppose the vendor only cares about average-case asymptotic algorithmic complexity.

Which algorithm should the vendor use for each implementation?

  1.   Bubble sort for $S1$ and insertion sort for $S2$.
  2.   Insertion sort for $S1$ and bubble sort for $S2$.
  3.   Selection sort for $S1$ and insertion sort for $S2$.
  4.   Insertion sort for $S1$ and selection sort for $S2$.
retagged by

2 Answers

Best answer
2 votes
2 votes

Question says AVERAGE CASE time complexity only to consider .

Selection sort uses about (N/ 2 ) comparisons and N exchanges on average.

Insertion sort uses about ( N2/4) comparisons and (N/ 8) exchanges on average.

Bubble sort uses about (N/ 2) comparisons and ( N/ 2) exchanges on average.


So if exchanges cost nothing and only comparisons count, then insertion sort way better than the others.

If exchanges count but comparisons cost nothing, then selection sort beats the others  asymptotically.

Hence they need to use Insertion sort for S1 and Selection sort for S2.

selected by
1 votes
1 votes
Selection Sort for (S2) as we know has least number of items exchanges (order of N) ,Exchange happens only once while pushing the maximum towards end in every iteration . So we can use Selection sort where the item exchanges are expensive.

Insertion sort for (S1), is good when we know the comparisions are costly because it just tends to compare only the element at the end of sorted subarray. In the best case as we know it might even lead to O(n) comparisions.
Answer:

Related questions

1 votes
1 votes
1 answer
1
Bikram asked Jan 24, 2017
274 views
Which of the following sorting algorithms has the lowest best-case asymptotic algorithmic complexity?Selection sortMerge sortInsertion sortHeap sort