How to design a finite state automaton that recognises the languages like $1^n 0^n$

373 Views Asked by At

The question goes like this: Design a finite state automaton that accepts binary strings with at least two $0$s and at most two $1$s.

I can easily design an NFA which accepts at least two $0$s OR at most two ones.

Additional question, how do you write regular expressions for automatas like these?

I cant get this method to work to generate regular expressions.

EDIT: Here is a photo of the solution. https://i.stack.imgur.com/CxLDU.jpg

EDIT 2: In the photo S5 will have a 0 to itself and S8 is the accepting state.

2

There are 2 best solutions below

1
On BEST ANSWER

Use an automaton with the following states

  • Have seen no 0 and no 1
  • Have seen one 0 and no 1
  • Have seen at least two 0 and no 1
  • Have seen no 0 and one 1
  • Have seen one 0 and one 1
  • Have seen at least two 0 and one 1
  • Have seen no 0 and two 1
  • Have seen one 0 and two 1
  • Have seen at least two 0 and two 1
  • Have seen at least three 1

with the obvious transitions and accepting states among these.

0
On

The general idea to simulate two finite automata running at once, here independent counting processes with

  • $Q_1$: $3$ states for counting digit $0$: counted $0$, $1$, $2$ or more digits
  • $Q_2$: $4$ states for counting digit $1$: counted $0$, $1$, $2$, $3$ or more digits

is to construct the product states $Q_1 \times Q_2$ and the product automaton, as demonstrated by Hagen's solution.