Need Something Sorted? Sleep on It
kevlinhenney.medium.com
kevlinhenney.medium.com
Seriously. How many times have you crashed out on a knotty problem and awakened with a clear solution?
Glad that my superpower remains secret.
...
An algorithm M is described that solves any well-defined problem p as quickly a the fastest algorithm computing a solution to p, save for a factor of 5 and low-order additive terms."
https://www.researchgate.net/publication/220180215_The_Faste...
"Have you still not migrated to the stars? What's blocking you?".
Wu wei
It's the opposite that is usually happening to me: I go to sleep thinking I finally solved some problem. When I wake up, literally the first thought is a clear counter-example on which the solution does not work. It's frustrating.
If you run the program and then just randomly trigger the debugger with CTRL-C.. the probability is that you're likely to have landed on a slow code path because that's where the program is spending most of its time.
Note that pstack will probably take a bit for each stack snapshot it prints. It has to attach as a debugger, walk the stacks, and read the symbol tables each time. It's easy for the whole process to freeze for a second or two, so you probably don't want to do this on a production process that is limping along okay-ish.
No, it is not. It's O(N+M) where M is the largest value in the list. And, notably, it can fail if the time to schedule the jobs takes longer than the smallest difference between elements in the list
> Bonkers, brilliant and definitely NSFW.
Given there's n timers and O(1) operations I'm not sure where the O(n log n) fits in here. Possible in the minimum number of ticks?
http://www.cs.columbia.edu/~nahum/w6998/papers/sosp87-timing...
Production implementation: https://github.com/facebook/folly/blob/master/folly/io/async...
> If we can guarantee that all timers are set for periods less than MaxInterval, this modified algorithm takes O(1) latency for START_TIMER, STOP_TIMER, and PER_TICK_BOOKKEEPING.
I think that puts this in the same class as counting sort.
Edit:
Why divide by m, when you can divide by M*C. Where C will speed this portion up by a factor!
You can find the largest element in a list in O(1) time with n^2 processors[0]*.
Division of the list by that number is O(1) with n processors
Therefore the operation is O(1)
[0]* on a CRCW PRAM https://www.cpp.edu/~gsyoung/CS535/CS535Notes/Part2PRAM.pdf#...
But I cannot remember what it is, and I'm likely explaining it badly. It had some neat algorithmic or type-level properties too, I believe, and I remember seeing it in context to modelling truly real-time systems.
Does anyone know what I'm talking about? Or is my memory finally deciding to make things up, whole-cloth!
Edit; found it with the help of the commenters below!
https://en.m.wikipedia.org/wiki/Synchronous_programming_lang...
https://en.m.wikipedia.org/wiki/Synchronous_programming_lang...
Synchronous programming was the term I was thinking of: the concept of logical ticks being first-class in the programming language itself is what SleepSort reminded me of :)
Another interesting one is Chuck, a strongly-timed language. :)
Useful for making musical programs.
I like the method because not only is it silly, it's also very easy to do on GPU and good enough so I actually have used it in real products.
Another good thing that came out of 4chan in the same year: https://en.wikipedia.org/wiki/Superpermutation
1. For each entry in your list, cut a straw of length proportional to the value to be sorted
2. Take all your straws in a bundle
3. Bang them gently on a flat table
4. Draw out the straws in order of length, each operation of which can be done in O(1) time
Perhaps by making use of the Oracle of Delphi, you could do away with the array.
Also, the energy requirements... Wouldn't they be proportional to the number of operations required, i.e. the time complexity?
Very good point! Computer-based algorithms need O(log(M) N) storage, I guess.
Edit: This is usually the problem with analog algorithms: you can easily tell apart 100 items, but scale it up and you find you need so much energy to differentiate that you'd collapse into a black hole before successfully measuring the differences.
From a technical point of view, it's simply handing the problem over to the cpu scheduler. Kind of like touching empty files and naming them in a particular way and doing an ls to get them back sorted. Similar to rc scripts.
Walking helps my brain juices flow.
On a personal note, these days I find listening to music outside off-putting and potentially rude and/or dangerous in a city environment.
All that said, a good night's sleep works wonders for both body and mind