419 views
0 votes
0 votes

1 Answer

0 votes
0 votes

Insertion Sort.

As the size is small, we can neglect time complexity. Now we have to judge these algorithms based on the number of swaps and the number of comparisons.

  Number of Swaps Number of Comparisons

Insertion Sort

O(n) [Worst Case] O(n^2) [Worst Case]

Selection Sort

O(n) [Every Case] O(n^2) [Every Case]

Bubble Sort

O(n^2) [Every Case] O(n^2) [Every Case]

In best case number of comparisons performed by Insertion Sort is O(n)

Related questions

330
views
1 answers
0 votes
Mrityudoot asked Mar 7
330 views
For flag based approach in Bubble sort we can check first by a flag if the list is sorted or not in O(n), and if it is sorted, then no need to sort ... the same concept applicable to selection sort? Why it never comes down from O(n$^2$)?
618
views
1 answers
1 votes
Sajal Mallick asked Nov 28, 2023
618 views
Consider the problem that given a set Sof n integers and another integer x, whether or not there exist two elements in S whose sum is exactly x. What is the worst ... in dynamic programming? Then complexity should be O(n^2).How O(n logn)?
220
views
0 answers
0 votes
237
views
0 answers
0 votes
Sajal Mallick asked Nov 27, 2023
237 views
As we have to select maximal set of “non overlapping” activities. So like job scheduling algo of greedy we can solve it. So according to that complexity must be O(n logn). But ans is (b). Anyone please explain.