• retagged by
1,498 views
2 2 votes

I answered this as $O(n^2)$ considering the question asks for best worst case of all inplace sorting algorithms.

2 Answers

1 1 vote

O(n) is right 

BEST CASE OF INSERTION SORT

The best case input is an array that is already sorted. In this case insertion sort has a linear running time (i.e., O(n)). During each iteration, the first remaining element of the input is only compared with the right-most element of the sorted subsection of the array.

1 1 vote

Bubble sort, as well as Insertion sort both, will give o(n) in its best case: in bubble sort assumption is made that the passes will be stopped on the same instance when the elements are sorted. While in Insertion sort assumption is that the elements are already sorted or almost sorted

Position:
Show:

Related questions

0 0 votes
2 2 answers
1.9k
1.9k views
2 2 votes
1 answers 1 answer
1.1k
1.1k views
Raj_Choudhary asked Nov 22, 2017
1,062 views
Suppose in an array A[] , we exchange elements A[i] and A[i+k] , which were originally out of orderA) at least 1 and at most 2k-1 inversions are removedB) at least 2 and ...
9 9 votes
6 6 answers
4.0k
4.0k views
Arjun asked Feb 27, 2025
3,980 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...
1 1 vote
1 1 answer
147
147 views
GO Classes asked Aug 25
147 views
Let $P$ be the problem of sorting $n\geq1$ elements using only comparisons.Consider the class of all comparison-based algorithms that correctly solve $P$.What is the asym...