Module I
Module I
FINITE AUTOMATA
Ex: 1, a, b, #
Ex: ∑ = {a, b}
∑ = {0, 1, 2, +}
∑ = {#, β, Δ}
w4 = #β , w5 = #Δ , w6 = βΔ,
Ex: Let M be the finite automata with all strings over ∑ = {#, β, Δ}
Ex: Let M be the finite automata with all strings of length two over ∑ = {#, β, Δ}
Operations on Languages:
a) Union – Let L1 and L2 be two languages. Then their union is a language comprising
of all strings from both L1 and L2. It represented as L1 U L2.
L1 U L2 = { #β , #Δ , Δ , #βΔ }
c) Closure Operations
ii) Positive Closure (∑+) – Set of all possible combination of strings excluding ε
Ex: Let ∑ = {#, β, Δ}
. . . . . }
Problem 2: Determine the language over ∑ = {#, β, Δ} comprising of all strings in which
the 2nd symbol is Δ.
(i) Input – At each of the discrete instants of time t1, t2, . . . tm , the input values I1 , I2
. . . . Ip are applied as input to model. Each input symbol takes a value from the input
alphabet ∑.
iii) Output – O1 , O2 , . . . . Oq are the outputs of the model; each output symbol takes
a value from the output alphabet O.
(iii) States – At any instant of time the automaton can be in one of the states q1, q2 , . .
. , qn.
(iv) State relation – At any instant of time, the next state of the automaton is determined
by the present state and the present input.
(v) Output relation – The output is related to either state only or to both the input and
the state. It should be noted that at any instant of time the automaton is in some state.
On ‘reading’ an input symbol, the automaton moves to a next state which is given by the
state relation.
FA serve as fundamental models of computation with a finite set of states and transitions
between these states based on input symbols. These models help computer scientists and
researchers understand the nature of computation, formal languages, and the
fundamental limits of what can be efficiently computed within the realm of regular
languages.
FA finds applications in various domains of computer science, including:
a) Lexical analysis in compilers: They are used to recognize and tokenize strings
based on specific patterns or regular expressions.
c) Pattern matching:
d) Network protocols:
✓ for verifying systems of all types that have a finite number of distinct
states such as communication protocols
a) States: These are distinct configurations or conditions in which the automaton can
exist at any given point during its operation.
b) Transitions: These depict the movement between states based on input symbols.
Transitions are governed by a set of rules or a transition function.
Finite Automata can recognize and accept strings that belong to the languages they are
designed for (e.g., regular languages for DFAs and NFAs). The step-by-step explanation of
how a Finite Automaton operates:
a) States: The FA starts in a designated initial state from a set of finite states. Each
state represents a particular configuration or condition of the automaton at a given
moment.
b) Transition Function: The FA has a transition function that defines the rules for
transitioning between states based on the input symbols it receives. This function
specifies the next state the FA moves to when it reads a particular input symbol
while being in a certain state. The transition function can be represented in the
form of a transition table or a transition diagram or a transition relation.
e) Behavior (for NFAs): For a Nondeterministic Finite Automaton (NFA), the process
is similar, but with more flexibility. An NFA might have multiple possible transitions
for a given state and input symbol. It can be in multiple states simultaneously, and
it accepts an input string if there exists at least one path that leads to an accepting
state.
f) Completion of Input: Once the entire input string is processed, the FA halts, and
its final state or states determine whether the input string is accepted or rejected
based on the language it recognizes.
b) Nondeterministic Finite Automata (NFA): Unlike DFAs, NFAs can have multiple
possible transitions for a given state and input symbol. They are more flexible in
their behavior, allowing transitions to multiple states simultaneously or the option
to "guess" the correct path. NFAs recognize the same class of languages as DFAs,
but their design and operation are more versatile.
6. Mathematical Model of DFA
A DFA can be represented mathematically as a 5-tuple:
M = ( Q , ∑ , δ , q0 , F )
δ is defined as
δ ( q4 , + ) = q7 Next State
Present
State/∑ + X
δ ( q4 , X ) = q4
δ ( q7 , + ) = q4 ➔ q4 q7 q4
δ ( q7 , X ) = q7 q7 q4 q7
Transition Diagram
M = ( Q , ∑ , δ , q0 , F )
δ: Transition function Q X ∑ → 2Q
A transition in an NFA can have more than one possible next state.
Example NFA: Let the NFA be M = ( Q , ∑ , δ , q4 , F )
δ is defined as
δ ( q4 , + ) = q7 Next State
Present
State/∑ + X
δ ( q4 , X ) = q4
δ ( q7 , + ) = q4 ➔ q4 q7 q4
δ ( q7 , X ) = q4 , q7 q7 q4 q4 , q7
Transition Diagram
8. Acceptability of Strings
Let the DFA be M = ( Q , ∑ , δ , q0 , F ). A string X is said to be accepted by M if δ (q0, X)
= q where q ϵ F.
A string is said to be accepted by NFA if there exists at least one completed path that ends
with a final state. Let the MFA be M = ( Q , ∑ , δ , q0 , F). A string X is said to be accepted
by M if δ (q0, X) contains some final state.
Example Problem 1: For the following DFA, determine the acceptability of the string
XX+X.
∑ = { + , X } , q4 is initiate state , F = { q4 }
δ is defined as
δ ( q4 , + ) = q7 Next State
Present
State/∑ + X
δ ( q4 , X ) = q4
δ ( q7 , + ) = q4 ➔ q4 q7 q4
δ ( q7 , X ) = q7 q7 q4 q7
Transition Diagram
δ ( q4 , X X + X ) = δ ( q4 , X + X ) = δ ( q4 , + X ) = δ ( q7 , X ) = q7
As q7 is not a final state, string “XX+X” is not accepted by the given FA.
Example Problem 2: For the following NFA, determine the acceptability of the string
XX+X.
∑ = { + , X } , q4 is initiate state , F = { q4 }
δ is defined as
δ ( q4 , + ) = q7 Next State
Present
State/∑ + X
δ ( q4 , X ) = q4
δ ( q7 , + ) = q4 ➔ q4 q7 q4
δ ( q7 , X ) = q4 , q7 q7 q4 q4 , q7
Transition Diagram
9. Problems on Design of FA
Problem 1: Design a DFA that recognizes the language over { v , p } containing strings
that start with 'v' and have an odd length.
Answer: Let the FA that recognizes the language over { v , p } containing strings that start
with 'v' and have an odd length be
M = ( Q , ∑ , δ , q0 , F ) where Q = { q4 , q5 , q6 } ,
∑ = { v , p } , q4 is initiate state , F = { q5 }
δ is defined as
δ ( q4 , v ) = q5 Next State
Present
State/∑ v p
δ ( q5 , v ) = q6
δ ( q5 , p ) = q6 ➔ q4 q5
δ ( q6 , v ) = q5 q5 q6 q6
4
δ ( q6 , p ) = q5 q6 q5 q5
Transition Diagram
δ ( q4 , v p v p p ) = δ ( q5 , p v p p ) = δ ( q6 , v p p ) = δ ( q5 , p p ) = δ ( q6 , p ) = q5
Note: δ’ ( [q0 , q1 , . . . . , qn ] , a ) = δ ( q0 , a ) U δ ( q1 , a ) U . . . . U δ ( qn , a )
∑ = { + , X } , q3 is initiate state , F = { q3 }
δ is defined as
δ ( q3 , + ) = q5 Next State
Present
State/∑ + X
δ ( q3 , X ) = q3
δ ( q5 , + ) = q3 ➔ q3 q5 q3
δ ( q5 , X ) = q3 , q5 q5 q3 q3 , q5
Transition Diagram
δ’ is defined as
M = ( Q , ∑ , δ , q0 , F )
δ is defined as
Transition Diagram
12. Conversion of NFA-ε to NFA
Note: ε-closure(q) = set of all states p such that there is a path from q to p with label ε.
𝛿̂ (𝑞 , a) = ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒(𝛿(𝛿̂ (𝑞 , ε ), 𝑎))
Example Problem: Convert the following NFA-ε to equivalent NFA without ε-transitions.
δ is defined as
Transition Diagram
ε-closure(q4) = 𝛿̂ (𝑞4 , ε) = { q4 , q7 }
ε-closure(q7) = 𝛿̂ (𝑞7 , ε) = { q7 }
= ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒( { ∅ } ∪ { 𝑞4 })
= ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒( { 𝑞4 })
= { 𝑞4 , 𝑞7 }
= ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒( { 𝑞4 } ∪ { 𝑞7 })
= ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒( { 𝑞4 , 𝑞7 })
= { 𝑞4 , 𝑞7 } ∪ { 𝑞7 }
= { 𝑞4 , 𝑞7 }
= ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒(𝛿({𝑞7} , +))
= ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒( { 𝑞4 })
= { 𝑞4 , 𝑞7 }
= ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒(𝛿({𝑞7} , 𝑋))
= ε − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒( { 𝑞7 })
= { 𝑞7 }
δ’ is defined as
Transition Diagram
a) Moore Machine: The output is associated with each state rather than with
transitions. Upon entering a state, the machine produces an output determined by
that state.
b) Mealy Machine: Outputs are associated with transitions, meaning the output
depends on both the current state and the input symbol. Outputs are produced
when a transition occurs from one state to another due to an input symbol.
Moore Machine:
In Moore machine, output function Z(t) depends only on the present state q(t) and is
independent of the current input. "t” is a discrete instant of time.
Z(t) = λ (q(t) )
M = ( Q , ∑ , Δ , δ , λ , q0 )
δ: Transition function QX ∑ →Q
λ: output function Q → Δ
For a Moore machine if the input string is of length “n”, the output string is of length “n+1”.
δ is defined as
δ ( q4 , + ) = q7 Next State δ
Present Output
State/∑ + X λ
δ ( q4 , X ) = q4
δ ( q7 , + ) = q4 ➔ q4 q7 q4 P
δ ( q7 , X ) = q7 q7 q4 q7 M
Transition Diagram
Output Function λ
λ ( q4 ) = P
λ ( q7 ) = M
Problem: For the above Moore Machine, determine the output for the input string “XX+X”.
δ ( q4 , X X + X ) = δ ( q4 , X + X ) = δ ( q4 , + X ) = δ ( q7 , X ) = q7
Output P P P M M
Mealy Machine:
In Mealy machine, output function Z(t) depends on the present state q(t) and the current
input x(t).
M = ( Q , ∑ , Δ , δ , λ , q0 )
δ: Transition function QX ∑ →Q
λ: output function Q X ∑ → Δ
For a Mealy machine if the input string is of length “n”, the output string is of length “n”.
δ is defined as
δ ( q4 , + ) = q7 + X
Present
State/∑ Next Output Next Output
δ ( q4 , X ) = q4
State δ λ State δ λ
δ ( q7 , + ) = q4 ➔ q4 q7 M q4 P
δ ( q7 , X ) = q7 q7 q4 P q7 M
Transition Diagram
Output Function λ
λ ( q4 , + ) = M
λ ( q4 , X ) = P
λ ( q7 , + ) = P
λ ( q7 , X ) = M
Problem: For the above Mealy Machine, determine the output for the input string “XX+X”.
δ ( q4 , X X + X ) = δ ( q4 , X + X ) = δ ( q4 , + X ) = δ ( q7 , X ) = q7
Output P P M M
Answer:
δ is defined as
δ ( q4 , + ) = q7 Next State δ
Present Output
State/∑ + X λ
δ ( q4 , X ) = q4
δ ( q7 , + ) = q4 ➔ q4 q7 q4 P
δ ( q7 , X ) = q7 q7 q4 q7 M
Transition Diagram
Output Function λ
λ ( q4 ) = P
λ ( q7 ) = M
δ ( q4 , + ) = q7
+ X
Present
δ ( q4 , X ) = q4 State/∑ Next Output Next Output
State δ λ State δ λ
δ ( q7 , + ) = q4
➔ q4 q7 M q4 P
δ ( q7 , X ) = q7
q7 q4 P q7 M
Transition Diagram
= λ ( q4 ) = λ ( q7 )
Output Function λ’
λ ( q4 , + ) = M
λ ( q4 , X ) = P
λ ( q7 , + ) = P
λ ( q7 , X ) = M
Answer:
δ ( q4 , + ) = q7
+ X
Present
δ ( q4 , X ) = q4 State/∑ Next Output Next Output
State δ λ State δ λ
δ ( q7 , + ) = q4
➔ q4 q7 M q4 M
δ ( q7 , X ) = q7
q7 q4 P q7 M
Transition Diagram
Output Function λ
λ ( q4 , + ) = M
λ ( q4 , X ) = M
λ ( q7 , + ) = P
λ ( q7 , X ) = M
δ’ is defined as
Transition Table
+ X
Present
State/∑ Next Output Next Output
State δ λ State δ λ
➔ q4M q7 M q4M M
q4P q7 M q4M M
q7 q4P P q7 M
+ X
Present
State/∑ Next Output Next Output
State δ λ State δ λ
➔ q4’ q7 M q4M M
q4M q7 M q4M M
q4P q7 M q4M M
q7 q4P P q7 M
Present Next State δ Output
State/∑ + X λ
➔ q4’ q7 q4M ε
q4M q7 q4M M
q4P q7 q4M P
q7 q4P q7 M
δ ( q4’ , + ) = q7
δ ( q4’ , X ) = q4M
δ ( q4M , + ) = q7
δ ( q4M , X ) = q4M
δ ( q4P , + ) = q7
δ ( q4P , X ) = q4M
δ ( q7 , + ) = q4P
δ ( q7 , X ) = q7
Output Function λ’
λ ( q4’ ) = ε
λ ( q4M ) = M
λ ( q4P ) = P
λ ( q7 ) = M