GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
73 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.6k points)   | 73 views
quetion ask best case for any inplace sorting algorithm . Bubble sort will take O(n).

1 Answer

0 votes

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)  


Top Users Mar 2017
  1. rude

    4018 Points

  2. sh!va

    2994 Points

  3. Rahul Jain25

    2804 Points

  4. Kapil

    2606 Points

  5. Debashish Deka

    2092 Points

  6. 2018

    1414 Points

  7. Vignesh Sekar

    1318 Points

  8. Bikram

    1218 Points

  9. Akriti sood

    1166 Points

  10. Sanjay Sharma

    1004 Points

Monthly Topper: Rs. 500 gift card

21,439 questions
26,753 answers
60,919 comments
22,929 users