Deprecated: Implicit conversion from float-string "1578945502.391" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1578945502.391" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1578945502.391" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1578945502.391" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1578945502.391" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594
Test by Bikram | Mock GATE | Test 2 | Question: 17 / GATE Overflow for GATE CSE
retagged by
807 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

267
views
1 answers
1 votes
Bikram asked Jan 24, 2017
267 views
Which of the following sorting algorithms has the lowest best-case asymptotic algorithmic complexity?Selection sortMerge sortInsertion sortHeap sort
626
views
2 answers
1 votes
Bikram asked Jan 24, 2017
626 views
Why might quick sort be preferred over insertion sort and merge sort?The worst-case asymptotic algorithmic complexity of quick sort is superior to that of insertion sort ...
665
views
1 answers
0 votes
Bikram asked Feb 9, 2017
665 views
We write a new algorithm by considering the fact that number of comparisons required by Selection Sort can be reduced by considering elements in pairs and finding the min...
445
views
1 answers
3 votes
Bikram asked Jan 24, 2017
445 views
If $T$$\left ( 0 \right )$ $=$ $T$$\left ( 1 \right )$ $=$ $1$, each of the following recurrences for $n$ $\left ( \geq \right )$$2$ defines a function $T$ on the nonnega...
Total PHP MySQL Other RAM
Time (ms) % Time (ms) % File count Time (ms) % Query count Time (ms) % Amount %
Setup 4.1 3% 2.4 1% 72 1.5 1% 2 0.2 0% 569k 42%
Control 13.2 10% 1.6 1% 5 11.8 9% 12 0.0 0% 329k 24%
View 2.6 2% 2.6 2% 12 0.0 0% 0 0.0 0% 115k 8%
Theme 102.3 79% 4.8 3% 15 97.6 76% 3 0.0 0% 328k 24%
Stats 5.8 4% 0.1 0% 0 5.7 4% 1 0.0 0% 0k 0%
Total 128.0 100% 11.5 8% 104 116.7 91% 18 0.0 0% 1344k 100%