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

Pages: 1-

Cyclic sort

Name: Anonymous 2013-03-18 17:09

What if I wanted to sort a list of integers, but with the added condition that the list was cyclical and the sorted data could "start" at any point? e.g. the list [7, 4, 2, 5, 3] could be sorted as [2, 3, 4, 5, 7], [5, 7, 2, 3, 4], [4, 5, 7, 2, 3], etc.

Would an algorithm that implements this sort be more efficient than a standard sort? It seems like since there are now n solutions instead of just 1, sorting the list should be n times easier and thus only take O(log n) time. But I think that's probably bullshit.

Name: Anonymous 2013-03-18 17:14

(define (cyclic-sort lis)
  (apply circular-list (sort lis)))

Name: Anonymous 2013-03-18 18:45

sub oh_en_sort {
    for (@_) { @a[$_] = $_; }
    return @a;
}


boom, O(n) sort. For 1..n sequences only, though. You could add a grep{/./} in there to remove empty array elements but that would increase the complexity.

Name: Anonymous 2013-03-18 19:04

Fibonacci buttsort.

Name: Anonymous 2013-03-18 19:18

/prog/ already invented sleepsort, the only sort you'll ever need.

Name: Anonymous 2013-03-18 19:25

>>3
That is radix sort. It has kN complexity, not O(N)
http://en.wikipedia.org/wiki/Radix_sort

Name: Anonymous 2013-03-18 23:43

>>3

What the fuck language is that?  Ruby?  Perl?

Name: Anonymous 2013-03-19 0:21

>>7
That's perl, baby. @_ is the implicit array of arguments provided to the most local sub or function. It's basically TECO, only somehow uglier.

Name: Anonymous 2013-03-19 4:48

it's the same "standard" (dunno what you mean as 'standard' though but w/e) sort just with some additional parameter where to start

>seems like since there are now n solutions instead of just 1

and only 1 solution is correct for any given parameter


a = [7, 4, 2, 5, 3]
b, c, n = [], [], 3
for i in a:
    if i > n:
        b += [i]
    else:
        c += [i]
b.sort()
c.sort()
a = b + c

Name: Anonymous 2013-03-19 14:56

>>6
What the fuck is $kN$ and how is it different from $n$?

Name: Anonymous 2013-09-01 13:38


 Ruitomo? Killing curse that's not unique to you is good enough.

Name: Anonymous 2013-09-01 15:09


How are little girls disgusting? If that's not it, how is a grown man masturbating to little girls any more disgusting than another grown man masturbating to women?

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