Class of machines called Nondeterministic Finite Automata:

Class of machines called Nondeterministic Finite Automata: Last time we knew machines called Deterministic Finite Automata (DFA or FA) that accepts so...
0 downloads 1 Views 128KB Size
Class of machines called Nondeterministic Finite Automata: Last time we knew machines called Deterministic Finite Automata (DFA or FA) that accepts some simple languages as for example {a}. As you might have noticed, those DFAs have states and transitions which do not contribute to accepting strings and languages. For example all we need about an FA that accepts { a } is the following regardless of the alphabet (whether be it { a } , { a , b } or any other) .

This is an essence of FA. But it is not DFA. A DFA that accepts { a } need more states and transitions as the example below:

Without extra states and transitions it is not a DFA if the alphabet is { a , b } . To avoid those redundant states and transitions and to make model easier we can use finite automata called Nondeterministic Finite Automata (short: NFA). There is presented a formal definition of NFA below and and some examples. For any NFA there is a DFA which accepts the same language and vice versa. NFAs are quite similar to DFAs. The only difference is in the transition function. NFAs do not necessarily go to a unique next state. The NFA may not go to any state from the current state on reading an input symbol or it may select one of several states nondeterministically as its next state.

1

Definition of nondeterministic finite automaton Let Q be a finite set and let be a finite set of symbols. Let be a function from Q  to 2Q , Let q0 be a state in Q and let A be a subset of Q. If we call the elements of Q a state, the transition function, q0 the initial state, A the set of accepting states.

Then a nondeterministic finite automaton is a 5-tuple < Q ,

, q0 ,

,A>

Notes on the definition 1. The set Q in the above definition is simply a set with a finite number of elements, as in the case of DFA its elements can be interpreted as a state that the system (automaton) is in. 2. The transition function is also called a next state function. Unlike as DFs a NFA moves into one of the states given by (q, a) if it receives the input symbol a while in state q. There is determined nondeterministically, which one of the states in (q, a) to select. 3. Note that is a function. Thus for each state q of Q and for each symbol a of (q, a) must be specified. The NFA aborts its operation if there is an empty set, 4. As in the case of DFA the accepting states are used to distinguish sequences of inputs given to the finite automaton. If the finite automaton is in an accepting state when the input ends i.e. ceases to come, the sequence of input symbols given to the finite automaton is "accepted". Otherwise it is not accepted. 5. Note that any DFA is also a NFA.

Example 1: Q = { 0, 1 }, following table.

= { a }, A = { 1 }, the initial state is 0 and

is as shown in the

State (q) Input (a) Next State ( (q, a) ) 0 a {1} 1 a

2

A state transition diagram for this finite automaton is given below.

If the alphabet

is changed to { a, b } instead of { a } it still remains an NFA that accepts {a}.

Example 2: Q = { 0, 1, 2 }, the following table.

= { a, b }, A = { 2 }, the initial state is 0 and

State (q) Input (a) Next State ( 0

a

0

b

1

a

1

b

2

a

2

b

is as shown in

(q, a) )

{1,2}

{2}

Note that for each state there are two rows in the table for corresponding to the symbols a and b, while in the Example 1 there is only one row for each state. A state transition diagram for this finite automaton is given below.

3

Example 3 For example consider the NFA with the following transition table: State (q) Input (a) Next State ( (q, a) ) 0 a {0,1,3} 0 b {2} 1 a 1 2 2

b a b

3

a

3

b

{3} {3}

{1}

The transition diagram for this NFA is as given below.

4

Task 2: Automaton accepting all the sets from the file in which there are elements which repeated themselves once. Using Nondeterministic Finite Automaton (NFA) propose a computer program which will accept all the sets contained elements which repeat themselves once. NFA is using following alphabet: ∑ = {0,1,2,3,4,5,6,7,8,9}. Program should read data from a whole file at once and points explicitly all cases (for example a position of the first element of the set) where the accepted sets are. It is possible to separate the sets from themselves with the symbol “#”. The Rules:  Your program must use transition table to determine its next state,  Finishing the program during the lab and sending it to the leading person – a “+”,  The console version of the program – mark 4,  The program with GUI – mark 5,  You can choose any language from C/C++, Java, C#, etc.,  Additional advantage – if the program will be able to check the file’s data correctness (if all enclosed sets were constructed correctly, please input the faulty set as the example). You can use NFA or FA to fulfill this additional task. If you will do that, the console version is enough to obtain mark 5.  additional tip: you should enclose “wider range alphabet” than defined – digits and letters for example as well as use the sign which terminates the whole file. EOF – for example.  The zip or rar packed archive should be named after following schema: LM_lab_2_Surname_indexnumber

Copyright © Dariusz Brzeziński & Łukasz Jopek 2011 5