python implementation of algorithms