this program is instance of a algorithm  on the book-introduction to algorithms.