0% found this document useful (0 votes)
184 views

Finite Automata

This document discusses finite automata and non-deterministic finite automata (NFAs). It begins by defining languages and deterministic finite automata (DFAs) using states, transitions, initial states, accepting states, and transition functions. NFAs are then introduced which allow transitions without reading an input or multiple possible state transitions. While NFAs are more convenient, any NFA can be converted to an equivalent DFA using a process that tracks all possible state sets. Examples are provided of constructing DFAs and NFAs to recognize specific languages.

Uploaded by

Elmer Perez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
184 views

Finite Automata

This document discusses finite automata and non-deterministic finite automata (NFAs). It begins by defining languages and deterministic finite automata (DFAs) using states, transitions, initial states, accepting states, and transition functions. NFAs are then introduced which allow transitions without reading an input or multiple possible state transitions. While NFAs are more convenient, any NFA can be converted to an equivalent DFA using a process that tracks all possible state sets. Examples are provided of constructing DFAs and NFAs to recognize specific languages.

Uploaded by

Elmer Perez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

Mathematical Foundations of Computer Science

Chapter 2: Finite Automata

Languages
language (over an alphabet ) is any subset of the set of all possible strings over . The set of all possible strings is written as *. Example:
A

= {a, b, c} * = {, a, b, c, ab, ac, ba, bc, ca, aaa, } one language might be the set of strings of length less than or equal to 2.
L = {, a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc}

Finite Automata
A

deterministic finite automaton (dfa) is a mathematical model for a machine that can accept certain types of languages. The singular is automaton, the plural is automata.

Finite Automata
on/off switch

"guts" of the machine


accept or reject

input tape

tape read head

A finite automaton

Finite Automata
The

machine, or automaton, when on, will at any moment be in some "state". This type of machine has only a finite number of states. The machine goes into new states as it reads the input tape. When the light is on, the string up to that point is "accepted". When off, it is "rejected". The machine has to read all the way to the last character on the tape.

Finite Automata
A

deterministic finite automaton (dfa) is a quintuple M = (Q, , , q0, F) , where:


Q is a finite set of states, is a finite set of symbols (the alphabet), q0 is one of the states in Q (called the initial state), F is a subset of Q and represents the final, or accepting states of M, and : Q Q is the transition function of M.

The

transition function specifies, for each state and symbol, the next state the machine will enter.

Finite Automata
The

transition function specifies, for each state and symbol, the next state the machine will enter. When we write (q1, b) = q2, we are saying that if the machine is in state q1 and the next symbol read is b, then the state of the machine becomes state q2. The machine always starts in the initial state looking at the leftmost symbol on the tape. The machine stops after reading the rightmost symbol on the tape.

Finite Automata
transitive closure of , written as *(q1, w) = q2 is used to represent the fact that the machine, when in state q1, winds up in state q2 by following the path that exists for the transitions specified by the series of symbols in w. For example, if (q1, a) = q2, (q2, b) = q3 and (q3, a) = q4, then *(q1, aba) = q4.
The

Finite Automata
The

language accepted by a dfa is exactly the set of strings over the alphabet that result in the machine ending in an accepting state. The language is symbolized as L(M). The transition function makes the automaton deterministic. At each moment in time, the machine has exact instructions as to what will happen next.

Bubble Diagrams

In order to visualize a particular finite automaton, we draw a bubble diagram, (or bubble chart). Here's a simple example:

b a

The circles represent states, with a double circle being an accepting state. The arcs represent the transitions of the transition function.

Bubble Diagrams
What

language is accepted by this machine?

b
a
L

= {x | x {a, b}* and x has an even number of b's}

Example 1

Here is another example of a finite automaton M, in "bubble diagram" form: b


a
q0 q1

a
q3

a, b

q2

a, b

What is (q1, b)? q1 q3 What is *(q0. abbaba)? Given that q3 is the only accepting state, what is L(M), the language is accepted by this machine?

Strings beginning with an a and containing at least two a's.

Example 2
Construct a

dfa that accepts the language L = {x {a, b} | x begins and ends with the sequence aab.} b a a a b a a
A AA AAB A AA

b a
x

accepting state.

b
b a,b "trap" state

Why?

Example 2
Construct a

dfa that accepts the language L = {x {a, b} | x begins and ends with the sequence aab.} b a a a b a a
q0 q1 q2 q3 q4 q5

b
qT

b a
q6

b
b a,b

bubble diagram format

Example 2
a q0 q1 q2 q3 q1 q2 qT q4 b qT qT q3 q6

Table format

q4
q5 q6 qT

q5
q5 q4 qT

q6
q3 q6 qT

Example 3
Construct a

dfa that accepts the language L = {x {a, b} | x has an even number of a's and an odd number of b's.}
EE

a a

OE

b
EO

b a a

b
OO

Example 4
Construct a

dfa that accepts the language L = {x {a, b} | x consists of even number of a's followed by an odd number of b's.} a b a a

a
b

a,b

b
b

Finite Automata
That's

how finite automata are built, and that's how they work. Some automata are easy to construct; others quite tricky or difficult. Representations:

bubble diagram format


good for construction good for visualizing behavior

table format
good for computer simulation good for applying certain algorithms

Chapter 2, Section 1 Homework


2.1/1-15

Non-deterministic finite automata


Notice

how annoying all the necessary detail is. Perhaps we can come up with a more powerful and more convenient automaton.

Non-deterministic finite automata


A

non-deterministic finite automaton (nfa) is a quintuple M = (Q, , , q0, F) , where Q is a finite set of states, is a finite set of symbols (the alphabet), q0 is one of the states in Q (called the initial state), F is a subset of Q and represents the final, or accepting states of M, and : Q {, } 2Q is the transition function of M.

Non-deterministic finite automata


Q {, } 2Q means that if the machine is in state q and sees an a (or perhaps merely ignoring the input [] he can wind up in any of the states within some set of states. (q, a) = {q1, q4, q7} goes to any of three states. (q, a) = {} "dies" (q, ) = {q, p} goes to either of 2 states without looking at the input tape.
:

Non-deterministic finite automata


The

only difference is in the transition function. We now allow the machine to go to a new state WITHOUT looking at a symbol. ( transitions) We also allow the machine the choice of going to any of a number of states for a given symbol!!! (non-deterministic transitions)

Non-deterministic finite automata


We

have just made this machine smart, as we will shortly see. Having non-deterministic transitions means that we can specify no transition for a qiven state and symbol as well, which makes design a little less cluttered because we don't have worry about "useless" stuff.

Non-deterministic finite automata


If

there is no transition specified,


the machine merely dies. It does not accept the string and can accept no more input, just like for specifying trap states in a dfa.

But

if there is ANY path from the initial state to an accepting state for a given string

that string is accepted and belongs to L(M). even if only one out of a million paths leads to an accepting state!!!!

Now

thats smart!

Constructing an nfa
Construct an

nfa that accepts the language L = {x {a, b} | x begins and ends with the sequence aab.} a a b end of
q0 q1 q2 q3

start of string: aab


q4 q5

string: aab
q6 q7

a,b middle of string: anything

Non-deterministic finite automata


But

nfa's are no more powerful than dfa's !!!

If a language can be recognized by an nfa, it can be recognized by a dfa.

We

"prove" this by demonstrating an algorithm that converts any nfa into a corresponding dfa. The book describes the algorithm, but it's hard to understand; we'll look at how it works by studying the last example.

Chapter 2, Section 2 Homework


2.2/2-12

Converting nfa's to dfa's

Look at the nfa we just constructed:

a q0 q1 q2 {q1} {q2}

b {q3}

*(q0, a) = {q1} so (Q0, a) in the corresponding dfa would equal Q1. The subscript of Q represents the set of states that the nfa could wind up in. *(q0, b) = {} so (Q0, b) in the corresponding dfa would equal QT, the trap state.

q3 q4 q5 q6 q7

{q4, q5} {q6}

{q4} {q7}

{q4}

Converting nfa's to dfa's

Of course (QT, a) = (QT, b) = QT since it's the trap state. Now we proceed to state Q1 and draw arcs for a and for b. We keep going until we add no more new states to the dfa and all the transitions have been specified. Note that since (q3, a) = {q4, q5}, (Q3, a) = Q45

a q0 q1 q2 {q1} {q2}

b {q3}

q3 q4 q5 q6 q7

{q4, q5} {q6}

{q4} {q7}

{q4}

Converting nfa's to dfa's


a b

a
Q0 Q1

a
Q2

b
Q3

q0

{q1}

b
QT

a b a
Q45

q1
q2 q3 q4

{q2}
{q4, q5}

{q3} {q4} {q4}

a
Q456

b
b

Q4

a b
Q47

q5
q6 q7

{q6}

{q7}

a, b

a because of the transition, if the nfa is in q3, it could just as well be in q4. (the closure of q3 is {q3, q4}

Converting nfa's to dfa's

Start with the initial state of the nfa Create a corresponding initial state in the dfa For each symbol of the alphabet, find the set of states that you could wind up in. Create a corresponding state in the dfa. Keep going until there are no more states, and no more transitions need to be drawn.

Note: When there are lambda transitions, you have to look at the closure. Remember: a = a = a

Any state in the dfa which has in it the number of an accepting state of the nfa becomes an accepting state.

Chapter 2, Section 3 Homework


2.3/1-6, 8,

12

Chapter 2 Homework Summary


2.1/1-15

2.2/2-12
2.3/1-6, 8,

12

You might also like