Re: [OT] stable algorithm with complexity O(n)
- From: "Diez B. Roggisch" <deets@xxxxxxxxxxxxx>
- Date: Sat, 13 Dec 2008 20:35:58 +0100
Duncan Booth schrieb:
"Diez B. Roggisch" <deets@xxxxxxxxxxxxx> wrote:
David HláÄ?ik schrieb:I think you must have fallen asleep during CS101. The lower bound for sorting where you make a two way branch at each step is O(n * log_2 n), but if you can choose between k possible orderings in a single comparison you can get O(n * log_k n).Hi guys,Unless I grossly miss out on something in computer science 101, the lower bound for sorting is O(n * log_2 n). Which makes your task impossible, unless there is something to be assumed about the distribution of numbers in your sequence.
i am really sorry for making offtopic, hope you will not kill me, but
this is for me life important problem which needs to be solved within
next 12 hours..
I have to create stable algorithm for sorting n numbers from interval
[1,n^2] with time complexity O(n) .
Can someone please give me a hint. Would be very very thankful!
Who has given you that assignment - a professor? Or some friend who's playing tricks on you?
To beat n * log_2 n just use a bucket sort: for numbers with a known maximum you can sort them digit by digit for O(n log_k n), and if you don't restrict yourself to decimal then k can be as large as you want, so for the problem in question I think you can set k=n and (log_n n)==1 so you get O(n)
Thanks. I *totally* forgot about that.
Diez
.
- References:
- [OT] stable algorithm with complexity O(n)
- From: David Hláčik
- Re: [OT] stable algorithm with complexity O(n)
- From: Diez B. Roggisch
- Re: [OT] stable algorithm with complexity O(n)
- From: Duncan Booth
- [OT] stable algorithm with complexity O(n)
- Prev by Date: Re: [OT] stable algorithm with complexity O(n)
- Next by Date: Bidrectional Subprocess Communication
- Previous by thread: Re: [OT] stable algorithm with complexity O(n)
- Next by thread: Re: stable algorithm with complexity O(n)
- Index(es):
Relevant Pages
|