Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I see that sort of thing a lot, where a simple model appears to violate some algorithmic boundary, but a more complete analysis reveals that all is well.

For example, take "spaghetti sort." This is a weird physical sorting algorithm where you represent each number to be sorted as a physical strand of uncooked spaghetti of corresponding length. To perform the sort, you grab the spaghetti in a bundle and place it on a table so the bottom of each spaghetti strand is on the table. Then you put your other hand on top, find the longest strand, and pull it out. Repeat this process once for each strand, and you then have all the numbers in order.

This is described as a "linear time" algorithm because you perform the same procedure once per number, so it's clearly O(n). It's obviously impractical for real-world use, but if you had some utterly ridiculous quantity of numbers, maybe it could be the best way!

But of course this ignores important factors. For example, the radius of the bundle will increase with the square root of the number of strands present within it. Whatever you use to select and retrieve the longest strand must move at some finite speed to traverse this distance, which means that the actual running time is O(n^1.5), substantially worse than the theoretical O(n log n) limit!

Another factor that is often ignored is the fact that analog systems don't actually have infinite precision. If you look at their actual (or even theoretical) precision and convert that to bits, it's not all that many! Lots of analog solutions can look extremely clever and quick, until you realize that it's just solving the problem for a 28-bit number, or whatever.



I consider those the Brownian ratchets [1] of computing. Interesting to model and see what's going on!

Here's another variation: arrange the sticks in a line. Have a pole scan the sticks from the top, and when the pole is impeded, record it's height. You've just computed max(a1,...,aN) in O(1) time?! (disproving is left as an exercise -- note you can even assume the pole is weightless and infinite!)

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


All too easy!

Relativity tells us that disturbances in the pole cannot move faster than the speed of light. Therefore the time it takes to find out that your pole hit something is O(n), since the location of the tallest element will be on average halfway down your line.

Of course, there's the much more obvious problem that "arrange the sticks in a line" requires manipulating each stick, and is thus O(n)!


Correct, of course :) Maybe it's not that good example... I was trying to come up with a way to obfuscate the speed of light limitation (one usually thinks of poles as rigid). A thing I like about those is even if they're really simple they highlight limits like the Bekenstein bound: you can make your experiment arbitrarily large, but if you allow it to shrink arbitrarily (as a function of n), you get unexpected results (essentially BSS machines[1] versus Turing machines?) -- in your example you could actually sort the numbers in O(n).

[1] https://en.wikipedia.org/wiki/Blum%E2%80%93Shub%E2%80%93Smal...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: