codes for some algorithms