Source: http://www.math.uaa.alaska.edu/~afkjm/csce351/handouts/finite-automata.pdf