implementation of the various algorithms