Live data from Hacker News

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

news.ycombinator.com

211–220 of 507 posts

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

#211
post #8

Diffie–Hellman. I know that cryptography can get much fancier and more clever, but Diffie–Hellman took a concept my intuition told me was impossible and showed that it's possible in a really simple, elegant way. Learning about it was the first time I realized how beautiful the math behind computer science is. It's also a great insight into just how fundamental the concept of computational complexity is.

I was just blown away when my professor taught me this.

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

#212
post #27

https://en.wikipedia.org/wiki/Paxos_(computer_science) It took me days/weeks of processing to understand it (and appreciciate the problem(s) it solves).

It's very concise but very tricky at the same time, and it solves a fondamental problem. Even though I've spent some time studying it, I'm not sure I'd be able to figure it out by myself.

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

#214
post #149

Earlier quoted context omitted.

It is absolutely an algorithm in the sense of "a set of rules to be followed". I think you mean that it doesn't guarantee an optimal solution. That just means it's a heuristic algorithm, same as simulated annealing is a heuristic algorithm for solving optimisation problems.

Nope. An algorithm has to be effective. You can find pathological cases for k-means such that it will never converge on anything useful. So if you set your termination case to be convergence it will never terminate and if you don't then it will never be effective.

In that sense kmeans may be better referred to as a 'computational method' rather than an algorithm.

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

#215
post #70

Bloom filters are interesting. A bunch of different hashes as kind of fingerprint that make search fast but with caveats: negative answer is negative, positive answer might be negative.

HyperLogLogs are a great sketch data structure of which a bloom filter is a special case. The cool thing about them is that you can perform approximate set operation cardinalities in runtime proportional to sketch size rather than the cardinalities of the sets you’re comparing.

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

#217

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. Va…

BitTorrent is foundational to the rise of decentralized stores and sharing: IPFS, Dat Protocol, WebTorrent, Storj, Holochain, etc.

An Introduction to Kademlia DHT & How It Works

http://gleamly.com/article/introduction-kademlia-dht-how-it-...

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

#218

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…

NYC public schools use a version of this too: https://www.nytimes.com/2014/12/07/nyregion/how-game-theory-...

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

#219

Binary search. Very simple, incredibly powerful; can search on data or math function. It's the basis for other CS concepts. JS implementation: https://gist.github.com/netgusto/90c8e0e7019a832cbf95eac58e1...

Regarding "very simple" - as I recall from some book, first bug-free implementation appeared only after several years after invention / initial description of the algorithm. From wikipedia: "A study published in 1988 shows that accurate code for it is only found in five out of twenty textbooks" ( https://en.wikipedia.org/wiki/Binary_search_algorithm ).

It was in Programming Pearls, IIRC.
Post reply on HN