- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Draw DFA which accepts the string starting with ‘ab’.

## Problem

Draw the state transition diagram over an alphabet Σ={a,b} that accepts the string starting with ‘ab’.

## Solution

The formal definition of Deterministic Finite Automata (DFA) is as follows −

A DFA is a collection of 5-tuples as shown below −

**M=(Q, Σ, δ,q0,F)**

Where,

- Q: Finite set called states.
- Σ: Finite set called alphabets.
- δ: Q × Σ → Q is the transition function.
- q0 ∈ Q is the initial state.

The language is generated as given below −

L={ab,aba,abab,…….}

The transition diagram is as follows −

Here,

- D is a dead state.
- D is a transition state, which it can never escape. Such a state is called a trap state. It is called the dead state.

## Example 1

**ab**− q1 on’ a’ goes to q2 and q2 on ‘b’ goes to qf to reach final state. So, ab is accepted.**baa**− q1 on ‘b’ goes to D state, which is dead state. There is no way to reach the final state. So, baa is not accepted.

## Transition table

The transition table is as follows −

State/Input symbol | a | b |
---|---|---|

∈q1 | q2 | Dead state (D) |

q2 | Dead state (D) | qf |

qf | qf | qf |

D | - | - |

## Explanation

**Step 1**− q1 is an initial state on input a it goes to state q2 and on ‘b’ goes to dead state.**Step 2**− q2 on ‘a’ goes to dead state and on ‘b’ goes to qf which is the final state.**Step 3**− qf is the final state on input ‘a’ and ‘b’ goes to qf state itself.**Step 4**− D is a dead state, there is no path from D to any state.

## Example 2

Design a DFA which accepts a language over the alphabets Σ = {a, b} such that L is the set of all strings starting with ‘aba’.

All strings start with the substring “aba”.

Therefore, length of substring = 3.

Minimum number of states in the DFA = 3 + 2 = 5.

The language L= {aba,abaa,abaab,abaaba}

The transition diagram is as follows −

## Transition table

The transition table is as follows −

State/Input symbol | a | b |
---|---|---|

∈q0 | q1 | Dead state (D) |

q1 | Dead state (D) | q2 |

qf | qf | qf |

D | - | - |

- Related Articles
- Construct DFA with Σ= {0,1} accepts all strings with 0.
- C Program to construct a DFA which accepts L = {aN | N ≥ 1}
- Design a DFA that accepts at most 3 a"s
- Python Program to accept string starting with vowel
- Construct DFA of a string in which the second symbol from RHS is ‘a’
- How can I filter string value with starting letter?
- Draw a circle with centre at point $O$ and radius $5 cm$. Draw its chord $AB$, draw the perpendicular bisector of line segment $AB$. Does it pass through the centre of the circle?
- Draw a circle with centre at point $O$. Draw its two chords $AB$ and $CD$ such that $AB$ is not parallel to $CD$. Draw the perpendicular bisectors of $AB$ and $CD$. At what point do they intersect?
- Construct DFA for strings not ending with "THE"
- Find the row means for columns starting with a string in an R data frame.
- Find the Number of Unique Permutations Starting with 1 of a Binary String using C++
- DFA for Strings not ending with “THE” in C++?
- Smallest String Starting From Leaf in Python
- Explain the operation of DFA with block diagram in TOC
- Query MongoDB collection starting with _?