Java implementation of some algorithms