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

Lecture 3

The document outlines the processes for converting between Non-deterministic Finite Automata (NFA) and Deterministic Finite Automata (DFA), as well as converting regular expressions to NFA and vice versa. It includes step-by-step examples demonstrating these conversions, particularly focusing on transition tables and state elimination methods. Additionally, it discusses the state elimination method for converting automata to regular expressions, detailing how to handle incoming and outgoing edges for states.

Uploaded by

Bebo BX
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lecture 3

The document outlines the processes for converting between Non-deterministic Finite Automata (NFA) and Deterministic Finite Automata (DFA), as well as converting regular expressions to NFA and vice versa. It includes step-by-step examples demonstrating these conversions, particularly focusing on transition tables and state elimination methods. Additionally, it discusses the state elimination method for converting automata to regular expressions, detailing how to handle incoming and outgoing edges for states.

Uploaded by

Bebo BX
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

CSE432: Automata and Computability

Conversion Between Automata and


Regular Expressions
Outlines

• Converting NFA into DFA


• Converting Regular Expression to NFA
• Converting Automaton to Regular Expression
Converting NFA to DFA
NFA to DFA
Let M = (Q, ∑, q0, δ, F) is an NFA which accepts the language L(M). There
should be equivalent DFA denoted by M' = (Q', ∑, q0, δ', F') such that L(M) =
L(M').
Steps for converting NFA to DFA
1. Initially set Q' = ϕ
2. Add q0 of NFA to Q'. Then find the transitions from this start state.
3. In Q', find the possible set of states for each input symbol. If this set of states
is not in Q', then add it to Q'.
4. In DFA, the final state will be all the states which contain F (final states of
NFA)
Example 1
Convert the following NFA to DFA.

Let’s write the transition table for the given NFA


State 0 1
→q0 q0 q1
q1 {q1, q2} q1
*q2 q2 {q1, q2}
Example 1
We obtain δ' transition for state q0.
δ'([q0], 0) = [q0]
δ'([q0], 1) = [q1]
The δ' transition for state q1 is obtained as:
δ'([q1], 0) = [q1, q2] (new state generated)
δ'([q1], 1) = [q1]
The δ' transition for state q2 is obtained as:
δ'([q2], 0) = [q2]
δ'([q2], 1) = [q1, q2]
Now we will obtain δ' transition on [q1, q2]. (The state [q1, q2] is the final state as well because it
contains a final state q2)
δ'([q1, q2], 0) = δ(q1, 0) ∪ δ(q2, 0)
= {q1, q2} ∪ {q2}
= [q1, q2]
δ'([q1, q2], 1) = δ(q1, 1) ∪ δ(q2, 1)
= {q1} ∪ {q1, q2}
= {q1, q2}
= [q1, q2]
Example 1
The transition table for the constructed DFA will be:

State 0 1

→[q0] [q0] [q1]

[q1] [q1, q2] [q1]

*[q2] [q2] [q1, q2]

*[q1, q2] [q1, q2] [q1, q2]


Example 1 We can eliminate state q2,
since it is an unreachable state
Example 2
Convert the following NFA to DFA.

Let’s write the transition table for the given NFA

State 0 1
→q0 {q0, q1} {q1}
*q1 ϕ {q0, q1}
Example 2
We obtain δ' transition for state q0.
δ'([q0], 0) = {q0, q1}
= [q0, q1] (new state generated)
δ'([q0], 1) = {q1} = [q1]
The δ' transition for state q1 is obtained as:
δ'([q1], 0) = ϕ
δ'([q1], 1) = [q0, q1]
As in the given NFA, q1 is a final state,
The δ' transition on [q0, q1].
then in DFA wherever, q1 exists that state
δ'([q0, q1], 0) = δ(q0, 0) ∪ δ(q1, 0) becomes a final state. Hence in the DFA,
= {q0, q1} ∪ ϕ
= {q0, q1} final states are [q1] and [q0, q1]. Hence,
= [q0, q1] set of final states F = {[q1], [q0, q1]}.
Similarly,
δ'([q0, q1], 1) = δ(q0, 1) ∪ δ(q1, 1)
= {q1} ∪ {q0, q1}
= {q0, q1}
= [q0, q1]
Example 2
The transition table for the constructed DFA will be:

State 0 1
→[q0] [q0, q1] [q1]
*[q1] ϕ [q0, q1]
*[q0, q1] [q0, q1] [q0, q1]

Even we can change the name of the


states of DFA, for example.
A = [q0]
B = [q1]
C = [q0, q1]
Converting Regular Expressions into NFA
From a Regular Expression to an NFA
• For construct the NFA

• For a in ∑, construct the NFA

• For the regular expression a | b construct the following NFA.


From a Regular Expression to an NFA
• For the regular expression a* construct the following composite NFA.

• RE = ab
From a Regular Expression to an NFA
RE = (ab)*
From a Regular Expression to an NFA
RE = (a | b)*a
Example 1
RE = a* (a | b)
Example 2
RE = a(a+b)*ab
Example 3
RE = a + b + ab
Converting Automaton to Regular Expression
State Elimination Method
1. If there are no incoming edges to the start state proceed further to check the
rest of the rules. If there are incoming transitions to the initial state, get rid of
incoming edges by making a new start state with no incoming edges and an
outgoing edge to the old start state with Ɛ-transition. the initial start state before
is now a normal state with added incoming Ɛ-transition.

Into
State Elimination Method
2. If there are no outgoing edges from final state proceed further to check
the last rule. If there are outgoing transitions from final state, to get rid of
outgoing edges make new final state with no outgoing edges and an
incoming edge from old final state of Ɛ-transition. Old final state is
transformed into a normal state with the added transition of Ɛ.

Into
State Elimination Method
3. If there are no multiple final states proceed to elimination (except final
and initial) of normal states. If the Automaton has multiple final states,
then strip their status of being final states and add outgoing Ɛ-transitions
to new and only final state with no outgoing transitions.

Into
Elimination of Normal States
• Assume we have the following DFA
Elimination of Normal States
• Applying rules 1 and 2 will lead to:
Elimination of Normal States
• Eliminating State B and C in any order, the answer will be the same in both
cases, now let’s eliminate B first.
• Eliminate B and imagine if there wouldn’t have been any State B then we reach
State C directly from Start state A with the input symbol of Ɛb*a we can neglect
Ɛ then input symbol will be b*a from A to C.
Elimination of Normal States
• Outgoing edge from State C to B is now become self Loop since State B is not
there. Edge from C is going to B, taking b* and returning to C with ‘a’ this can
happen infinite time hence self-loop of b(b)*a. We can write the two self-loops
‘a’ and ‘bb*a’ as (bb*a +a) meaning we can traverse one loop at a time.
Elimination of Normal States
• Now after eliminating C state, We would reach final State D directly from initial
state A, now we were reaching State C by input of ‘b*a’ on C state we are taking
infinite loops on (bb*a + a) and with Ɛ reaching final state D. hence Finally no
normal states remaining we got a stream of input symbols directly from initial to
final which is b*a(bb*a + a)*.
Questions and Discussions

You might also like