implemented probabilistic algorithm