For each state i of the NFA create a new one containing each of the
possible states sets from the nfa.
(ie, on a two state NFA with states 1,2 you get (1), (2) and (1,2)).
Now for each connection from states i to j you have to create a new
one from every state containing i to each state containing j.
Finally mark any state containing a final state in the original
automaton as final and mark the state conatining only the initial
state as initial.
The funny thing is that this causes a state explosion showing that
although not more descriptive NFA create more eficient automatons :D
Yes, this is (for me) the easiest way of constructing a DFA, by doing
it from the NFA. However, as you point out you'll have to write many
many states if you start that way.
I start with the NFA start state, and then follow the edges to the
next possible states, and create the states in the DFA on demand.
E.g. if you have the following NFA with states 1,2, 3 and 4, with 1 as
the start state:
1 -- a --> 2
1 -- a --> 3
1 -- b --> 3
2 -- c --> 3
3 -- c --> 4
Then we start by making a state {1} in the DFA. From it we can follow
the a edge to both 2 and 3, so we create the state {2,3} and make an
"a" arrow from state {1} to it. Then we follow the b edge from 1 and
find that we can only land in 3, so we create a state {3} in the DFA
(and draw the edge). Now we have:
{1} -- a --> {2,3}
{1} -- b --> {3}
Looking at the NFA, I can see that if I'm in either state 2 or 3, the
only edges are c edges, and following (all of) the will put me in
state 3 or 4. So, I create state "3,4" and add the edge
{2,3} -- c --> {3,4}
From state 3 we can get only get to 4 via a c edge, so we add the
state {4} and edge
{3} -- c --> {4}
Finally we see if that we are in either state 3 or 4 (need to consider
this since there is a node {3,4} in our DFA), then the only arrow we
can follow is a c arrow to state 4. So we add also
{3,4} -- c --> {4}
Finally, to make sure, check every state in your DFA, and look at the
corresponding sets of states in the NFA to see if there are any
outgoing edges (from the _set_) that are not represented in the DFA.
If so, you must add them.
(Note that the above state machines don't correspond to any regular
expression, it's just a made up example)
You have to be careful also with epsilon edges. Whenever we can enter
a state in the NFA which has an outgoing epsilon edge, we must include
the possiblity of following that edge also. E.g. for the NFA:
1 -- a --> 2 -- eps --> 3
The corresponding DFA is
{1} -- a --> {2,3}
A state in the DFA is an accept state if any of the states it
represents in the NFA is an accept state.
hope this helps,
Arnar
I'd suggest you mark the accepting states in the table e.g. with an
asterisk or something, as long as you explain your notation. If you
draw the state machine on the exam, it is conventional to mark the
start state with an incoming arrow (not from any state) and an
accepting state with a double stroke circle.
cheers,
Arnar
space = (' ' | '\t' | '\n')
code = (token space*) *
token = string | comment
string = '"' ((char - '"'-'*')| '*' (char - '"'-'/')))* '"'
comment = '/' '*' ((char - '*') | '*' (char - '/'))* ('*')+ '/'
Hope that helps although the notation may not be correct.