Duff's device. Because you will first look at it in disgust, but then you realize how clever it really is. See: https://en.wikipedia.org/wiki/Duff%27s_device
Quite a few EA Sports games have Duff's Device in locations of computational bottlenecks. I know because I put them there. Wonderful little mechanism.
Ask HN: What's your favorite elegant/beautiful algorithm?
251–260 of 507 posts
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#252Duff's device. Because you will first look at it in disgust, but then you realize how clever it really is. See: https://en.wikipedia.org/wiki/Duff%27s_device
These days compilers usually do loop unrolling on their own, so the device has mostly lost its purpose, but it can apparently also be used to implement something similar to coroutines in C, which is nice.
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#253Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#254Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#255 A to B: send message (repeat until ack)
B to A: ack (resend if a repeat of message is received)
A to B: commit message (repeat until commit ack)
B to A: commit ack (resend if a repeat is received, but commit only once)Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#256http://faculty.engineering.asu.edu/palais/counter-rotating-r...
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#257https://automorph.wordpress.com/2012/06/20/eulers-analytic-p...
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#258Also the compress and extract algorithms from Hacker's Delight.
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#259Not exactly an algorithm, but I like recursion as a pattern to be just insane to even think about. You can build an entire working structure from base operations, exit conditions and logic that scale to higher states of the operations. Extending the same, TCO is another very elegant concept in CS.
The same goes for some data structures, a simple example being a list, as often defined in functional programming languages. E.g.:
A list is either:
- empty, i.e. []
- a head (an element) followed by a tail (which is also a list), i.e. h | t
Lists of any size fit that definition because of the recursive definition.
Similar for binary tree, being either just a node, or a node with left and right child, each of which is a binary tree.
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#260Earlier quoted context omitted.
Without looking much further into it, I can't imagine it going very wrong. My intuition says that the density function will be bounded, since you're working with a finite number of points, therefore you'll always be able to climb to a local maximum.
The problem I see is the word "near" in "climb to nearest peak" . To quote the curse of dimensionality wiki page: > The common theme of these problems is that when the dimensionality increases, the volume of the space increases so fast that the available data become sparse. This sparsity is problematic for any method that requires statistical significance. https://en.wikipedia.org/wiki/Curse_of_dimensionality
Although I wonder if you can't account for that by simply increasing the kernel bandwidth. Perhaps not. Perhaps this is why mean-shift seems to be mostly used for computer vision and image processing, where (I guess?) the number of dimensions is low.