[algogeeks] Re: Sorting Array

2011-06-29 Thread 991
Radix sort can solve the problem in O(N) time. Max. value of input is N^2 so in binary representation, we need d = 2(logN)+1 digits to represent each number. ( It is O(logN) - thats the key) Now group logN bits ( say r = logN ) The maximum value in each group is O( 2^r) This is the base in which

[algogeeks] Re: Sorting Array

2011-06-28 Thread L
There is one way in which we can do O(n). Convert the numbers in base 'n'. [ O(n) ]. Now, there are 2-digit numbers, each digit ranging from 0 to n-1. You can call count-sort 2 times (for each digit), so, complexity is O(n +n) =O(n). On Jun 27, 12:22 am, Dan dant...@aol.com wrote: Your question

[algogeeks] Re: Sorting Array

2011-06-26 Thread ross
@radhakrishnan: Counting sort in this case, will be O(n2).. as it involves traversing the entire array! On Jun 26, 5:03 pm, L prnk.bhatna...@gmail.com wrote: Count sort is O(n+k), since k~n^2 here, it will be O(N^2). Radix sort has complexity O(r.n) which is nearly O(n logn). Are you sure that

[algogeeks] Re: Sorting Array

2011-06-26 Thread ross
@L: It was asked if we could take advantage of the ranges of the integers between 1-N^2.. I doubt if its possible. On Jun 26, 5:33 pm, ross jagadish1...@gmail.com wrote: @radhakrishnan: Counting sort in this case, will be O(n2).. as it involves traversing the entire array! On Jun 26, 5:03 pm,

Re: [algogeeks] Re: Sorting Array

2011-06-26 Thread Rujin Cao
@ross: I guess the orignal problem is that there are N numbers which are all in the range [1, N * N], can you do the sorting in O(N) time complexity? If this is true, we can firstly do the discretization and then do the counting sort. -- You received this message because you are subscribed to

[algogeeks] Re: Sorting Array

2011-06-26 Thread ross
@Rujin Cao: Yea, your formulation of the problem is correct.. my bad,. missed that there are N numbers. can u elaborate more on the discretization procedure and how ll u do counting sort (which might warrant traversing of N^2 elements) On Jun 26, 5:45 pm, Rujin Cao drizzle...@gmail.com wrote:

Re: [algogeeks] Re: Sorting Array

2011-06-26 Thread Rujin Cao
@ross: It seems that after discretization , the time complexity still would be O(nlogn). The discretization idea is: say there are 4 numbers, each of them is in the range[1, 16]. e.g. 12 3 12 15 You can do one time transverse to map each of them to a global increasing index (hashing is the

Re: [algogeeks] Re: Sorting Array

2011-06-26 Thread DK
Use a radix sort. Complexity of the radix sort is O(N k) where k is the number of digits used to represent the number in some base b. If we use the convenient fiction that both N and N^2 fit into the same 32 bit integer then k is a constant and we get an O(N) sort. (It's kindof cheating :) ).

[algogeeks] Re: Sorting Array

2011-06-26 Thread ross
@Divye: Good theoretical proof and analysis as well.. As you mentioned, this one works like charm for uniformly distributed inputs :) On Jun 26, 8:36 pm, DK divyekap...@gmail.com wrote: Use a radix sort. Complexity of the radix sort is O(N k) where k is the number of digits used to represent

Re: [algogeeks] Re: Sorting Array

2011-06-26 Thread Apoorve Mohan
u can use radix sort On Sun, Jun 26, 2011 at 9:44 PM, ross jagadish1...@gmail.com wrote: @Divye: Good theoretical proof and analysis as well.. As you mentioned, this one works like charm for uniformly distributed inputs :) On Jun 26, 8:36 pm, DK divyekap...@gmail.com wrote: Use a radix

[algogeeks] Re: Sorting Array

2011-06-26 Thread Dan
Your question is good for a classroom style discussion/debate. However, in the real world, there is no simple answer. There are lots of sorting algorithms. Each one has it's pros cons and no single sorting algorithm is best, especially when not much is known about the data to be sorted. In