Exercise 4.1-3 of CLRS