# DFA of a string in which 2nd symbol from RHS is ‘a’

Prerequisite – Finite Automata Introduction

**Problem –** 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

**For example:**

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:

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.

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.

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.

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’.

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

## Recommended Posts:

- DFA of a string in which 3rd symbol from RHS is ‘a’
- Symbol Table in Compiler
- DFA of a string with at least two 0’s and at least two 1’s
- Turing Machine to check whether given string is Even Palindrome or not
- Physical and Logical Data Independence
- Data Models in DBMS
- Difference between First Come First Served (FCFS) and Longest Job First (LJF) CPU scheduling algorithms
- Difference between Longest Job First (LJF) and Round Robin (RR) scheduling algorithms
- Difference between LOOK and C-LOOK Disk scheduling algorithms
- RAG Full Form
- Precedence Graph in Operating System
- Concurrency in Operating System
- Minimal to Canonical Form Conversion
- Loop Optimization Techniques | Set 2

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.