Algorithm design 3rd homework