Вы находитесь на странице: 1из 7

Tahir Naseem/Handout 1

-1-

Theory of Automata and Formal Languages

Lecture 11
Objectives
Language of FSA
Non-determinism
o Nondeterministic Automaton

Formal definition

Meaning of NFA

Choosing where to go

The ability to make choices

How to run an NFA

Examples

Language of NFA

- transitions

DFA to NFA
The transition function of a DFA takes a state and an element of the
alphabet and returns a state, but the transition function of an NFA takes
a state and either an element of the alphabet or nothing, and returns an
element of the power set of the states of the NFA. As a on sequence of
the above, there is usually more than one way to read in a string with an
NFA. The rules for acceptance and rejection of strings are the same for
an NFA as they are for a DFA: if the final state is an accept state, the
string is accepted; otherwise, it is rejected. If the NFA is in a state that
does not define a transition for the next element of the string (and
defines no empty transition), the string is rejected.
While it would initially seem that an NFA is more capable than a
DFA, due to its extra 'features,' that turns out to not be the case. A DFA
can be constructed that is equivalent to any NFA. The procedure is as
follows:
1. The list of states in the DFA will consist of one state for every element
of the powerset of the NFA's states. For example, if an NFA has states
A, B, and C, the DFA will have states A, B, C, AB, AC, BC, ABC, and an
empty state.

Tahir Naseem/Handout 1

-2-

Theory of Automata and Formal Languages

2. The alphabet for the DFA remains the same as it was for the NFA.
3. The initial state of the DFA is the one with the same name as the initial
state of the NFA.
4. The transition function is constructed in a manner that almost has to
be seen to be understood, but is basically as follows. Starting at the
initial state, find which combination of states each element of the
alphabet results in; the concatenation of these states is the state you
go to in the DFA. For example, if reading a 0 from state A allows you to
go to either state B or C in the NFA, then in the DFA reading a 0 from
state A will lead to state BC. Repeat the above procedure for each
resulting state until all possible transitions are covered. It will often
turn out that not all combinations of NFA states are actually reachable,
and as such can be completely omitted from the DFA.
5. The accept states of the DFA are all states that include at least one of
the accept states of the NFA. For example, if the NFA has states A, B,
and C, with A and C being the accept states, the accept states of the
DFA are A, C, AC, and ABC.
Once this process is complete, the DFA will be functionally identical
to the NFA.
Language of FSA: We can write a language from an FSA by analyzing it. To write a
language for given FSA we have to keep our eyes on acceptance words of that particular
FSA. It is elaborated with the help of examples below
Example 1:
a, b
-1

a, b

+2
a, b

Language for the given FSA is : Language having words of odd length
i.e. (a + b)((a + b)(a + b))*

-1

+3

b
4

+5

a, b

a, b
6

a, b

Tahir Naseem/Handout 1

-3-

Theory of Automata and Formal Languages

Language for the given FSA is : Language having two words aa and bb
i.e. aa + bb

Nondeterministic Finite Automata (NFA)


Formal Definition
A nondeterministic finite automaton (NFA) is a 5-tuple (Q, , , q0, F) where
o Q is a finite set of states
o is an alphabet
o : Q ( U {}) Q is a transition function
o q0 Q is the initial state
o F Q is a set of accepting states (or final states).
Differences from DFA:
o transition function d can go into several states
o It allows e-transitions
Meaning of NFA

Check that you are at the end of


input

Choosing Where to Go

Tahir Naseem/Handout 1

-4-

Theory of Automata and Formal Languages

State q0 has two transitions


labeled 1

Upon reading 1, we have


the choice of staying in q0
or moving to q1

The ability to make choices


Case 1

State q1 has no transition


labeled 1

Upon reading 1 in q1, we


die; upon reading 0, we
continue to q2

Case 2

Tahir Naseem/Handout 1

-5-

Theory of Automata and Formal Languages

State q3 has no transition


going out

Upon reading 0 or 1 in q3,


we die

How to run an NFA

It accepts if at the end, one of its act

Tahir Naseem/Handout 1

-6-

Theory of Automata and Formal Languages

Example 1:
Construct an NFA over alphabet {0, 1} that accepts those strings that contain the pattern 001
somewhere.

0, 1
+q3

Language of NFA:
The NFA accepts string x * if there is some path that, starting from q0, leads to an
accepting state as the string is read left to right.
The language of an NFA is the set of all strings that the NFA accepts.
Transitions

, aa, ba, bb,

Example 2:

Tahir Naseem/Handout 1

-7-

Theory of Automata and Formal Languages

Example 3:
Construct an NFA that accepts all strings with an even number of 0s or an odd number
of 1s

q0

Вам также может понравиться