GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
75 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)   | 75 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 Apr 2017
  1. akash.dinkar12

    3514 Points

  2. Divya Bharti

    2546 Points

  3. Deepthi_ts

    2040 Points

  4. rude

    1966 Points

  5. Tesla!

    1768 Points

  6. Shubham Sharma 2

    1610 Points

  7. Debashish Deka

    1588 Points

  8. Arunav Khare

    1454 Points

  9. Kapil

    1424 Points

  10. Arjun

    1420 Points

Monthly Topper: Rs. 500 gift card

22,076 questions
28,042 answers
63,233 comments
24,135 users