0% found this document useful (0 votes)
43 views30 pages

TCS Lect 6-7-8 DFA

TCS Lect 6-7-8 DFA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views30 pages

TCS Lect 6-7-8 DFA

TCS Lect 6-7-8 DFA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Finite Automata

Lecture 6

Prepared By: Mr. Vaibhav


Content

• Introduction to Finite Automata

• Definition of Deterministic Finite Automata ( DFA


)

• Examples on DFA

Prepared By: Mr. Vaibhav


Finite Automata

• There are two types of Finite Automata

1. Deterministic Finite Automata (DFA)

2. Non – deterministic Finite Automata (NFA)

• DFA is deterministic in nature. Each transition in this automata


is uniquely determined on current state and current input

• NFA is non – deterministic in nature. Next state can not be


determined uniquely for a given transition with current state
and current input
Prepared By: Mr. Vaibhav
Deterministic Finite Automata (DFA)

• The Finite Automata is called Deterministic Finite Automata (DFA) if


there is only one path for a specific input from current state to next state.

• E.g.
a
So S1 a

b
S2

• From state S0 for input 'a' there is only one path going to S1
• Similarly all the transitions can be described

Prepared By: Mr. Vaibhav


Definition of DFA
Deterministic Finite automata or DFA is defined as

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

Where

Q is a finite set of internal states

Σ is a finite set of symbols called the input alphabet

δ : Q X Σ → Q is a Total Function called Transition Function

q0 is an initial state q0 ε Q

F is a set of final states F ⊆ Q


Prepared By: Mr. Vaibhav
Definition of DFA
• Transition Function accepts two parameters one is current state
and other is input symbol

• It returns a state which can be called as next state

• It is described as δ : Q X Σ → Q

• For example:

q1 = δ ( q0, a) means from current state 'q0' with input a next


state transition is 'q1'

Prepared By: Mr. Vaibhav


Examples on DFA

Ex. 1 Design FA which accepts the only string 101 over Σ = { 0 , 1 }


Solution:
Transition Diagram:

1 0 1
q0 q1 q2 q3

Above DFA can be represented as Transition Table:


M = ( Q , Σ , δ , q0 , F ) Transition Function Input/ 0 1
States
Where Q = { q0, q1, q2, q3 } ( δ ):
qo -- q1
Σ = { 0, 1 } δ ( q0 , 1 ) = q1
q1 q2 --
q0 = q0 δ ( q1 , 0 ) = q2 q2 -- q3

F = { q3 } δ ( q2 , 1 ) = q3 q3 By: Mr.
Prepared -- Vaibhav
--
Examples on DFA
0
Ex. 2 Design FA which checks whether the given binary
number is even. q2
0
Solution:
Binary no is made up of 1's and 0's. Hence Σ = { 0 , 1 } 1
q0 0
When binary number is ended with 1 → Odd Number
When binary number is ended with 0 → Even Number q1
1
Above DFA can be represented as Transition Function 1
M = ( Q , Σ , δ , q0 , F ) ( δ ):
Transition Table:
Where Q = { q0, q1, q2 } δ ( q0 , 0 ) = q2
Input/ 0 1
Σ = { 0, 1 } δ ( q0 , 1 ) = q1 States
q0 = q0 δ ( q1 , 0 ) = q2 qo q2 q1
q1 q2 q1
F = { q2 } δ ( q1 , 1 ) = q1
q2 q2 q1
δ ( q2 , 0 ) = q2 Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 2 Design FA which checks whether the given binary number
is even.
Solution:
Transition Table:
The simulation to check whether given binary number is even or
not.
Input/ 0 1
Suppose input number is 11010 States
δ ( q0 , 1 1 0 1 0 ) |-- δ ( q1 , 1 0 1 0 ) qo q2 q1
|-- δ ( q1 , 0 1 0 ) q1 q2 q1
|-- δ ( q2 , 1 0 ) q2 q2 q1

|-- δ ( q1 , 0 )
|-- δ ( q2 , ε )
= q2
q2 is a final state.
Hence given number 11010 is accepted by given DFA
Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 2 Design FA which checks whether the given binary number is
even.
Solution:
The simulation to check whether given binary number is even or
Transition Table:
not.
Input/ 0 1
Suppose input number is 10101
States
δ ( q0 , 1 0 1 0 1 ) |-- δ ( q1 , 0 1 0 1 ) qo q2 q1
|-- δ ( q2 , 1 0 1 ) q1 q2 q1
|-- δ ( q1 , 0 1 ) q2 q2 q1
|-- δ ( q2 , 1 )
|-- δ ( q1 , ε )
= q1
q1 is not a final state.
Hence given number 10101 is not accepted by given DFA
Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 3 Design DFA which accepts only those strings which starts
with 1 and ends with 0 for Σ = { 0, 1 }.
Solution:
Above DFA can be
Regular expression = 1 . ( 0 + 1 )* . 0
Here, q1 represents strings start with 1 and end with 1 represented as
State q2 which represents strings start with 1 and end with zero M = ( Q , Σ , δ , q0 , F )
Transition Diagram: Where Q = { q0, q1, q2 }
1 0
1 Σ = { 0, 1 }
q0 q1 q2
q0 = q0
0
1 F = { q2 }
Transition Table:
Inputs
Transition Function ( δ ): 0 1
/States
δ ( q0 , 1 ) = q1 δ ( q2 , 0 ) q0 -- q1

= q2 q1 q2 q1
q2 q2 q1
δ ( q1 , 0 ) = q2 δ ( q2 , 1 ) Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 3 Design DFA which accepts only those strings which
starts with 1 and ends with 0 for Σ = { 0, 1 }.

Solution: Transition Table:


Simulation for the string 10010
δ ( q0 , 1 0 0 1 0 ) |-- δ ( q1 , 0 0 1 0 ) Input/ 0 1
States
|-- δ ( q2 , 0 1 0 )
q0 -- q1
|-- δ ( q2 , 1 0 ) q1 q2 q1
|-- δ ( q1 , 0 ) q2 q2 q1
|-- δ ( q2 , ε )
= q2
q2 is a final state.
Hence given string 10010 is accepted by given DFA

Prepared By: Mr. Vaibhav


Examples on DFA
0
Ex. 4 Design DFA which accepts odd number of 1's and any
number of 0's q1
1
Solution:
Here, Σ = { 0 , 1 } 1
q0 1
Here, q1 represents strings with odd number of 1's
State q2 represents strings with even number of 1's q2
0
Above DFA can be represented as Transition Function 0
M = ( Q , Σ , δ , q0 , F ) ( δ ):
Transition Table:
Where Q = { q0, q1, q2 } δ ( q0 , 1 ) = q1
Input/ 0 1
Σ = { 0, 1 } δ ( q0 , 0 ) = q2 States
q0 = q0 δ ( q1 , 0 ) = q1 qo q2 q1
q1 q1 q2
F = { q1 } δ ( q1 , 1 ) = q2
q2 q2 q1
δ ( q2 , 0 ) = q2 Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 4 Design DFA which accepts odd number of 1's and any
number of 0's
Solution:
Transition Table:
Simulation for the string 11010
δ ( q0 , 1 1 0 1 0 ) |-- δ ( q1 , 1 0 1 0 ) Input/ 0 1
|-- δ ( q2 , 0 1 0 ) States
qo q2 q1
|-- δ ( q2 , 1 0 )
q1 q1 q2
|-- δ ( q1 , 0 )
q2 q2 q1
|-- δ ( q1 , ε )
= q1
q1 is a final state.
Hence given string 11010 is accepted by given DFA

Prepared By: Mr. Vaibhav


Examples on DFA
Ex. 5 Design DFA to accept the string which always ends Above DFA can be
with 00 for Σ = { 0, 1 }.
represented as
Solution:
Regular expression = ( 0 + 1 )* . 00
M = ( Q , Σ , δ , q0 , F )

Here, q1 represents strings end with 0 Where Q = { q0, q1, q2 }


q2 represents strings end with 00 Σ = { 0, 1 }
q0 represents strings other than cases of q1 and q2 q0 = q0
Transition Diagram:
Transition
F Function
= { q2 }
0
0 0 (δ):
q0 q1 q2
δ ( q0 , 0 ) = q1
1
δ ( q0 , 1 ) = q0
1 δ ( q1 , 0 ) = q2

1
Prepared
δ ( q1 , By:
1)= Mr.q0
Vaibhav
Examples on DFA
Ex. 5 Design DFA to accept the string which always ends
with 00 for Σ = { 0, 1 }.
Solution:
Transition Table:
Simulation for the string 10100
δ ( q0 , 1 0 1 0 0 ) |-- δ ( q0 , 0 1 0 0 ) Input/ 0 1
|-- δ ( q1 , 1 0 0 ) States
qo q1 q0
|-- δ ( q0 , 0 0 )
q1 q2 q0
|-- δ ( q1 , 0 )
q2 q2 q0
|-- δ ( q2 , ε )
= q2
q2 is a final state.
Hence given string 10100 is accepted by given DFA

Prepared By: Mr. Vaibhav


Examples on DFA
Ex. 6 Design DFA to accept the strings of a's and b's ending with
abb over Σ = { a, b }. Above DFA can be
Solution: represented as
Regular expression = ( a + b )* . abb
M = ( Q , Σ , δ , q0 , F )
Here, q1 represents strings end with a
q2 represents strings end with ab Where Q = { q0, q1, q2,
Q3 represents strings end with abb q3 }
q0 represents strings other than cases of q1, q2 and q3
Σ = { a, b }
Transition Diagram:
a Transition Function
q0 = (q0
δ):
a b b δ ( q0 , a ) = F
q1 = { q3
δ (}q0 ,
q0 q1 q2 q3
b ) = q0
a a δ ( q1 , a ) = q1 δ ( q1 ,

b b ) = q2
b
δ ( q2 , a ) = q1 δ ( q2 , b )
= q3
Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 6 Design DFA to accept the strings of a's and b's ending
with abb over Σ = { a, b }
Solution:
Transition Table:
Simulation for the string baabb
δ ( q0 , b a a b b ) |-- δ ( q0 , a a b b ) Input/ a b
|-- δ ( q1 , a b b ) States
qo q1 q0
|-- δ ( q1 , b b )
q1 q1 q2
|-- δ ( q2 , b )
q2 q1 q3
|-- δ ( q3 , ε ) q3 q1 q0
= q3
q3 is a final state.
Hence given string baabb is accepted by given DFA

Prepared By: Mr. Vaibhav


Examples on DFA
Ex. 7 Construct DFA that accepts all the strings on Σ = { 0, 1 } except those Regular expression
containing the substring 101
= ( 0 + 1 )* . 101 . ( 0 + 1 )*
Solution:
Here, q1 represents strings end
Design DFA for accepting strings which has 101 as substring.
with 1
Final state is representing state which accepts strings having 101 as
substring. All other states representing other cases.
q2 represents strings end with
10
Therefore all other states will act as final states and final state will act as
normal state for given problem statement Q3 represents strings end with
Transition Diagram for DFA with 101 as 101 and strings with 101 as
0
substring: substring
1
q0 represents strings other than
1 0 1 cases of q1, q2 and q3
q0 q1 q2 q3

0
0

Prepared By: Mr. Vaibhav


Examples on DFA
Ex. 7 Construct DFA that accepts all the strings on Σ = { 0, 1 } except those
containing the substring 101
Above DFA can be represented

Solution: as
Invert all the Non Final states into Final states and Final state into non final state. M = ( Q , Σ , δ , q0 , F )
Required transition diagram is as follows: Where Q = { q0, q1, q2, q3 }

Transition Σ = { 0, 1 }
Diagram: q0 = q0
0
F = { q0, q1, q2 }
1
Transition Function ( δ ) :
1 0 1
qo q1 q2 q3 δ ( q0 , 0 ) = q0 δ ( q0 ,
1 ) = q1
1 δ ( q1 , 0 ) = q2 δ ( q1 , 1 )
0 = q1
0
δ ( q2 , 0 ) = q0 δ ( q2 ,
1 ) Prepared
= q3 By: Mr. Vaibhav
Examples on DFA
Ex. 7 Construct DFA that accepts all the strings on Σ = { 0,
1 } except those containing the substring 101

Transition Table:
Solution:
Simulation for the string 11001 Input/ 0 1
δ ( q0 , 1 1 0 0 1 ) |-- δ ( q1 , 1 0 0 1 ) States
qo q0 q1
|-- δ ( q1 , 0 0 1 )
q1 q2 q1
|-- δ ( q2 , 0 1 )
q2 q0 q3
|-- δ ( q0 , 1 ) q3 q3 q3
|-- δ ( q1 , ε )
= q1
q1 is a final state.
Hence given string 11001 is accepted by given DFA
Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 8 Design DFA to accept all the string in Language L such that Above DFA can be
total number of a's in them are divisible by three on Σ = { a, b }.
Solution: represented as
Regular expression: (b*ab*ab*ab*)* M = ( Q , Σ , δ , q0 , F )
Here, q0 represents strings with number of a's are divisible by 3
Where Q = { q0, q1, q2 }
q1 represents strings with number of a's are divisible by 3 plus one
q2 represents strings with number of a's are divisible by 3 plus two Σ = { a, b }
Transition Diagram: q0 = q0
b Transition
F Function
= { q0 }
b
a a (δ):
q0 q1 q2
δ ( q0 , a ) = q1
δ ( q0 , b ) = q0
b δ ( q1 , a ) = q2

a
Prepared
δ ( q1 , By:
b)= Mr.q1
Vaibhav
Examples on DFA
Ex. 8 Design DFA to accept all the string in Language L
such that total number of a's in them are divisible by three
on Σ = { a, b }.
Solution: Transition Table:
Simulation for the string baaba
Input/ a b
δ ( q0 , b a a b a ) |-- δ ( q0 , a a b a ) States
|-- δ ( q1 , a b a ) qo q1 q0
|-- δ ( q2 , b a ) q1 q2 q1

|-- δ ( q2 , a ) q2 q0 q2

|-- δ ( q0 , ε )
= q0
q0 is a final state.
Hence given string baaba is accepted by given DFA
Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 9 Design DFA which accepts even number of 0's and even number of Above DFA can be
1's over Σ = { 0, 1 }.
represented as
Solution:
Here, q0 represents strings with even number of 0's and even number of
M = ( Q , Σ , δ , q0 , F )
1's Where Q = { q0, q1, q2,
q1 represents strings with odd number of 0's and even number of 1's
q3 }
q2 represents strings with odd number of 0's and odd number of 1's
Σ = { 0, 1 }
q3 represents strings with even number of 0's and odd number of 1's
q0 = q0
Transition Diagram:
Transition Function ( δ ) : F = { q0 }
0
q0 q1
δ ( q0 , 0 ) = q1 δ ( q0 , 1 ) =
q3
0
1 1 1 1 δ ( q1 , 0 ) = q0 δ ( q1 , 1 ) =
0 q2
q3 q2 δ ( q2 , 0 ) = q3 δ ( q2 , 1 ) =
0 q1 Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 9 Design DFA which accepts even number of 0's and
even number of 1's over Σ = { 0, 1 }.
Solution:
Transition Table:
Simulation for the string 100010
δ ( q0 , 1 0 0 0 1 0 ) |-- δ ( q3 , 0 0 0 1 0 ) Input/ 0 1
|-- δ ( q2 , 0 0 1 0 ) States
qo q1 q3
|-- δ ( q3 , 0 1 0 )
q1 q0 q2
|-- δ ( q2 , 1 0 )
q2 q3 q1
|-- δ ( q1 , 0 ) q3 q2 q0
|-- δ ( q0 , ε )
= q0
q0 is a final state.
Hence given string 100010 is accepted by given DFA
Prepared By: Mr. Vaibhav
Examples on DFA
Ex. 10 Design DFA to check whether given decimal number is divisible by 3 Above DFA can be
Solution: represented as
Logic is Divisibility test of 3
M = ( Q , Σ , δ , q0 , F )
Here, q3 represents remainder 0 state
q1 represents remainder 1 state Where Q = { q0, q1, q2,
q2 represents remainder 2 state q3 }
Transition Diagram: Σ = { 0, 1, 2, 3,
…,9}
2, 5, 8
q2 q0make
Here, we will = q0group
q0
of inputs toFrepresent
= { q3 }
0, 3, 6, 9 transitions as they have
2, 5, 8
similar next state on
0, 3, 6, current Input.
9
2, 5, 8 1, 4, 1, 4,
1, 4, 7 7 7
1, 4,7 Group 1: 0, 3, 6, 9
q3 Group 2: 1, 4, 7
q1 Group 3: 2, 5, 8
2, 5,8 0, 3, 6,
0, 3, 6, Prepared By: Mr. Vaibhav
9
Examples on DFA
Ex. 10 Design DFA to check whether given decimal number is divisible by 3 Transition Function:
Solution:
Logic is Divisibility test of 3
δ ( q0 , ( 0, 3, 6, 9 ) ) = q3
Here, q3 represents remainder 0 state
q1 represents remainder 1 state
δ ( q1 , ( 0, 3, 6, 9 ) ) = q1
q2 represents remainder 2 state δ ( q2 , ( 0, 3, 6, 9 ) ) = q2
Transition Diagram: δ ( q3 , ( 0, 3, 6, 9 ) ) = q3
δ ( q0 , ( 1, 4, 7 ) ) = q1
2, 5, 8 δ ( q1 , ( 1, 4, 7 ) ) = q2
q0 q2
δ ( q2 , ( 1, 4, 7 ) ) = q3
0, 3, 6, 9
2, 5, 8 δ ( q3, ( 1, 4, 7 ) ) = q1
0, 3, 6, δ ( q0 , ( 2, 5, 8 ) ) = q2
9
2, 5, 8 1, 4, 1, 4,
1, 4, 7 7 7 δ ( q1 , ( 2, 5, 8 ) ) = q3
1, 4,7
q3 δ ( q2 , ( 2, 5, 8 ) ) = q1
q1
2, 5,8 0, 3, 6, δ ( q3 , ( 2, 5, 8 ) ) = q2
0, 3, 6, Prepared By: Mr. Vaibhav
9
Examples on DFA
Ex. 10 Design DFA to check whether given decimal number is divisible by 3 Transition Table:
Solution:
Logic is Divisibility test of 3
Inputs/
Here, q3 represents remainder 0 state 0, 3, 6, 9 1, 4, 7 2, 5, 8
States
q1 represents remainder 1 state
q0 q3 q1 q2
q2 represents remainder 2 state
q1 q1 q2 q3
Transition Diagram:
q2 q2 q3 q1
q3 q3 q1 q2
2, 5, 8
q0 q2
0, 3, 6, 9
2, 5, 8
0, 3, 6,
9
2, 5, 8 1, 4, 1, 4,
1, 4, 7 7 7
1, 4,7
q3 q1
2, 5,8 0, 3, 6,
0, 3, 6, Prepared By: Mr. Vaibhav
9
Examples on DFA
Ex. 10 Design DFA to check whether given decimal number
is divisible by 3
Solution:
Transition Table:
Simulation for the string 532
δ ( q0 , 5 3 2 ) |-- δ ( q2 , 3 2 ) Inputs/ 0, 3, 1, 4, 2, 5, 8
|-- δ ( q2 , 2 ) States 6, 9 7
q0 q3 q1 q2
|-- δ ( q1 , ε )
q1 q1 q2 q3
= q1
q2 q2 q3 q1
q3 is not a final state. q3 q3 q1 q2
Hence given string 532 is not accepted by given DFA

Prepared By: Mr. Vaibhav


Examples on DFA
Ex. 10 Design DFA to check whether given decimal number
is divisible by 3
Solution:
Transition Table:
Simulation for the string 324531
δ ( q0 , 3 2 4 5 3 1 ) |-- δ ( q3 , 2 4 5 3 1 ) Inputs/ 0, 3, 1, 4, 2, 5, 8
|-- δ ( q2 , 4 5 3 1 ) States 6, 9 7
q0 q3 q1 q2
|-- δ ( q3 , 5 3 1 )
q1 q1 q2 q3
|-- δ ( q2 , 3 1 )
q2 q2 q3 q1
|-- δ ( q2 , 1 ) q3 q3 q1 q2
|-- δ ( q3 , ε )
= q3
q3 is a final state.
Hence given string 324531 is accepted by given DFA
Prepared By: Mr. Vaibhav

You might also like