Conversion of the finite automaton nfa-ε to the NFA and to the DFA

Source: Internet
Author: User

The DFA (deterministic finite automata), a deterministic finite automaton, refers to a unique next state for each state that is determined by the input alphabet, and the NFA (Nondeterminisic finite Automata) is an indeterminate finite automaton, which means that for any state, when the state obtains the input alphabet, it is possible that the resulting state is not one, but multiple, that is, a set of states. In a sense, DFA is a special form of NFA. The nfa-ε is a more empty jump operation, that is, a state can automatically jump to another state without having to enter the alphabet.

Just look at the text some jerky, or to see the figure.





As can be seen, in the NFA, for the S state, when the input alphabet is a, there are two possible subsequent states q0 and Q2. In nfa-ε, for q0 states, because of the presence of the empty jump character ε, it is possible to skip to state Q1 and F when there are no other alphabet inputs.

After a brief introduction of these three types of automata, let's now look at some of the characters ' meanings.

Q: Set of finite number of states

∑: Enter the alphabet

T: Migration function

S: Initial state

F: End state

Now let's introduce the conversion from nfa-ε to NFA

Q ', ∑ ', t ', S ', f represent the finite number of states in the NFA, enter the alphabet, the migration function, the initial state, and the end state, while Q, ∑, T, S, f represent the finite number of states in the nfa-ε, enter the alphabet, the migration function, the initial state, the end state; ∑ ' =∑ , q ' = Q,s ' = S, F ' = {Q | E (q) ∩f≠ф} (where E (q) denotes the ε closure of Q)

To put it simply, it is to see what State B is in this state a continuous empty hop arrives, and if B is reached by entering the letter table x to the status C, then directly simplifies to the state a accepts the input Alphabet B arrives at c if B does not get

Any input to the alphabet, a does not take any action. The simple diagram is as follows:

The sequence of processes below the graph can be equivalent to state q0 absorbing X and becoming State Q2

Now take a look at an example of nfa-ε to NFA and turn the following image into an NFA


First from the state X, it can be empty jump to state I, because the state I absorbed 1 after the state J, so the state X can accept 1 directly into the state J, and the state G, H, I can be omitted. In addition, the State x can also always empty jump to the state A and status C, for the status A, its receive 1 after the status B, so x can be directly received 1 into State B, the same as the state C after accepting 0 to become the state D, so X can also be directly received after 0 to become the State D. Here the status X is all discussed.
The status G is discussed next, because the status G can be obtained by the state x jump, and X has been discussed, so the status G can be ignored. Similarly, status H, I, A, C can also be ignored.
Next discuss State B, State B can jump to the status A and status C, because A can accept 1 to become State B, so B can be directly received 1 to maintain its own state, and because C can receive 0 into the state D, so B can also receive 0 into the state d. In addition, the State B can also jump to the state F, because F receive 1 into a state J, so the State B can also receive 1 directly into the state J. This concludes the status B discussion.
Next discuss the status C, because the status C can jump to the state A and status C, because A can receive 1 to become State B, so C can receive 1 directly into the State B; Because C can receive 0 becomes the state D, so D can be directly received 0 to maintain their own state unchanged. In addition, the status C can also jump to the state F, because the status F receive 1 into a state J, so the status D can also be directly received 1 into the State J. At this point, the status C discussion ends.
The next discussion of the state f,f can be obtained by the B, d through the empty jump, because B, D has been discussed, so F can be ignored.
In the next discussion of State J, J is an end state because State J can get status y through an empty jump and Y is the end state.
The status y is then discussed, and y can be ignored because the state J gets the status y through an empty jump.

At this point, the full state analysis is complete, and the following diagram of the changes


Next we discuss how to turn the NFA into a DFA with the following algorithm


Where the symbol on the left represents the symbol in the DFA, and the symbol on the right represents the symbol in the NFA. The main idea is that each state in this state set receives the alphabet in turn to get another state, the newly obtained

The set of these states is the next State collection.

This algorithm can also be improved, the improved algorithm does not have to traverse the 2 Q-node nodes, but simply traverse the start node and each subsequent traversal of a state set resulting from another set of states. Its pseudo-code

As follows
For example, in the image below, the NFA is on the left and the converted DFA on the right. The process is as follows

First, the state set of the initial state x has only one element, {x}, when X receives 1 to get the state set {b,j}, this state is the state Q1, and when the state x receives 0, the state set {D} is obtained, this

Status is recorded as state Q2, at this point, the status {X} has been discussed.

Next, State Q1, state set {b,j}, for State B in Q1, when B receives 1, gets the state set {B,J}, which is state Q1; when B receives 0, it gets state D, which is state Q2.

For the state J in Q1, because J is the end state, so the set state of J is empty, and {b,j} is still {b,j},{d} and empty after the empty null phase and remains {D}, so the state Q1

State set {B, J}) receive 1 hold state Q1 unchanged, receive 0 becomes state Q2 (i.e. state set {D}), at this point, the status Q1 discussion ends. Next, State Q2, state set {D},d receive 0 get state set {d}, state q2,d receive 1 get state set {b,j}, i.e. State Q1. At this point, the status Q2 discussion is complete.

Since the start state {X} and the next state he produced Q1, Q2 have been discussed, and Q1, Q2 in the discussion process has not produced a new state, so all the state transition process discussed

Complete. But which state is the end state? According to the conversion rules, the newly obtained state set has a common subset with the previous ending state, indicating that the state is an end state. Accordingly, the state

The set {B,j} (that is, state Q1) contains the previous end state J, so the state set {B,J} (that is, state Q1) is the end state. At this point the entire conversion process ends with the following results


This article references: http://web.stanford.edu/class/cs143/materials/lecture03.pdf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.