Live data from Hacker News

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

news.ycombinator.com

131–140 of 507 posts

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

#136
post #96

It would be hard to beat Floyd–Warshall algorithm. Think about the problem of finding shortest paths between all pairs of nodes in graph. Sounds trivial? Would you believe if someone told you it can be done in literally 5 lines of code? When I saw that for the first time I was in the disbelief. The elegance comes from these fact, - Very non-trivial problem - Just 5 lines of code - Probably the most language agnostic…

> Probably the most language agnostic algorithm

Are you sure about this point? I'd like to see a purely functional implementation of this, e.g. in Haskell without monoids. I believe it's significantly harder than a C implementation (which is indeed a few lines)

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

#137

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…

K-means is not an algorithm, it's a heuristic for an Np-hard problem.

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

#138
B-trees are really beautiful. I also like the Aho-Corasick algorithm as used by fgrep. I actually started to reinvent this algorithm myself before finding out it was already done. It's essentially a way to add links to a trie such that you can find all occurrences of multiple substrings within a larger string with one pass through the larger string.

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

#139
post #82

Minimax search https://www.cs.cornell.edu/courses/cs312/2002sp/lectures/rec... How knew that a couple of line of code could be used cause so many interesting behaviors like cooperation, betrayal etc.

Yes and alpha beta pruning. Your link mentions that.

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

#140

Been learning about Hashlife[0] the last few days. It's pretty cool. [0] http://www.drdobbs.com/jvm/an-algorithm-for-compressing-spac...

I agree. If an algo can demonstrate the huge gain between a clever algorithme and a naive one, it's this one.
Post reply on HN