- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- 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 Questions & Answers
- Construct DFA of a string in which the second symbol from RHS is ‘a’
- Construct DFA beginning with ‘a’ but does not have substring ‘aab’
- Construct DFA with Σ= {0,1} accepts all strings with 0.
- Validate input: replace all ‘a’ with ‘@’ and ‘i’ with ‘!’JavaScript
- C Program to construct a DFA which accepts L = {aN | N ≥ 1}
- Program to build DFA that starts and ends with ‘a’ from the input (a, b)
- What is the use of ‘ALL’, ‘ANY’, ’SOME’, ’IN’ operators with MySQL subquery?
- Replacing ‘public’ with ‘private’ in “main” in Java
- Why in MySQL, we cannot use arithmetic operators like ‘=’, ‘<’ or ‘<>’ with NULL?
- MySQL query to search a string ‘demo’ if someone mistakenly types ‘deom’?
- Program to build DFA that starts and end with ‘a’ from input (a, b) in C++
- Design a DFA that accepts at most 3 a"s
- How to Use ‘cat’ and ‘tac’ Commands with Examples in Linux
- In the query [SELECT column1, column2 FROM table_name WHERE condition; ] which clause among ‘SELECT’, ‘WHERE’ and ‘FROM’ is evaluated in the last by the database server and why?
- Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ in C++