GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
96 views

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

asked in Algorithms by Boss (8.7k points)   | 96 views
quetion ask best case for any inplace sorting algorithm . Bubble sort will take O(n).

2 Answers

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

answered by Active (1.3k points)  
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

answered by Junior (937 points)  


Top Users Aug 2017
  1. ABKUNDAN

    4670 Points

  2. Bikram

    4556 Points

  3. akash.dinkar12

    3420 Points

  4. rahul sharma 5

    3124 Points

  5. manu00x

    2864 Points

  6. makhdoom ghaya

    2450 Points

  7. just_bhavana

    2136 Points

  8. Tesla!

    2042 Points

  9. stblue

    1930 Points

  10. joshi_nitish

    1686 Points


24,970 questions
32,072 answers
74,567 comments
30,150 users