2
{w∈{a,b}∗|w has baba as a substring} 

I am confused with this. How can I capture the following input for example?

aaababa
abbbaba
ababbba
ababaaaa

It seems there must always be baba in either middle or start or end. I must decide whether to put it always in start or middile or end?

Thanks

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
webiondev
  • 135
  • 1
  • 7

1 Answers1

3

By the Myhill-Nerode theorem, the states are:

  • Already matched 'baba' (accepting state)
  • Immediately after 'bab', and haven't matched 'baba'
  • Immediately after 'ba', and haven't matched 'baba'
  • Immediately after 'b', and none of the above
  • None of the above (start state)

It's essentially the same DFA created by the Knuth-Morris-Pratt search algorithm.

Matt Timmermans
  • 53,709
  • 3
  • 46
  • 87