Live data from Hacker News

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

news.ycombinator.com

101–110 of 507 posts

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

#101
post #17

Karger's randomized contraction algorithm for finding a min-cut. It's a common algorithm to introduce students into the world of randomized algorithms. Also a shameless plug. My friend and I came up with this pseudo-polynomial time algorithm for subset sum that can be taught in a single session. It is faster than the standard dynamic programming algorithm. https://arxiv.org/abs/1807.08248

I actually read some of this paper! I liked your FFT trick.

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

#103
I've always appreciated the Bresenham's line algorithm. It's a very simple algorithm and has been "superseded" by Xiaolin Wu's line which can also do antialiasing, but ever since I learnt about it, I've been very fond of it. Also the fact that it's an algorithm for use in computer graphics helps, because for me it's very easy to get excited about visual stuff as opposed to the more abstract CS stuff, which I have deep appreciation for but can't understand most of or kick myself enough to try.

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

#105

The "2 watched literal" algorithm used in sat solvers (here is a random blog post I found by googling http://haz-tech.blogspot.com/2010/08/whos-watching-watch-lit... ). The algorithm has many lovely features. It is very efficient -- it is used in basically every SAT solver with minimal modifications. It's not entirely trivial it works, particularly the backtracking part. It is a good example of how there are algorith…

Awesome, thanks for mentioning this! I completely forgot about 2-literal watching and I hadn't ever thought about the idea that it'd be difficult to implement functionally. It's absolutely clever. And one other intuition I would like to add to it is that, from the way I see it at least, it is a cheap "detector" for when 3-SAT degenerates into 2-SAT, which finally becomes polynomial-time solvable -- which is exactly the kind of thing you want to have a detector for!

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

#106
R-Trees for spatial indexing.

What?: Quite powerful data structure for geographic data.

Why?: I dabbled with geodata for quite a bit before discovering PostGIS and the R*-tree. Operations that took me several seconds before (geojson+ruby) could be computed in well under 100ms directly on the Database.

[0]: https://en.wikipedia.org/wiki/R-tree

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

#108
post #5

Euclid's GCD algorithm, and Russian peasant multiplication.

I like this version of the Euclid algorithm:

Make a rectangle with side lengths of 2 positive real numbers. Put the biggest square inside (i.e. against a short side) that you can, add as many as fit. If there's still a gap, put the biggest square that fits in that, repeating until filled.. If you never fill the gap, the ratio is irrational. The number of squares of each size used gives the ratio's continued fraction.

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

#109
Oh, man. So many answers. The blockchain of bitcoin is pretty gorgeous, if that counts.

AES is beautiful as well. And I love Huffman encoding. hm, what else. Bloom filters are awesome.

I suspect FFT is beautiful, too, but it surpassed my ability to understand.

Post reply on HN