0

How can we make a DFA for given condition in title from alphabets {0,1} (binary).

What can be the regular expression for this?

My calculated expression is (a+b)*a(a+b)(a+b) , please correct me if i'm wrong and help find the correct expression and it's DFA.

WizWarrior
  • 1
  • 1
  • 2
  • 4

3 Answers3

3

You probably want to substitute $a$ with $1$ and $b$ with $0$ but apart from that your solution is correct.

Finding an equivalent NFA is easy with Thompson, Glushkov etc. From that you can derive an DFA via powerset construction. However, for this short expression you also can just write the DFA down. Imagine the states as storage what the last 3 symbols were, and accept if the third last was a 1, i.e. name the states 000 to 111 where 000 is the initial state and all states with a leading 1 are accepting. A transition is just a shift-left with the last read symbol on the right, i.e. $\delta(abc, d) = bcd$, with $a,b,c,d \in \{0,1\}$.

ttnick
  • 2,034
  • 10
  • 19
1

Your regular expression is correct.

For a DFA, in this case it's easier to define it than to draw it. Formally, defining a DFA means choosing an alphabet, a state set, a start state, an accepting set, and a transition function.

Alphabet: $\Sigma = \{0,1\}$ as specified.

State set: The states are ordered triples $(x,y,z)$ where $x$, $y$, and $z$ are either 0, 1, or Null. These represent the last three symbols seen.

Start state: Start in state (Null, Null, Null). We haven't seen any symbols yet, with Null meaning "no symbol seen yet".

Accepting set: A state $(x, y, z)$ is accepting if $x$ is 1. That is, we accept if the third symbol from the end was a 1.

Transition function: If you're in state $(x, y, z)$ and you see symbol $s$, you transition into state $(y, z, s)$.

This fully defines the DFA, without needing to draw it out (which is more complicated for this question).

Draconis
  • 7,216
  • 1
  • 19
  • 28
-1

enter image description here

Check this out , it's not neat but it will get the work done. Correct me if i'm wrong in this DFA.

WizWarrior
  • 1
  • 1
  • 2
  • 4