Design of Dfa

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Amritsar College of Engineering & Technology, Amritsar, Punjab, INDIA

NAAC - A grade, NBA accredited courses(2009-12, 2016-18), UGC Autonomous College

SUBJECT: THEORY OF COMPUTATIONS


TOPIC: Design of DFA

Er. Pavitar Singh


Assistant Professor
Department of Computer Science and
Engineering

11 Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


OBJECTIVES

After going through this topic, you should be able to:

• Understand the concept of designing a DFA;


• learn the various examples.

Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


22
How to construct a DFA ?

Procedure for designing a DFA

 Step 1: Decide what a DFA need to memorize,


 Step 2: How many states do we need?
 Step 3 : Construct the language,
 Step 4: Construct the transition diagram using minimum states.

Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


3
1. Construct a DFA which accepts set of all strings over ∑ = {a,b} of length 2.

Solution:

Explanation

1.We have to create DFA which will accept string of length 2 on alphabet {a,
b}
2.So first thing about creating DFA which will accept of 1 length string, that
is pretty simple
3.You just take 2 states, 1 length string can be accepted. Now take 2 length
string for that we need 3 states

Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


4
4. And third state will be final state.
5. But what if we came up with a string of length 3, it should not be
accepted in our DFA, right ?
6. So we have to attach one more state to take care of string greater than 2.
7. State 'D' is called dead state.

5 Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


2.Construct a DFA which accepts set of all strings over
Σ={a,b} of length ≥2

Explanation
We have to create DFA which will accept string of length ≥ 2 on alphabet {a, b}.
1. So again first thing about creating DFA which will accept of 1 length string,
that is pretty simple.
2. You just take 2 states 1 length string can be accepted.
3. Now take 2 length string for that we need 3 states.
4. And third state will be final state.
5. And if input comes over state C then it will go to C itself to accept strings
greater than 2
6. Now if string < 2 will not reach final state, so will not be accepted.

6 Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


Testing
1. Suppose we have abab, so take alphabets from left to right
2. firstly 'a' came on start state A, then we will go to state B
3. then input came as 'b', so on state B we will go to state C.
4. then 'a', we go to C itself
5. then 'b', we go to C itself
6. At the end of the string we are at final state, so we say that string is
accepted
7. And for the strings which are less than 2, you will not reach final state.

7 Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


3. Construct a DFA which accepts set of all strings over Σ={a,b} of
length ≤2

8 Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


Explanation
We have to create DFA which will accept string of length ≤ 2 on alphabet
{a, b}.

1. Think about the language content = {∈,a, b, ab, ba, bb, aa}
2. So again first thing about creating DFA which will accept of ∈, that is
first state will be final state
3. Then we have to accept single letter that is two states will be required
and second state also will be final state
4. Now we need to accept 2 input symbols one after another in case of aa
or ab or bb or ba
5. And strings which are greater than 3 should not be accepted.
6. So we have to attach 1 more state as dead state.

9 Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


4. Design FA with ∑ = {0, 1} accepts the set of all strings
with three consecutive 0's.

Solution:
 The strings that will be generated for this particular languages are 000,
0001, 1000, 10001, .... in which 0 always appears in a clump of 3. The
transition graph is as follows:

Note that the sequence of triple zeros is maintained to reach the


final state.

10 Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC


5.Design DFA to accepts L, where L is set of strings in which ‘a’
always appears tripled over ∑ = {a, b}.

11 Er. Pavitar Singh pavitar.cse@acetedu.in CSE 8 th Sem. TOC

You might also like