algorithms exercise