Java implementation of various algorithms