News for hackers. Stuff that matters.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by gambiting on Tuesday March 19, 2019 @04:44AM (#19429079)
Sleep sort is still my favourite - if you're sorting numbers, just spawn a new thread for each number, make it sleep that number of milliseconds and print out the number after waking up. After the largest number of milliseconds elapse, you have the sorted list of numbers nicely printed out.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by saagarjha on Tuesday March 19, 2019 @05:10AM (#19429198)
Of course, then you're just relying on your scheduler, which may or may not actually do the sort correctly.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by tinus_hn on Tuesday March 19, 2019 @09:04AM (#19430359)
The scheduler doesn’t have a hard job if all but 1 thread is sleeping.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by benchaney on Tuesday March 19, 2019 @09:10AM (#19430407)
Figuring out which threads to wake up when is an equivalent problem to sorting. The kernel has to maintain a queue of threads sorted on their sleep times in order to implement the sleep syscall in the first place
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by gambiting on Tuesday March 19, 2019 @03:28PM (#19434703)
Surely that's not true. You can keep a list of threads not sorted by their sleep time and just iterate through them and see if they are due to be woken up or not.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by benchaney on Tuesday March 19, 2019 @09:55PM (#19438161)
That winds up being more work.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by bjoli on Tuesday March 19, 2019 @11:32AM (#19431754)
Then check if it's sorted. If it is not, double the sleep time increments to make it more tolerant to scheduler error.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by emilfihlman on Tuesday March 19, 2019 @07:08AM (#19429725)
Isn't sleep sort equivalent to gravity sort?
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by deugtniet on Tuesday March 19, 2019 @04:14AM (#19428962)
From the pdf "3 Worstsort: the final solution"

Reminds me of a German statistics professor that taught me the basics of contemporary statistics. This guy would often say "final solution" with a thick German accent, which was kinda funny to hear. But after a couple of lectures I did discreetly tell him about the cultural annotations behind this term. Afterwards he was a bit more modest in its usage.

Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by majewsky on Tuesday March 19, 2019 @05:15AM (#19429229)
How can someone say "final solution" with a thick German accent? I'm German myself and when I try to pronounce it with deliberately thick accent, it doesn't change all that much.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by rocqua on Tuesday March 19, 2019 @05:45AM (#19429348)
I'd guess something like 'ze final zolution'. With the second z a lot less pronounced than the first. Mostly the pronunciation of 'the' by Germans is easy to notice.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by majewsky on Wednesday March 20, 2019 @08:11AM (#19441255)
The most obvious giveaways are pronouncing "the" like "s" and "w" like "v". Also, consonants in general are pronounced too hard, making the pronunciation less "flowing".
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by joosters on Tuesday March 19, 2019 @06:14AM (#19429495)
This still feels like ... cheating to me, if that's not too strong a word. If your algorithm for sorting a list involves generating a bigger list and then sorting that, then it's obvious that by recursion, you can make your sort function take forever.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by crave_ on Tuesday March 19, 2019 @06:59AM (#19429698)
A program that does not halt is not an algorithm. If you want to create a sorting algorithm, it has to halt, i.e. not run forever.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by candiodari on Tuesday March 19, 2019 @07:30AM (#19429809)
Not seeing that in either the definition and essentially all control algorithms, like say PID control, are meant to run "forever" (meaning longer than you can foresee in the code, they need an infinite loop)
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by frabert on Tuesday March 19, 2019 @09:50AM (#19430752)
You could consider that in PID control the actual algorithm is the single iteration, after which the output is sent out and a new set of inputs comes in, thus restarting the algorithm. In an endless iteration, you never give out any outputs
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by candiodari on Tuesday March 19, 2019 @12:50PM (#19432631)
You can't run PID in a single iteration. The integration and differentiation parts would be 0 in any single iteration, and so it's quite PID control if you look at it that way.

The description of the algorithm doesn't make much sense in a single iteration either.

Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by yogsototh on Tuesday March 19, 2019 @03:44AM (#19428853)
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by xorfish on Tuesday March 19, 2019 @04:06AM (#19428922)
How inefficient can a sort algorithm be with O(1) or O(n) memory usage?
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by karmakaze on Tuesday March 19, 2019 @12:51PM (#19432642)
Random shuffle, verify if sorted.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by cookingrobot on Tuesday March 19, 2019 @01:09PM (#19432876)
Make a random list, see if it’s sorted, then see if it’s the same as your original set.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by Rainymood on Tuesday March 19, 2019 @06:04AM (#19429444)
Why is bubblesort consistently spelled as bublesort?
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by faceplanted on Tuesday March 19, 2019 @06:05AM (#19429451)
Because the people spelling it wrong Just Haven't Met You yet
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by Taniwha on Tuesday March 19, 2019 @05:15AM (#19429227)
make a linear pass through the data, if they are in order quit, otherwise swap two random entries and repeat
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by martin_a on Tuesday March 19, 2019 @11:02AM (#19431422)
So, the minimum running time for this would be O(1), but can one estimate the maximum? I don't see how, but maybe I'm missing something.
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by astrobe_ on Tuesday March 19, 2019 @12:20PM (#19432282)
This is known as BoZosort [1], which is said to be O(n!) on average.

[1] https://en.wikipedia.org/wiki/Bogosort

Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by kevinwang on Tuesday March 19, 2019 @12:51PM (#19432635)
I think it may be another factor of n slower than that

Edit: wow nevermind, I just read the paper linked to bozo sort in wikipedia. They conjecture that it's O(n!) whereas bogosort is Omega(n*n!). Wow, that's surprising!

Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by smartstakestime on Tuesday March 19, 2019 @04:07AM (#19428926)
O(2 * n)
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by anonytrary on Tuesday March 19, 2019 @04:48AM (#19429105)
O(2*n) == O(n)
Re:How Inefficient Can a Sort Algorithm Be? (2012) [pdf] by augustk on Tuesday March 19, 2019 @05:23AM (#19429250)
Or with common mathematical notation: O(2*n) = O(n)