+1 vote
90 views

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

quetion ask best case for any inplace sorting algorithm . Bubble sort will take O(n).

+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.

Best Case complexity of Bubble Sort is O(n).
+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