Implementation of algorithms in Java and Ruby