Live data from Hacker News

What algorithm blows your mind? (Reddit compsci)

reddit.com

21–30 of 71 posts

Re: What algorithm blows your mind? (Reddit compsci)

#21
Quake3's Fast InvSqrt function:

http://www.beyond3d.com/content/articles/8/

It's been discussed here before, and no doubt it'll be cited numerous times in the comments of that reddit post, but it was the first time I'd ever seen such trickery. When I got into low level DSP programming I saw many more examples of clever hacks, but this is the one which sticks in my mind above all of those.

Re: What algorithm blows your mind? (Reddit compsci)

#22
post #18
post #16

Bloom Filters: http://en.wikipedia.org/wiki/Bloom_filter Sort of a probabilistic hash, where you trade space for accuracy. But it's also like a memory function - it can remember if it has seen a piece of data before.

What I love about bloom filters is that when checking to see if something is in a bloom filter, you can only get false positives, not false negatives. That property is just awesome to me.

Also the fact that you can use more bits per element and reduce the error rate for false positives. Using around 3 bytes per element, can bring the error rate down to 0.001%.

Re: What algorithm blows your mind? (Reddit compsci)

#24
The quantum search algorithm: http://en.wikipedia.org/wiki/Grovers_algorithm

It lets you search a completely unstructured N-item search space using the square root (!) of N queries, not the N queries you'd think were necessary.

Also, the algorithm is so simple that once you know it's possible, and provided you're very comfortable with basic quantum mechanics, it's almost trivial to find the algorithm.

Re: What algorithm blows your mind? (Reddit compsci)

#26
All very nice suggestions below, but I found suffix trees missing: http://en.wikipedia.org/wiki/Suffix_tree

And the reasons why it blows my mind:

(1) Knuth called it "Algorithm of the year 1973" (possibly because it beat an intuitive lower bound that he had for a problem I can't remember).

(2) It's relatively new for a "core", first-principles algorithm. Ukkonen's algorithm is from 1995, although there are earlier versions.

(3) This BOOK is largely devoted to the many, many applications of suffix trees: http://www.amazon.com/Algorithms-Strings-Trees-Sequences-Com... It should be required reading for anyone interested in advanced algorithms.

(4) Longest common substring in linear time.

(5) Lempel-Ziv decomposition in linear time.

(6) Longest repeated substrings in linear time.

And too many more to list.

Re: What algorithm blows your mind? (Reddit compsci)

#27
My mind is blown by the algorithm for matching with mismatches which I present in the first chapter of my thesis. It shouldn't be, given that I discovered this algorithm -- but somehow "I take the Fourier Transfer of the FreeBSD kernel" sounds more like the punch line to a joke than the first step in an algorithm.

Re: What algorithm blows your mind? (Reddit compsci)

#28

My mind is blown by the algorithm for matching with mismatches which I present in the first chapter of my thesis. It shouldn't be, given that I discovered this algorithm -- but somehow "I take the Fourier Transfer of the FreeBSD kernel" sounds more like the punch line to a joke than the first step in an algorithm.

Speaking of incredibly cool algorithms based on Fourier transforms, the Schoenage-Strassen algorithm for multiplying integers is also amazing:

http://en.wikipedia.org/wiki/Sch%C3%B6nhage%E2%80%93Strassen...

At least to me, it seems hard to imagine that multiplying two N-bit integers could be done with less than O(N^2) operations. Schoenage-Strassen lets you do it using O(N log N log log N) operations!

Post reply on HN