DESKTOP

Compiler Design: Transforming NFA To DFA

7/24/2010 7:59:46 PM
2.3 TRANSFORMING NFA TO DFA
For every non-deterministic finite automata, there exists an equivalent deterministic finite automata. The equivalence between the two is defined in terms of language acceptance. Since an NFA is a nothing more than a finite automata in which zero, one, or more transitions on an input symbol is permitted, we can always construct a finite automata that will simulate all the moves of the NFA on a particular input symbol in parallel. We then get a finite automata in which there will be exactly one transition on an input symbol; hence, it will be a DFA equivalent to the NFA.

Since the DFA equivalent of the NFA simulates (parallels) the moves of the NFA, every state of a DFA will be a combination of one or more states of the NFA. Hence, every state of a DFA will be represented by some subset of the set of states of the NFA; and therefore, the transformation from NFA to DFA is normally called the "construction" subset. Therefore, if a given NFA has n states, then the equivalent DFA will have 2n number of states, with the initial state corresponding to the subset {q0}. Therefore, the transformation from NFA to DFA involves finding all possible subsets of the set states of the NFA, considering each subset to be a state of a DFA, and then finding the transition from it on every input symbol. But all the states of a DFA obtained in this way might not be reachable from the initial state; and if a state is not reachable from the initial state on any possible input sequence, then such a state does not play role in deciding what language is accepted by the DFA. (Such states are those states of the DFA that have outgoing transitions on the input symbols—but either no incoming transitions, or they only have incoming transitions from other unreachable states.) Hence, the amount of work involved in transforming an NFA to a DFA can be reduced if we attempt to generate only reachable states of a DFA. This can be done by proceeding as follows:

Let M = (Q, Σ, δ, q0, F ) be an NFA to be transformed into a DFA.

Let Q1 be the set states of equivalent DFA.

begin:

    Q1old = Φ
    Q1new = {q0}

While (Q1old Q1new)
{
Temp = Q1new - Q1old Q1 = Q1new for every subset P in Temp do
for every a in Σdo
If transition from P on a goes to new subset S of Q then (transition from P on a is obtained by finding out
the transitions from every member of P on a in a given

NFA
and then taking the union of all such transitions)
Q1 new = Q1 new S
}
Q1 = Q1new end

A subset P in Ql will be a final state of the DFA if P contains at least one member of F of the NFA. For example, consider the following finite automata:

where:

The DFA equivalent of this NFA can be obtained as follows:

0

1

{q0)

{q1}

Φ

{q1}

{q1}

{q1, q2}

{q1, q2}

{q1}

{q1, q2, q3}

*{q1, q2, q3}

{q1, q3}

{q1, q2, q3}

*{q1, q3}

{q1, q3}

{q1, q2, q3}

Φ

Φ

Φ

The transition diagram associated with this DFA is shown in Figure 1.

Click To expand
Figure 1: Transition diagram for M = ({q0, q1, q2, q3}, {0, 1} δ, q0, {q3}).

Other  
  •  Algorithms for Compiler Design: THE NFA WITH ∈-MOVES
  •  Algorithms for Compiler Design: THE NFA WITH ∈-MOVES TO THE DFA
  •  Compiler Design: MINIMIZATION/OPTIMIZATION OF A DFA
  •  Algorithms for Compiler Design: EXAMPLES OF FINITE AUTOMATA CONSTRUCTION
  •  Algorithms for Compiler Design: REGULAR SETS AND REGULAR EXPRESSIONS
  •  Algorithms for Compiler Design: OBTAINING THE REGULAR EXPRESSION FROM THE FINITE AUTOMATA
  •  Algorithms for Compiler Design: LEXICAL ANALYZER DESIGN
  •  Algorithms for Compiler Design: PROPERTIES OF REGULAR SETS
  •   Algorithms for Compiler Design: EQUIVALENCE OF TWO AUTOMATAS
  •  Algorithms for Compiler Design: CONTEXT-FREE GRAMMAR
  •  Algorithms for Compiler Design: REGULAR GRAMMAR
  •  Algorithms for Compiler Design: RIGHT LINEAR AND LEFT LINEAR GRAMMAR
  •  Algorithms for Compiler Design: Top-down parsing
  •  Algorithms for Compiler Design: Implementation
  •  Algorithms for Compiler Design: THE PREDICTIVE TOP-DOWN PARSER
  •  Algorithms for Compiler Design: A HANDLE OF A RIGHT SENTENTIAL FORM
  •  Algorithms for Compiler Design: IMPLEMENTATION in Bottom-up Parsing
  •  Algorithms for Compiler Design: THE LR PARSER
  •  Algorithms for Compiler Design: DATA STRUCTURES FOR REPRESENTING PARSING TABLES
  •  Algorithms for Compiler Design: WHY LR PARSING IS ATTRACTIVE
  •  
    Most View
    Syncing And Streaming (Part 3) - Transferring media via third-party services
    Understanding Exchange Policy Enforcement Security : Creating Messaging Records Management Policies
    Western Digital Black 4TB - One Of The Quickest Physical Drives
    Ditch your printer today : Step-by-step print your files to PDF (part 1)
    Online Critiquing (Part 2)
    Windows Server 2003 : Using the Indexing Service - Creating and Configuring Catalogs
    Programming with DirectX : Game Math - Vectors
    Showdown: lOS vs Android vs WP7 (Part 1)
    Windows Server 2003 : Creating and Managing Digital Certificates - Introducing Certificates
    Amazon Kindle Paperwhite 3G
    Top 10
    ASP.NET 4 in VB 2010 : The Data Controls - Sorting and Paging the GridView
    Microsoft Content Management Server Development : A Date-Time Picker Placeholder Control (part 2)
    Microsoft Content Management Server Development : A Date-Time Picker Placeholder Control (part 1)
    Microsoft Content Management Server Development : Building SharePoint Web Parts - Configuring the Web Part, Debugging the Web Part
    Windows Server 2008 R2 networking : Planning and Deploying DNS (part 4) - Monitoring and troubleshooting DNS
    Windows Server 2008 R2 networking : Planning and Deploying DNS (part 3) - Setting up DNS zones
    Windows Server 2008 R2 networking : Planning and Deploying DNS (part 2) - Installing the DNS Server role, Configuring DNS Servers
    Windows Server 2008 R2 networking : Planning and Deploying DNS (part 1) - Designing a DNS infrastructure
    Windows Server 2008 R2 networking : Routing and Remote Access
    ADO.NET Programming : Microsoft SQL Server (part 4) - Working with Typed Data Sets