Added algorithm for exercise b).