Finite automata where the difference in the number of a's and b's is less than three

613 Views Asked by At

Given the following problem:

Design a finite automata that only recognizes the strings of the language $L$ of the alphabet $\sum = \{ a, b \}$ such that each string does not contain any prefixes where the difference between the number of letters $a$ and letters $b$ is more than three.

I am having difficulties conceptualizing this and I was thinking of trying to create a grammar in hopes that it would help but no luck.

How do I put this into concept?

1

There are 1 best solutions below

0
On

You can easily construct an automaton that counts the number of $a$'s minus the number of $b$'s, as long as that number stays between $-4$ and $+4$.

If that difference stays between $-3$ and $+3$ until the end of the string, then the string is accepted.

If that difference ever gets to either $-4$ or $+4$, then the string is immediately rejected.