0% found this document useful (0 votes)
102 views49 pages

DFA Design Problems Lect-3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views49 pages

DFA Design Problems Lect-3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 49

Designing of DFA

Designing of DFA
• The problems can be classified in to two types:
• They are Type-1 and Type-2
• Type-1 Problems: languages consisting of strings ending with a
particular substring.
• Type-2 Problems: languages consisting of strings starting with a
particular substring.
Construction Of DFA-Type-01
Problems-
• In Type-01 problems, we will discuss the construction of DFA for
languages consisting of strings ending with a particular substring.
• Steps To Construct DFA-
• Step-01:Determine the minimum number of states required in the DFA.
• Draw those states.
• Use the following rule to determine the minimum number of states-

RULE
Calculate the length of substring.
All strings ending with ‘n’ length substring will always require
minimum (n+1) states in the DFA.
Construction Of DFA-Type-01
Problems-
• Step-02:
• Decide the strings for which DFA will be constructed.
• Step-03:
• Construct a DFA for the strings decided in Step-02.
• Remember the following rule while constructing the DFA-
RULE
While constructing a DFA,
Always prefer to use the existing path.
Create a new path only when there exists no path to go with.
Step-04:
•Send all the left possible combinations to the starting state.
•Do not send the left possible combinations over the dead state.
Example -1
• Design a DFA for the language accepting strings ending with ’01’ over
input alphabets ∑ = {0, 1}
• Regular expression for the given language = (0 + 1)*01
• Step-01:
• All strings of the language ends with substring “01”.
• So, length of substring = 2.
• Thus, Minimum number of states required in the DFA = 2 + 1 = 3.
• It suggests that minimized DFA will have 3 states.
Example -1
• Step-02:
• We will construct DFA for the following strings-
• L= { 01, 001, 0101, . . .}
• Step-03:The required DFA is-

Problem-02:
Draw a DFA for the language accepting
strings ending with ‘abb’ over input
alphabets ∑ = {a, b}
• Regular expression for the given language = (a + b)*abb
• Step-01:
• All strings of the language ends with substring “abb”.
• So, length of substring = 3.
• Thus, Minimum number of states required in the DFA = 3 + 1 = 4.
• It suggests that minimized DFA will have 4 states.
• Step-02:
• We will construct DFA for the following strings-
• L ={ abb, aabb, ababb, abbabb, . . . }
Problem-02:
• Step-03:
• The required DFA is-
Problem-03:
Draw a DFA for the language accepting strings ending with
‘abba’ over input alphabets ∑ = {a, b}
• Regular expression for the given language = (a + b)*abba
• Step-01: All strings of the language ends with substring “abba”.
• So, length of substring = 4.
• Thus, Minimum number of states required in the DFA = 4 + 1 = 5.
• It suggests that minimized DFA will have 5 states.
• Step-02: We will construct DFA for the following strings-
• L ={ abba, aabba, ababba, abbabba, abbaabba, . . .}

Problem-03:
• Step-03: The required DFA is-
Problem-04:
Draw a DFA for the language
accepting strings ending with
‘0011’ over input alphabets ∑ =
• Regular expression for the given language = (0 + 1)*0011
{0, 1}
• Step-01: All strings of the language ends with substring “0011”.
• So, length of substring = 4.
• Thus, Minimum number of states required in the DFA = 4 + 1 = 5.
• It suggests that minimized DFA will have 5 states.
• Step-02:
• We will construct DFA for the following strings-
• Let L = { 0011, 00011, 000011, 0010011, 00110011, . . . }
Problem-04:
• Step-03:
• The required DFA is-
Type-02 Problems-
• In Type-02 problems, we will discuss the construction of DFA for
languages consisting of strings starting with a particular substring.
• Step-01: Determine the minimum number of states required in the
DFA. Draw those states. Use the following rule to determine the
minimum number of states-
• RULE
Calculate the length of substring.
All strings starting with ‘n’ length substring will always require minimum (n+2)
states in the DFA.

Step-02: Decide the strings for which DFA will be constructed.


Type-02 Problems-

• Step-03: Construct a DFA for the strings decided in Step-02.


• Remember the following rule while constructing the DFA-
RULE
While constructing a DFA,
Always prefer to use the existing path.
Create a new path only when there exists no path to go with.
Step-04:
Send all the left possible combinations to the dead state.
Do not send the left possible combinations over the starting state.
Example Problem-01:
Draw a DFA for the language accepting
strings starting with ‘ab’ over input
alphabets ∑ = {a, b}
• Regular expression for the given language = ab(a + b)*
• Step-01:
• All strings of the language starts with substring “ab”.
• So, length of substring = 2.
• Thus, Minimum number of states required in the DFA = 2 + 2 = 4
• It suggests that minimized DFA will have 4 states.
• Step-02: We will construct DFA for Language L with the following
strings-
• L={ ab, aba, abab, … }

Example Problem-01:

Step-03: The required DFA is-


Example Problem-02:
Draw a DFA for the language accepting
strings starting with ‘a’ over input
alphabets ∑ = {a, b}
• Regular expression for the given language = a(a + b)*
• Step-01: All strings of the language starts with substring “a”.
• So, length of substring = 1.
• Thus, Minimum number of states required in the DFA = 1 + 2 = 3.
• It suggests that minimized DFA will have 3 states.
• Step-02: We will construct DFA for the L with following strings-
• L={ a, aa, ….}
• Step-03: The required DFA is
Example Problem-03:
Draw a DFA for the language accepting
strings starting with ‘101’ over input
alphabets ∑ = {0, 1}
• Regular expression for the given language = 101(0 + 1)*
• Step-01:
• All strings of the language starts with substring “101”.
• So, length of substring = 3.
• Thus, Minimum number of states required in the DFA = 3 + 2 = 5.
• It suggests that minimized DFA will have 5 states.
• Step-02:
• We will construct DFA for the Language L withy the following strings-
L={ 101, 1011,
10110, 101101, . . .}
Example Problem-04:
Draw a DFA that accepts a language L over input
alphabets ∑ = {0, 1} such that L is the set of all
strings starting with ’00’.
• Regular expression for the given language = 00(0 + 1)*
• Step-01:
• All strings of the language starts with substring “00”.
• So, length of substring = 2.
• Thus, Minimum number of states required in the DFA = 2 + 2 = 4.
• It suggests that minimized DFA will have 4 states.
• Step-02:
• We will construct DFA for the L with the following strings-L={ 00, 000,
00000, . . .}
• Step-03:The required DFA is-
Example Problem-05:
Construct a DFA that accepts a language L over
input alphabets ∑ = {a, b} such that L is the set of
all strings starting with ‘aa’ or ‘bb’.
• Regular expression for the given language = (aa + bb)(a + b)*
• Step-01:
• Minimum number of states required in the DFA = 5.
• It suggests that minimized DFA will have 5 states.
• Step-02:
• We will construct DFA for the L with the following strings-
• L={ aa, aaa, aaaa, bb, bbb, bbbb, . . .}

Example Problem-05:

• Step-03:
• The required DFA is-
Example Problem-06:
Construct a DFA that accepts a language L over
input alphabets ∑ = {a, b} such that L is the set of
all strings starting with ‘aba’.
• Regular expression for the given language = aba(a + b)*
• Step-01:
• All strings of the language starts with substring “aba”.
• So, length of substring = 3.
• Thus, Minimum number of states required in the DFA = 3 + 2 = 5.
• It suggests that minimized DFA will have 5 states.
• Step-02:
• We will construct DFA for the following L with strings-
• L={ aba, abaa, abaab, abaaba, . . .}

Example Problem-06:

• Step-03:
• The required DFA is-
Examples of DFA
• Design a FA with ∑ = {0, 1} accepts those string which starts with 1
and ends with 0.
• Solution:
• The FA will have a start state q0 from which only the edge with input
1 will go to the next state.

• In state q1, if we read 1, we will be in state q1, but if we read 0 at


state q1, we will reach to state q2 which is the final state. In state
q2, if we read either 0 or 1, we will go to q2 state or q1 state
respectively. Note that if the input ends with 0, it will be in the
final state.
Example 2:

• Design a FA with ∑ = {0, 1} accepts the only input 101.


• Solution:

• In the given solution, we can see that only input 101 will be accepted.
Hence, for input 101, there is no other path shown for other input.
Example 3:
• Design FA with ∑ = {0, 1} accepts even number of 0's and even number of
1's.
• Solution:
• This FA will consider four different stages for input 0 and input 1. The
stages could be:
• Here q0 is a start state and the final state also. Note carefully that a
symmetry of 0's and 1's is maintained. We can associate meanings to each
state as:
• q0: state of even number of 0's and even number of 1's.
q1: state of odd number of 0's and even number of 1's.
q2: state of odd number of 0's and odd number of 1's.
q3: state of even number of 0's and odd number of 1's.
Example 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:
Example 5:
• Design a DFA L(M) = {w | w ε {0, 1}*} and W is a string that does not
contain consecutive 1's.
• Solution: When three consecutive 1's occur the DFA will be:

• Here two consecutive 1's or single 1 is acceptable, hence

• The stages q0, q1, q2 are the final states. The DFA will generate the strings
that do not contain consecutive 1's like 10, 110, 101,..... etc.
Example 6:

• Design a FA with ∑ = {0, 1} accepts the strings with an even number of


0's followed by single 1.
• Solution:
• The DFA can be shown by a transition diagram as:
DFA Exercises
1. Give a DFA for Σ = {0, 1} and strings that have an odd number of 1’s
and any number of 0’s.
2. Give a DFA for Σ = {a, b, c} that accepts any string with aab as a
substring.
3. Give a DFA for Σ = {a, b} that accepts any string with aababb as a
substring.
Solution to Problem 1

0 0

1
Solution to Problem 2
b,c a,b,c

b,c
Solution to Problem 3

b
Construct DFA to accept (0+1)*

1
Construct DFA to accept 00(0+1)*

0
0 0

1 1
1

0 1
(0+1)*00(0+1)*
• Idea: Suppose the string x1x2 ···xn is on
the tape. Then we check x1x2, x2x3, ...,
xn-1xn in turn.
• Step 1. Build a checker

0 0
• Step 2. Find all edges by the following consideration:
Consider x1x2.
• If x1=1, then we give up x1x2 and continue to check
x2x3. So, we have δ(q0, 1) = q0.
• If x1x2 = 01, then we also give up x1x2 and continue to
check x2x3. So,
δ(q1, 1) = δ(q0, 1) =q0.
• If x1x2 = 00, then x1x2··· xn is accepted for any x3···xn.
So, δ(q2,0)=δ(q2,1)=q2.
(0+1)*00(0+1)*

1 0

0 0

1
1
(0+1)*00
0
1

0 0

1
In general, suppose x1 x2 … xn is the string on the tape
And we want check x1 …xk, x2 …xk+1, …, in turn. If x1…xk
Is not the substring that we want and we need to check
x2…xk+1, then we set that for and i < k,
δ( δ(s, x1 …xi), xi+1) = δ(s, x1…xi xi+1).
(0+1)*(00+01)
1 0

0 0

1 1

0
1
2nd Solution-Parallel Machine
L(M) = (0+1)*00 M=(Q, Σ, δ, s, F)
L(M’)= (0+1)*01 M’=(Q’, Σ, δ’, s’, F’)
L(M’’) = (0+1)(00+01) = L(M) U L(M’)
Q’’ = {(q, q’) | q in Q, q’ in Q’}
δ’’((q, q’), a) = (δ(q, a), δ’(q’, a))
s’’ = (s, s’)
F’’ = { (q, q’) | q in F or q’ in F’ }.
1 0 1 0

0 0 0 1
c
a b c a 0
b
1 1

1
1 0

a 0 b 0 c
a b b
1
1
0
a 1
c
Union, Intersection, subtraction
Union: F’’ = {(q,q’) | q in F or q’ in F’}
Intersection: F’’= {(q,q’) | q in F and q’ in F’}
Subtraction: L(M) \ L(M’)
F’’ = {(q,q’) | q in F and q’ not in F’}
1 0 1 0

0 0 0 1
c
a b c a 0
b
1 1

1
1 0

a 0 b 0 c
a b b
1
1
0 (0+1)*00 ∩ (0+1)*01
a 1
c

c
c
1 0 1 0

0 0 0 1
c
a b c a 0
b
1 1

1
1 0

a 0 b 0 c
a b b
1
1
0 (0+1)*00 \ (0+1)*01
a 1
c
Complement
• L(M’)= Σ*-L(M)
F’ = Q - F
1
0

0 0

(0+1)*00
The set of all binary strings beginning
with 1 which interpreted as a binary
representation of an integer, is
congruent to zero modulo 5.
• Idea: To construct a DFA, we need to figure out what
should be states and where each edge should go.
Usually, states can be found through studying the
condition for accepting. The condition for accepting a
string x1x2···xn is x1x2···xn ≡ 0 mod(5). So, we first
choose residues 0, 1, 2, 3, 4 as states.
2i + 0 ≡ ? (mod 5)
2i + 1 ≡ ? (mod 5)

1
0
1 2
1
0
0 1 1
1
1
0 3 0 4

0
0

0,1

You might also like