2 2 votes I answered this as $O(n^2)$ considering the question asks for best worst case of all inplace sorting algorithms. Algorithms sorting testbook-test-series + – thor 1.5k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments joshi_nitish commented Nov 21, 2017 reply Follow flag no, bubble sort in best case take O(n) time.. because bubble sort is only sorting algorithm which checks if array is already sorted to avoid unnecessary iterations. 1 1 replyShare rahul sharma 5 commented Nov 21, 2017 reply Follow flag I dont think that in standard implementation of bubble sort best case 0(n) is possible.However it can be modified to work in 0(n).Please correct me if wrong 0 0 replyShare ravi kant Gautam commented Apr 22, 2018 reply Follow flag Bubble sort takes O(n^2) in every case but insertion sort takes O(n) in the best case and insertion sort is an in-place algorithm. 0 0 replyShare Please log in or register to add a comment.
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. RAJESHWAR YADAV answered Nov 28, 2016 RAJESHWAR YADAV comment Share Follow See 1 comment 1 1 comment reply Arnab Bhadra commented Jun 20, 2017 reply Follow flag Best Case complexity of Bubble Sort is O(n). 0 0 replyShare Please log in or register to add a comment.
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 vamp_vaibhav answered May 30, 2017 vamp_vaibhav comment Share Follow 0 reply Please log in or register to add a comment.