implementation of various algorithms