Live data from Hacker News

Ask HN: What's your favorite elegant/beautiful algorithm?

news.ycombinator.com

161–170 of 507 posts

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#161
Cantor's proof [1] of impossibility of a surjection into the powerset.

Although, calling this an algorithm may offend applied mathematicians.

I would call it an algorithm since explicitly defined sets are constructed to show the contradiction.

[1] https://en.wikipedia.org/wiki/Cantor's_theorem#Proof

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#162
post #3

1. The "Skew Algorithm", aka "DC3", aka Kärkkäinen-Sanders. It uses radix sort in an extremely brilliant way to construct suffix arrays in linear time. I found these explanations helpful (though it still took me some time to digest): http://www.mi.fu-berlin.de/wiki/pub/ABI/SS13Lecture3Material... 2. Fast Fourier transform (FFT). It's another quite brilliant algorithm used for decomposing a function into its frequency…

I would also vote for FFT. It's amazing how widely it's used and what sort of tricks you can do in frequency domain. Multiplying polynomials? Simple! Multiple 2D projections of a 3D object? Just FFT them, do a couple of simple steps and you will get a 3D model.

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#163

K - means clustering, which I learned about recently. For non-machine learning folks, this algorithms helps in grouping relevant items together. As a practical, using this algorithm you can segment your customers based on their purchase history and interests. The actual algorithm is very simple, imagine a lot of points on the 2D plane and each of them represent customers, whom you want to segment/cluster. Now, chose…

The scikit-learn page on clustering [1] is a really great way to see K-means and other algorithms side-by-side. The pictures really make it easy to see how all the algorithms perform on various data distributions.

[1] http://scikit-learn.org/stable/modules/clustering.html

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#165

Lempel–Ziv–Welch is pretty cute. I love how the decompressor/receiver builds up the dictionary in sync with the compressor/sender at the same point in the datasream without ever needing to store/send the dictionary.

I loved that algorithm because of its elegance and simplicity and also as you pointed out about the data stream. It would be fun to implement this as hardware block and that was what it was intended for i.e. on the fly compression and decompression between interfaces.

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#166

The Gale-Shapley Algorithm to solve the "Stable Marriage" problem. 2012 Nobel Prize in Economic Sciences for its wide-ranging use in medicine, education, and resource allocation. It's fairly easy to implement a basic version of it, feels intuitively obvious once explained, and has been applied to everything from organ transplants to student placement in elementary schools. Really, any place you have two groups where…

I remember when this "Nobel Prize" was announced I immediately started reading the paper and trying to figure out how it could work in code. It seems like it could have amazing economic potential if put to a good use, but until your comment I hand't known of any real-world uses outside of organ transplantation. Very excited to see it being appreciated by more computer scientists! I need to look into it again for sure!

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#167
post #127

Earlier quoted context omitted.

Link?

https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exc...

There's also this. The paint mixing analogy starts around 3 minutes in.

https://www.youtube.com/watch?v=YEBfamv-_do

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#169
> Eller's algorithm creates 'perfect' mazes, having only a single path between any two cells, one row at a time. The algorithm itself is incredibly fast, and far more memory efficient than other popular algorithms (such as Prim's and Kruskal's) requiring storage proportional to only a single row. This makes it possible to create mazes of indefinite length on systems with limited memory.

http://www.neocomputer.org/projects/eller.html

Re: Ask HN: What's your favorite elegant/beautiful algorithm?

#170
I always push my devs to really study the Bittorrent protocol. The elements of the protocol are all fairly easy to understand, but it's gorgeous to see how elegantly it solved a social problem rather than a computational problem. The tit-for-tat and fast-finish protocols are incredibly graceful ways to create virtuous cycles in a social/technical hybrid, and replaced very real vicious cycles in previous protocols.

Various TCP backoff algorithms are also a great study in how to approach problems with insufficient knowledge of the system under test, and building desirable properties (reliable in-order delivery) from a undesirable input (arbitrary packet loss, and loss in the face of congestion). I make all the kids try to implement their own, then walk through the history of TCP approaches to the modern day.

Post reply on HN