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.
Ask HN: What's your favorite elegant/beautiful algorithm?
41–50 of 507 posts
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#42Not 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.
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#43Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#44Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#45Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#46LR 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?
#47Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#48Binary 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...
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.
Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#49Re: Ask HN: What's your favorite elegant/beautiful algorithm?
#50Long division, because it shows that you don't need computers to run algorithms and that, in fact, any kid can do it.