Code for some algorithms