Basic algorithms implemented in java