Codes in book 'Introduction to Algorithms, 3rd Edition'.