Live data from Hacker News

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

news.ycombinator.com

41–50 of 507 posts

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

#41
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.

So true. Securely exchanging keys is an abstract concept until you see those paint colors mixing!

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

#42
post #37

Not 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.

check out a book called "Godel, Escher, Bach". It's an incredible book about recursion in life, and in some sense makes the argument that consciousness arises fundamentally from recursive loops (a system examining itself)

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

#46
Boyer-Moore (grep) : https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-sea... because it's cool.

LR parser https://en.wikipedia.org/wiki/LR_parser because Aho & Ullman

https://en.wikipedia.org/wiki/Church_encoding 'cos it shows how fundamental lambda calculus is in a simple way (and how functional programming is so superior (flame wars intended :-) )

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

#48

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

Isn't this bit:

const mid = Math.floor((right + left) / 2);

susceptible to overflow?

EDIT: Hm, perhaps not (in JS). Number.MAX_SAFE_INTEGER is much greater than I expected.

Post reply on HN