algos from chapter 3