implementation of some algorithms