practicing implementing algorithms in java