Live data from Hacker News

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

news.ycombinator.com

121–130 of 507 posts

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

#121

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.

Out of curiosity, what do you find beautiful about AES?

I personally think that Speck is pretty cool because of its extreme simplicity, but I can't see anything special about AES.

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

#122
post #66
post #41

Earlier quoted context omitted.

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

I love the idea of how essentially we have never met and we're shouting across a crowded room but no one else can understand our conversation.

Link?

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

#124

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.

[deleted]

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

#125

Gaussian integration. You might have heard of "2nd order" or "4th order methods to calculate an integral. This means that the error drops off with the number of sampling points like N^-2 or N^-4, respectively. But Gaussian quadrature has spectral accuracy, which transcends this measure. Error goes down like an exponential of N. Another neat feature is polynomials of degree 2N-1 or less are integrated exactly with thi…

This is a bit misleading. If the integrand is analytic, then the Gauss quadrature converges geometrically.

For example with f(x) = sqrt(1 + sin(x)) and you approximate integral f(x) dx from -1 to 1 with n Gauss points, then the the convergence is geometric:

    n | approx
    1 | 2.0------------- 
    2 | 1.9172----------
    3 | 1.917703--------
    4 | 1.917702153-----
    5 | 1.917702154417--
    6 | 1.91770215441681
   
But with a function that is not differentiable such as g(x) = |x|, there is definitely not geometric convergence.

      n | approx
      1 | 0.0-----------    
     10 | 1.007---------
    100 | 1.00008-------
   1000 | 1.0000008-----

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

#126

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.

Indeed, Java's binary search had this bug for a while! It was found through automatic verification, by the way.

https://ai.googleblog.com/2006/06/extra-extra-read-all-about...

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

#127
post #66

Earlier quoted context omitted.

I love the idea of how essentially we have never met and we're shouting across a crowded room but no one else can understand our conversation.

Link?

https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exc...

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

#129

Gradient descent is quite amazing in its power and simplicity. If we can figure out a good loss function and a model architecture with enough parameters, calculus can basically take care of the rest.

This pretty much my same pick. I'm completely blown away by the possibilities of a combination of gradient descent and clever loss/architectures. After learning how output shape and loss definition can result in wildly different tasks such as landmark detection, classification, or single shot multibox detection(bounding boxes AND classification wuuut?!) it really gets the imagination running wild.

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

#130
post #36

I really like Viterbi. It has applications all across computer vision and filtering and it takes full advantage of the magic of dynamic programming.

Same here! I blogged about it over 5 years ago (time flies) [1]!

Amusingly, despite having done a ton of Computer Vision (I worked for an image recognition company for 4 years) I never used it for that purpose. The main practical use case I had was related to the use of Trellis modulation [2] for band-limited communication channels.

[1] https://blog.separateconcerns.com/2013-03-03-viterbi-algorit...

[2] https://en.wikipedia.org/wiki/Trellis_modulation

Post reply on HN