From the 3rd edition of M. Sipser's Theory of Computation