Introducton To Algorithm 3rd Edition by CLRS.