Different Algorithm implementations in Java