0% found this document useful (0 votes)
25 views

Week 4 Notes

The document discusses deterministic finite automata (DFA) and non-deterministic finite automata (NFA). It provides examples of how to define the 5-tuple that describes a DFA or NFA, including the set of states, input alphabet, transition function, initial state, and final/accepting states. It also gives examples of how to draw the state transition diagram of a DFA and describes how a DFA or NFA accepts a string by reaching an accepting state. Examples are provided of DFAs that recognize specific languages containing certain patterns of symbols. The key difference between a DFA and NFA is that a DFA has a deterministic transition function, while an NFA transition function can map a state-symbol pair to multiple possible

Uploaded by

Anis Safwan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Week 4 Notes

The document discusses deterministic finite automata (DFA) and non-deterministic finite automata (NFA). It provides examples of how to define the 5-tuple that describes a DFA or NFA, including the set of states, input alphabet, transition function, initial state, and final/accepting states. It also gives examples of how to draw the state transition diagram of a DFA and describes how a DFA or NFA accepts a string by reaching an accepting state. Examples are provided of DFAs that recognize specific languages containing certain patterns of symbols. The key difference between a DFA and NFA is that a DFA has a deterministic transition function, while an NFA transition function can map a state-symbol pair to multiple possible

Uploaded by

Anis Safwan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

ICS3253

Automata Theory & Computation (Week 4)

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

■ Q  Finite state of “internal states”


■  Finite set of symbols called “input alphabets”
■  Transition Function
■  Initial State
■  Set of Final States
■ The input mechanism can move only from left to right and reads exactly one symbol on each step
■ The transition from one internal state to another are governed by the transition function .
■ If then if the DFA is in state and the current input symbol is a, the DFA will go into state
Example 5
■ Design a DFA, M which accepts the language L(M)={*: w does not contain three consecutive b’s
Let
Q = {q0,q1,q2,q3}
= {a,b}
q0 is the initial state
F = {q0,q1,q2} are initial states and is defined as follows:
Example #1 6
Initial State (q) Symbol ( ) Final State (q, )
q0 a q0
q0 b q1
q1 a q0
q1 b q2
q2 a q0
q2 b q3
q3 a q3
q3 b q3
Solution 7
■ M does not accept specified language, as long as three consecutive b’s have not been read
■ It should be noted that
– M is in state qi (where i=0,1,2) immediately after reading a run of i consecutive b’s that either
began the input string or was preceded by an ‘a’
– If an ‘a’ is read and M is in state, q0, q1, or M returns to its initial state q0
■ q0, q1 and q2 are “Final States”. Therefore any input string not containing three consecutive b’s will be
accepted
■ In case you get three consecutive b’s then the q3 state is reached (which is not final state), hence M
will remain in this state, irrespective of any other symbol in the rest of the string. This string q3 is said
to be “dead state” or M is said to be “trapped” at q3
>>> 8
■ The DFA schematic is shown below based on the previous discussion

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

■ The State Table diagram:


a b
q0 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2
>>> 14
■ State Transition Diagram / DFA Schematic (Can someone draw it in front?)

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

■ This is an NFA because and

You might also like