Determining optimal order for task completion