chapter 8 exercise : implement some standard algorithms