Live data from Hacker News

Unconventional Sorting Algorithms

codingkaiser.blog

31–40 of 60 posts

Re: Unconventional Sorting Algorithms

#32

Slightly off-topic, the article was fine except for one nitbit... I wonder what the author, "hilariously" making one sorting function print " sent to gulag" and calling it "stalin-sort", would think of "hitler-sort" which prints " burned in oven"? Please don't normalize mass-murderers, even for memes.

If you downvote, you must write what is wrong with that statement.

Re: Unconventional Sorting Algorithms

#33

Slightly off-topic, the article was fine except for one nitbit... I wonder what the author, "hilariously" making one sorting function print " sent to gulag" and calling it "stalin-sort", would think of "hitler-sort" which prints " burned in oven"? Please don't normalize mass-murderers, even for memes.

It's an obvious joke, the point of which is that the Stalin Sort is destructive and doesn't actually get you what you want, and you'd never want to use it.

Re: Unconventional Sorting Algorithms

#34
post #18
post #8

My contribution: Power Sort. Start with p=0 and add 2^n for each n. Then subtract the largest power of 2 successively to get your integers ordered. Con: p will be very big. Pro: you don't need ifs!

Ooh, that's a fun one. Another con: you'd better hope your input contains no duplicates. :)

Duplicates could also be handled by using (L+1)^n, rather than 2^n, where L is the length of the input: even if all elements are identical one will end up with a unique value p = L * (L+1)^n.

For an efficient implementation, one might want to round L+1 up to the nearest power of 2 to get crucial micro-optimisations based on instructions for bit scanning.

(I think this ends up being a very complicated phrasing of a counting sort.)

Re: Unconventional Sorting Algorithms

#35

Slightly off-topic, the article was fine except for one nitbit... I wonder what the author, "hilariously" making one sorting function print " sent to gulag" and calling it "stalin-sort", would think of "hitler-sort" which prints " burned in oven"? Please don't normalize mass-murderers, even for memes.

It's an obvious joke, the point of which is that the Stalin Sort is destructive and doesn't actually get you what you want, and you'd never want to use it.

I think OP gets the joke and is just saying it is in poor taste. Is it particularly different than their example of Hitler-sort burning stuff in an oven on failure? Or Columbine-sort, where the 15 coolest numbers get shot and then the rest of the numbers can get sorted.

Re: Unconventional Sorting Algorithms

#36
post #9

Isn't 'sleep sort' linear with respect to array size? O(n) sort achieved?

It is if you ignore how the underlying OS implements multitasking and sleep() in particular. And the kernel-side implementation usually involves some kind of priority queue of sleeping threads. So taken as a whole sleep-sort is just an convoluted implementation of heap-sort that outsources the actual sorting to OS.

The kernel could use a different implementation of multitasking, e.g. keep the threads in a circular doubly linked list instead of a priority queue. This wouldn't be optimal for a general-purpose OS, but works for our custom O(n) sorting machine.

Re: Unconventional Sorting Algorithms

#37
post #8

My contribution: Power Sort. Start with p=0 and add 2^n for each n. Then subtract the largest power of 2 successively to get your integers ordered. Con: p will be very big. Pro: you don't need ifs!

Fun fact, when you consider the bits required to contain p, this is equivalent to bucket sort with a bucket size of 1.

Re: Unconventional Sorting Algorithms

#38
I like Intelligent Design sort:

> The probability of the original input list being in the exact order it's in is 1/(n!). There is such a small likelihood of this that it's clearly absurd to say that this happened by chance, so it must have been consciously put in that order by an intelligent Sorter. Therefore it's safe to assume that it's already optimally sorted in some way that transcends our naïve mortal understanding of "ascending order". Any attempt to change that order to conform to our own preconceptions would actually make it less sorted.

https://www.dangermouse.net/esoteric/intelligentdesignsort.h...

Re: Unconventional Sorting Algorithms

#39
post #30
post #27

Earlier quoted context omitted.

For the operation of this algorithm, is there any meaningful difference between destroying the universe and destroying the observer(s)? https://en.wikipedia.org/wiki/Quantum_suicide_and_immortalit... EDIT: If you allow for the objects to spontaneously sort themselves, the runtime is O(1).

Surely O(n) for checking whether it is sorted?

(the problem of destroying which universe is also left as an exercise to the reader)

Re: Unconventional Sorting Algorithms

#40
I know this article is meant as a joke but the first variant of bogosort, which is actually randomsort, it will be the fastest algorithm once we start using quantum computing.

Having an array and allocating "n"=="array length" qubits for it then implementing parallel version of randomsort (no while, while is serialization!) will be the fastest sorting algorithm.

Post reply on HN