Basic algorithm and data structure implementation in Java