Exercise for "Introduction to Algorithms"