Open In App

DFA that Accepts All the Strings With At Least 1 ‘a’ and Exactly 2 b’s

Last Updated : 08 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Deterministic Finite Automata(DFA) is also known as Deterministic finite state automata(DSA). DFA is a Mathematical model of computation it is an abstract machine used to recognize patterns, it takes a string as input and changes its states accordingly when the desired terminal is found, then the transition occurs. At the time of transition, the automata can either move to the next state or stay in the same state.

It has two types of states:

1. ACCEPT(final state):A string is accepted means it reaches the final state.
2. REJECT(non-final state): A string is rejected means it does not reach the final state. 

Definition of DFA

Deterministic Finite Automata can be formally represented using five tuples(Q, Σ, δ, q0 F), where 

Q- finite non-empty set of states
Σ- finite non-empty set of input terminals
δ- transition function defined as a mapping
δ: Q ×E ->Q
q0 ∈ Q - is the initial state
F ∈ Q - is a set of final states

In this article, two instructions are given –

  • DFA should have at least 1 a
  • DFA should have exactly 2 b’s

This DFA should accept strings such as abb, bab, and bba.

Steps for Designing DFA

Step 1:

Take an initial state A; the minimum possible string is abb

  • The first transition from A-B for input a.
  • Next transition from B-C for input b.
  • Next transition from C-D for input b. And D is the final state(shown in the figure).
Step1

Step1

Step 2:

As we need at least 1 ‘a’ then there can n number of a’s can be accepted on state B(will be shown in following image).

  • The next minimum string automata can accept is ‘bab’. 
  • The first transition from A-E for input b.
  • Next transition from E-C for input a.
  • Next transition from C-D for input b. And self-loop is made for repetitive A’s.

Note: Self-loop is a state that can accept n number of letters followed by rules of construction of DFA.

Step2

Step2

But have you thought about what will happen if we get another ‘b’ at the final state i.e. ‘D’. The answer will be shown in the next step.

Step 3:

The following minimum string automata should accept is ‘bba’. Let’s construct a DFA. 

  • The first transition from A-E for first input b.
  • Next transition from E-F for the second b.
  • Next transition from E-D for input a.

A new State ‘T’ is introduced which means Trap state or dead state which means the string is not accepted.

Step3

Step 3

In this article, we have drawn a DFA that Accepts All the Strings With At Least 1 ‘a’ and Exactly 2 b’s. The required steps are mentioned in the article. You can follow them to get similar results also.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads