algorithm pattern practice