Question: Linear Time Sorting Problem

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Thread Solved

Join Date: Mar 2007
Posts: 9
Reputation: Direwolf007 is an unknown quantity at this point 
Solved Threads: 0
Direwolf007 Direwolf007 is offline Offline
Newbie Poster

Question: Linear Time Sorting Problem

 
0
  #1
Mar 30th, 2007
Hello, I have been asked to provide an algorithm for the following:

You are given an array of length N, which contains values in the range from 0 to (N^2) - 1. You are to sort it in O(N) time.

I have been unable to find any way to do it, due to the lack of a "hard" upper bound on the input range (Which varies with the size of input).

I'll be happy to hear ideas for anyone who can offer help. Thanks !
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Question: Linear Time Sorting Problem

 
0
  #2
Mar 31st, 2007
My first thought was a radix sort, but since that does depend on the value of the largest number, I'm don't think that it's strictly O(N) in this case.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 9
Reputation: Direwolf007 is an unknown quantity at this point 
Solved Threads: 0
Direwolf007 Direwolf007 is offline Offline
Newbie Poster

Re: Question: Linear Time Sorting Problem

 
0
  #3
Mar 31st, 2007
I have tried Radix Sort, but since the number of digits is not fixed, it scales with size of input, due to that fact, in this case, the complexity would be O(nlogn), since log(base10)n is the amount of digits.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Question: Linear Time Sorting Problem

 
0
  #4
Mar 31st, 2007
Yeah, that's what I was thinking too. Even counting sort depends on the range of values, so it wouldn't fit either. I'm out of ideas, sorry
Last edited by Infarction; Mar 31st, 2007 at 6:53 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 9
Reputation: Direwolf007 is an unknown quantity at this point 
Solved Threads: 0
Direwolf007 Direwolf007 is offline Offline
Newbie Poster

Re: Question: Linear Time Sorting Problem

 
0
  #5
Apr 1st, 2007
Thanks for the reply, nonetheless.

If anyone else could chime in, I would be rather thankful.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Question: Linear Time Sorting Problem

 
-1
  #6
Apr 1st, 2007
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 9
Reputation: Direwolf007 is an unknown quantity at this point 
Solved Threads: 0
Direwolf007 Direwolf007 is offline Offline
Newbie Poster

Re: Question: Linear Time Sorting Problem

 
0
  #7
Apr 1st, 2007
While I thank you for the reply - I already read the wikipedia entry for that, twice. I also spent a few hours on google, and reading "Introduction To Algorithms" (One of the authors is Cormen, another is Rivest, another is Stein, I don't recall the last one).

Any other ideas folks ?
Last edited by Direwolf007; Apr 1st, 2007 at 9:57 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Question: Linear Time Sorting Problem

 
0
  #8
Apr 3rd, 2007
>> You are given an array of length N, which contains values in the range from 0 to (N^2) - 1. You are to sort it in O(N) time.

2 questions to understand the question:

1. Why does the range of value matter? (size/range of value would have no impact on the order of algorithm from what I know)
2. When you say "in O(N) time" do you mean it's an algorithm of order N or you really mean some number of mili/micro/seconds.. ?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Question: Linear Time Sorting Problem

 
0
  #9
Apr 3rd, 2007
1. It does affect algorithm runtime in several cases, especially when dealing with non-comparison based sorts (since it's proven that comparision based sorts cannot be guaranteed to run in better than O(n log n) time, they don't make the cut for this problem). Look at some of the sorts already mentioned in this thread.

2. Linear time with respect to the length of the input.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,649
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Question: Linear Time Sorting Problem

 
0
  #10
Apr 3rd, 2007
Have you tried out SmoothSort ?

Its best case is O(n) and worst case is O(n log(n)) with the obvious downfall of difficult to implement.
Last edited by ~s.o.s~; Apr 3rd, 2007 at 4:11 pm.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Computer Science Forum


Views: 6547 | Replies: 29
Thread Tools Search this Thread



Tag cloud for Computer Science
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC