by SerpentJoe · 11y ago · 0 comments
┌┐
↓│
┌────┴┐
┌─→│ │←──┐
│ └─────┘ │
╔════╧═╗ ┌──┴──┐
├─→║ ╟───A──→│ │
╚══════╝ └─┬───┘
↑ │
└─────A,B────┘
Three states if you want to process the whole input. If your model is "reject when you fail to find an appropriate transition" rather than "reject if, after processing the string, you're in a reject state", then you don't need the failure trap and you can do it in two states.Backtracking is definitely not required, nor helpful.
See https://swtch.com/~rsc/regexp/ for information on finite-state-machine implementations of regexp matching.
What? Why is that? If the NFA has n states, then the DFA in principle might need one state for every possible set of states the NFA might be in, of which there are 2^n. Where does n^2 come from?