We describe in detail an efficient algorithm for studying site or bond perc
olation pn any lattice. The algorithm can measure an observable quantity in
a percolation system for all values of the site or bond occupation probabi
lity from zero to one in an amount of time that scales linearly with the si
ze of the system. We demonstrate our algorithm by using it to investigate a
number of issues in percolation theory, including the position of the perc
olation transition for site percolation on the square lattice, the stretche
d exponential behavior of spanning probabilities away from the critical poi
nt, and the size of the giant component for site percolation on random grap
hs.