Simulate a running of the algorithm presented in the book.