Live data from Hacker News

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

news.ycombinator.com

341–350 of 507 posts

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

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

And here is an elegant explanation of the Diffie-Hellman protocol https://www.youtube.com/watch?v=YEBfamv-_do

Absolutely amazing. This is one of those instances when analogy is exact (mixing colors) and doesn't dilute the original motif (One way function).

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

#342

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

A cool thing about binary search is you can also use it in real life. It's great for troubleshooting.

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

#344

Earlier quoted context omitted.

It's also critical for factoring prime numbers and SETI signal intelligence processing. Truly a gem.

Factoring prime numbers?

https://en.wikipedia.org/wiki/Prime-factor_FFT_algorithm

https://math.stackexchange.com/questions/977955/is-there-a-w...

My experience with this is from using Prime95 two decades ago as part of a distributed computing project to factor Mersenne prime numbers

https://en.wikipedia.org/wiki/Prime95 | https://www.mersenne.org/

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

#346

Exponential backoff: I don't know if this is a published algorithm. Basically, background processes need to keep retrying an operation until it succeeds. (Make an API call to a server, upload a file, ect, ect.) If the retry interval is too small, you can DOS the remote server. (Server returns a 5xx error because there's a corner case that hits a defect.) But, if the retry interval is too large, your background proces…

Ideally, you also want to implement "jitter" in the retries. AWS has a good article about it: https://aws.amazon.com/blogs/architecture/exponential-backof...

The summary (from the article) is that:

    sleep_time = random_between(0, min(2 ** retries, max_sleep_time))
so that retries are "spread across" the delay window.

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

#347
The first time I implemented the backtracking algorithm it felt really special. I was struggling to solve 8 queen problems for a couple of nights, banging my head around it. And then when it worked, I knew my love for programming was not going anywhere any time soon.

It was ugly, I had used 8 for loops, each running for 8 iterations, but, I still felt awesome when it worked. Before this, I had written only lab programs. Next, I applied the backtracking algorithm to solve Sudoku recursively, and that's how it all began. I entered the world of algorithms.

I know it's just one form of brute force algorithm, maybe doesn't even count as one, and is not that elegant, but, it will always remain my favorite.

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

#348
I think the beauty comes out when referring to the problems the algos solve:

a. Solving the nut/bolt matching programming challenge with Merge sort.

b. Backtracking e.g. finding the ordered pair of braces

c. Not to mention the various tree/ graph walk problems

d. I screwed my Google interview last round not knowing the problem could be easily solved topological sort

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

#349

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…

Lesson two of this course does a great job explaining K-means and its connection to Expectation Maximization. https://www.udacity.com/course/machine-learning-unsupervised...
Post reply on HN