Best case of Insertion/Bubble sort (When Numbers are already sorted).

i.e O(n)

i.e O(n)

The Gateway to Computer Science Excellence

+4 votes

Which of the following is best running time to sort $n$ integers in the range $0$ to $n^2-1$?

- $O(\text{lg } n)$
- $O(n)$
- $O(n\text { lg }n)$
- $O(n^2)$

0 votes

Best time complexity is O(n).

Refer below link for reference

https://www.geeksforgeeks.org/sort-n-numbers-range-0-n2-1-linear-time/

0 votes

Using merge, heap sort will get O(nlogn)

But using radix sort will get in linear time only. O(n)

Reference : https://stackoverflow.com/questions/12042107/sort-n-numbers-between-0-n2-1-in-on

http://noteworthyalgorithms.blogspot.com/2014/03/sort-n-numbers-in-range-from-0-to-n2-1.html

52,345 questions

60,501 answers

201,872 comments

95,325 users