Lurker News

Comments (491) 209 threads

Earlier comments
pimmen#
This is like choosing your favorite friend, I love a lot of algorithm's in their own, special way. I could also answer in families of algorithms, but that would be cheating. Some of my favorites have already been mentioned, too.

So, I'll mention Monte Carlo integration. It's very simple to implement, it was one of the first tasks my first CS professor gave freshman students, and he did it for the same reason I love it; it gives such profound insights about how computers can solve complex mathematical problems humans can't. I shiver every time I solve a problem with a Monte Carlo method.

drjesusphd3 replies#
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 this method. So if you have just 10 sampling points, you can calculate exactly the integral of a 19th order polynomial (times, perhaps, some known weighting function).

blt1 reply#
what?? the solution set is infinite, how does it choose?
stabbles#
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-----
justinpombrio#
That's a neat algorithm. You could also do part of a Fisher-Yates shuffle, if you're ok allocating the array.
venantius1 reply#
Surprised nobody's mentioned Hyper Log Log (or its more recent variants). A probabilistic constant-space unique cardinality estimator (i.e. if I see a billion events, how many are unique?) that also supports set operations.
dswalter#
The underlying reasoning behind PCSA/HLL (that if you squint, you can use the zeros and ones from a hash as analogues to coin-flipping, and can use the probability of the rarest event seen to estimate the total number of events seen) is excellent.

Count-min-sketch is also beautifully simple.

Load more comments