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

Genius sorting algorithm: Sleep sort

Name: Anonymous 2011-01-20 12:22

Man, am I a genius. Check out this sorting algorithm I just invented.


#!/bin/bash
function f() {
    sleep "$1"
    echo "$1"
}
while [ -n "$1" ]
do
    f "$1" &
    shift
done
wait


example usage:
./sleepsort.bash 5 3 6 3 6 3 1 4 7

Name: Anonymous 2011-05-28 3:47

It's O(n2) under the hood because the kernel has to scan the list of waiting threads every pass through the idle loop. It's only O(n) if you have n CPUs, in which case you should be using n-way mergesort, since that has already been shown to give O(log n) time.

Remember, guys: the OS is not magic, and just because you didn't take an OS design course doesn't make you a wizard.

Only LispM designers get to be wizards.

Newer Posts