• edited by
2,702 views
4 4 votes

Consider the following statements:
S1  : On any random input insertion sort is work more efficiently than bubble sort.
S2  : Average number of comparison of insertion sort is better than bubble sort by constant factor.
If efficiency, is considered as number of comparison to sort an array [input], then which of the above statement is correct?

1 Answer

0 0 votes
S1 is false because for sorting in opposite order will take lot comparison compare to bubble sort.

S2 bubble sort has avrage n-1, n-2, n-3, --------1 comparison total aprox O((n-1)(n)+n-1)/4 and total O((n^2+n)/4) in insertion sort. show it's true.
Position:
Show:

Related questions

4 4 votes
4 answers 4 answers
4.9k
4.9k views
Ramij asked Dec 20, 2018
4,873 views
Suppose there are 4 sorted list of 16 elements each. If we merge these lists into a single sorted list of 64 elements. The key comparisons that are needed in the worst ca...
0 0 votes
1 1 answer
5.1k
5.1k views
Rajat Agrawal007 asked Dec 17, 2018
5,135 views
Which of the following input will give best case time for selection sort?(A) 1 2 3 4 5 6 7 8 9 10(B) 2 3 1 5 9 7 8 6 10(C) 10 9 8 7 6 5 4 3 2 1 (D) All of above take same...
0 0 votes
2 2 answers
1.3k
1.3k views
naveen81 asked Jan 30, 2017
1,254 views
a. i>0,K>0, a[K] a[max]b. i>0,K<0, a[K]< a[max]c. i<0,K>0, a[K] a[max]d. i>0,K>0, a[K]< a[max]
3 3 votes
4 4 answers
2.5k
2.5k views
newdreamz a1-z0 asked Jan 21, 2019
2,487 views
Consider a scenario of modified quick sort, where we have given an input sorted array A[1 .. . n], all elements of array are distinct and n >=3. Pivot is the median of se...