Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Specific Sorting Algorithm Trouble

Name: Anonymous 2012-03-11 21:27

Sup /prog/,

So, I'm having trouble finding out what my professor meant by this, not sure if it's a typo because he often has typo's in his assignments. If the range was simply 1 to m, I would just use counting or bucket sort, but since it's 1 to m^2, I really have no clue. Thanks for any help I can get on this. Here's the problem:

Let x1, x2,…,xn be a sequence of integers in the range 1 to m^2. Describe an algorithm to sort this sequence in time O(n + m).

Name: Anonymous 2012-03-11 21:34

I hope this post doesn't go to the top, it's been a while and I forgot the email conventions.

Anyways, I was thinking possible a radix sort using bucket sort would work, but I'm not quite sure what my radix would be. Any elaboration on this would help, thanks.

Name: Anonymous 2012-03-11 22:03

>>2
try picking a radix and then try proving that the algorithm will run in O(n + m)

Name: Anonymous 2012-03-11 22:31

Sleep sort

Name: Anonymous 2012-03-11 22:35

>>3
Hmm, I'll try this. I'm thinking maybe a radix of log(m) or something. Thanks for the tip.

Name: Anonymous 2012-03-11 22:37

>>4
Weird, I'd never heard of this. I'll check it out thanks.

Name: Anonymous 2012-03-11 22:49

>>4
Haha, this is the coolest sorting algorithm I've ever come across, if I can't figure this one out(with radix), I'm going to do sleep sort. I doubt my prof. has even heard of it.

Name: Anonymous 2012-03-11 22:51

>>6
zomg it actually works for this!

Name: Anonymous 2012-03-11 22:54

>>8
Actually it doesn't, I just realized.

Let m = 5, and Arr = [1, m^2] = [1, 25]

It will take 25 seconds, and thats just including the sleeping, what about the time we spend running through the array making new threads? It needs to run in O(n + m), radix sort is the only way as far as I know.

Name: Anonymous 2012-03-12 0:01

>>9
just have the ith thread time out after sqrt(i) seconds, on a machine with infinite precision time.

Name: Anonymous 2012-03-12 0:15

>>9
You don't have to use seconds. Just don't use something too short.

Name: Anonymous 2012-03-12 2:35

>>10
>>11

It doesn't matter what unit of time you use, this is asymptotic notation, constants don't apply. O(10000000) is the same as O(1).

Name: Anonymous 2012-03-12 4:18

>>12
yesh. Thish ish y ey treds hime oot afta f(n) secounds, wher f(n) in o(n).

Don't change these.
Name: Email:
Entire Thread Thread List