VOOZH about

URL: https://www.geeksforgeeks.org/theory-of-computation/dfa-of-a-string-in-which-2nd-symbol-from-rhs-is-a/

⇱ DFA of a string in which 2nd symbol from RHS is 'a' - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

DFA of a string in which 2nd symbol from RHS is 'a'

Last Updated : 2 Feb, 2024

Draw deterministic finite automata (DFA) of the language containing the set of all strings over {a, b} in which 2nd symbol from RHS is 'a'. The strings in which 2nd last symbol is "a" are:

aa, ab, aab, aaa, aabbaa, bbbab etc

Input/Output

INPUT : baba

OUTPUT: NOT ACCEPTED

INPUT: aaab

OUTPUT: ACCEPTED

Constructing the DFA of the given problem directly is very complicated. So, here we are going to design the non-deterministic finite automata (NFA) and then convert it to the deterministic finite automata (DFA). The NFA of the language containing all the strings in which 2nd symbol from the RHS is "a" is:

👁 NFA

Here, A is the initial state and C is the final state. Now, we are going to construct the state transition table of the above NFA.

👁 State Transition Diagram 1

After that we will draw the state transition table of DFA using subset configuration on the state transition table of NFA. We will mention all the possible transition for a and b.

👁 State Transition Diagram 2

Now it's become very easy to draw the DFA with the help of its transition table. In this DFA, we have four different states A, AB, ABC and AC, where ABC and AC are the final states and A is the initial state of the DFA.

👁 DFA

This is our required DFA of the language containing the set of all strings over {a, b} in which 2nd symbol from RHS is 'a'.

Transition Table

STATESINPUT (a)INPUT (b)
---> A (initial state)ABA
ABABC* (final state)AC* (final state)
AC* (final state)ABA
ABC* (final state)ABC* (final state)AC* (final state)

C++ & Python Implementation

Output

Input: aaab

Output: string accepted

Input: baba

Output: string not accepted

Conclusion

Non-deterministic finite automata (NFA) simplifies building deterministic finite automata (DFA) for languages with specified patterns, such as strings with the 2nd symbol from the right being 'a'. This method simplifies and organizes DFA construction. Automata theory benefits from this method for representing and processing complex linguistic patterns.

Comment
Article Tags:

Explore