The Gateway to Computer Science Excellence
+4 votes
382 views

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

  1. $O(\text{lg } n)$
  2. $O(n)$
  3. $O(n\text { lg }n)$
  4. $O(n^2)$
in Algorithms by
edited by | 382 views
0
Best case of Insertion/Bubble sort (When Numbers are already sorted).

i.e O(n)
+2
can we sort in lgn time ?  at best it may be O(n)

2 Answers

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/

 

 

by
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

by

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,501 answers
201,872 comments
95,325 users