Ask HN: What's the most interesting algorithm?
(You can list several, if you like.)
It's a fun question, so maybe this will be a fun thread.
(You can list several, if you like.)
It's a fun question, so maybe this will be a fun thread.
What is really enlightening though is implementing a basic one, because it is so simple. The core of it involves popping two graph nodes from a heap and pushing a new one. I did this in school, and was impressed by it, but became far more appreciative when I tried to do the JPEG way. It doesn't even provide a table, just a histogram!
It also acted as the basis for the successor of arithmetic coding, which is pretty much in every modern video codec. Can you imagine a world that is still analog because we couldn't figure out how to transmit digit video or images or audio? Huffman is a key link in the chain between the past and present.
Another interesting but asymptotically slower integer/polynomial multiplication algorithm is Karatsuba's.
While we're on the subject: This book is a great read: http://www.amazon.com/Nine-Algorithms-That-Changed-Future/dp...
Last year I learnt Ford Fukkerson [0] and Dijkstra [1] Algorithm. Algorithns for graphs are really interesting and have a lot of applications. Fun fact, I learnt these in a transport engineering course, not in a computer science one, and I still use them sometimes in computer science courses.
[0] https://en.m.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algor... [1] https://en.m.wikipedia.org/wiki/Dijkstra%27s_algorithm
RMQ with linear preprocessing and constant time queries (which is also true for multi-dimensional cases, if the dimension is bounded by a constant).
Knuth-Morris-Pratt pattern matching is the first algorithm where I saw the usage of an additional variable in the pseudocode just to simplify the complexity analysis.