added stochastic and two-pass algorithms