July 16, 2012

Particles in the Universe and Algorithms


My physics binge continues.
Here's a cool explanation for why we say there are 4x10^79 atoms in the universe.

This is a useful number to know, since it has some interesting implications for algorithms in computer science. Often, if we try to solve a problem using a brute force search ("try every possible solution, and then see if one of them solves the problem"), our algorithm will run really, really slowly for even small problems.

For instance, some brute force algorithms run in O(2^n) time. This means that as that as the problem grows linearly, the time it takes to find a solution grows exponentially. For instance, if it took me 2^10 = 1024 seconds to sort a deck to 10 cards, it will take me 2^11 = 2048 seconds to sort a deck of 11 cards, and 2^40 = 1,099,511,627,776 seconds to sort a deck of 40 cards.

Our first reaction might be to say, so what? Computers are fast as shit, and they keep getting faster, so we don't need to worry about it.

Ah, but we do. What if I want to use our shitty algorithm to sort a deck of 200 cards? This will take 2^200 seconds to do. And since 2^200 > 4x10^79, this is more seconds than there are particles in the known universe.

What this means is that we'll never have a computer that's fast enough to solve this problem using our shitty exponential time algorithm: even if we had a computer that uses every particle in the universe to perform one calculation a second, it wouldn't be fast enough.

In other words,even if we use the universe itself as a calculator, we're fucked. And that's why people search for faster algorithms to problems, instead of simply trying to make faster computers.

No comments: