Week 4 Notes
Week 4 Notes
Week 4 Notes
1
DFA and NFA 2
■ DFA – Deterministic Finite Automata
■ Automata – What is it?
■ An automaton is an abstract model of a digital computer
■ It has a mechanism to read input – a string over a given alphabet
■ This input is written on an input file which can be read by the automaton but cannot change it
Input File
Automaton
Control Unit Storage
Output
>>> 3
■ Input file is divided into cells, each can hold one symbol
■ The automaton has a temporary “storage” device, which has unlimited number of cells, the contents
can be altered by the automaton
■ Automaton has a control unit, said to be in one of a finite number of “internal states”
■ Automaton types:
– Deterministic Automata
– Non-deterministic Automata
■ A deterministic automata is one in which each move (transition from one state to another) is unequally
determined by the current configuration
■ If the internal state, input and contents of the storage are known, it is possible to predict the future
behavior of the automaton
■ This is said to be deterministic otherwise it is non-deterministic
■ An automaton whose output response is yes or no is called an acceptor
Definition of DFA 4
■ 5-tuple
a
a b
a
q0 q1 q2 q3
b b b
a
Finite Automaton with four states
Example #2 9
■ Determine the DFA schematic for , where Q={q1,q2,q3}, , q1 is the start state, F={q2} and is given by
the table below
Initial State (q) Symbol Final state
q1 0 q1
q1 1 q2
q2 0 q3
q2 1 q2
q3 0 q2
q3 1 q2
0 1
0
q1 1 q3
q2
Finite automaton having three states
0,1
>>> 10
■ From the given table for , the DFA is drawn, where q2 is the only final state
■ It is to be noted that a DFA can “accept” a string and it can “recognize” a language.
■ The DFA accepts strings that has at least one 1 and an even number of 0s following the last 1
■ Hence the language L is given by
– L={w|w contains at least one 1 and an even number of 0s follow the last 1} where L(M) and M
recognized the RHS of the equation above
Example #3 11
■ Sketch the DFA given M=({q1,q2},{0,1}, ,q1,{q2}) and is given by
(q1,0) = q1 and (q2,0) = q1
(q1,1) = q2 and (q2,1) = q2 , determine a Language L(M), that the DFA recognizes.
■ From the given data, it is easy to predict the schematic of DFA as follows
internal states = q1, q2
symbols = 0, 1
transition function = (as defined above in the given problem)
q1 = initial state 0
q2 = final state 1
q2 q2
0
>>> 12
■ If a string ends in a 0, it is “rejected” and “accepted” only if the string ends in a 1
■ Therefore the language
– L(M) = {w | w ends in a 1}
■ Example #4
■ Design a DFA, the language recognized by the Automaton being
– L={anb: n0}
■ For the given language L={anb: n0}, the strings could be b, ab, b2b, a3b, …
■ The DFA accepts all strings consisting of an arbitrary number of a’s, followed by a single b. All other
input strings are rejected
a
a, b
b a, b
q0 q1 q2
Example #5 13
■ Obtain the state table diagram and state transition diagram (DFA Schematic) of the finite state
Automaton , where Q={q0,q1,q2,q3}, ={a,b}, q0 is the initial state, F is the final state with the transition
defined by
q0 q1
q2 q3
1
Example #6 15
■ Obtain the DFA that accepts/recognizes the language L(M)={w | w {a,b,c}* and w contains the pattern
abac}
■ Note: This is an application of DFA’s involving searching a text for a specific pattern
■ Solution:
■ Begin by “hard coding” the pattern into the machines state as shown:
q0 q1 q2 q3 q4
■ As the pattern “abac” has length 4, there are four states required in addition to one initial state q 0 to
remember the pattern. q4 is the only accepting state required and this state q4 can be reached only
after reading “abac”
■ The complete DFA is in the next slide
>>> 16
q0 q1 q2 q3 q4
Non-Deterministic Finite Automata (NFA) 17
■ 5-tuple
■ M=(Q, , , q0, F) where
Q = Finite set of internal states
= Finite set of symbols called “Input alphabet”
=Qx(
q0 Q is the initial states
F Q is a set of Final states
■ NFA differs from DFA in that, the range of in NFA is the powerset 2Q
■ A string is accepted by an NFA if there is some sequence of possible moves that will put the machine
in the final state at the end of the string
Example #1 18
■ Obtain an NFA for a language consisting of all strings over {0,1} containing a 1 in the third position
from the end
■ Solution:
q1, q2 and q3 are initial states
q4 is the final state
q1 q2 q3 q4