SlideShare a Scribd company logo
1 of 48
Finite Automata
Finite Automata
• Two types – both describe what are called regular
languages
– Deterministic (DFA) – There is a fixed number of states and we
can only be in one state at a time
– Nondeterministic (NFA) –There is a fixed number of states but we
can be in multiple states at one time

• While NFA’s are more expressive than DFA’s, we will see
that adding nondeterminism does not let us define any
language that cannot be defined by a DFA.
• One way to think of this is we might write a program using
a NFA, but then when it is “compiled” we turn the NFA
into an equivalent DFA.
Informal Example
• Customer shopping at a store with an electronic
transaction with the bank
– The customer may pay the e-money or cancel the emoney at any time.
– The store may ship goods and redeem the electronic
money with the bank.
– The bank may transfer any redeemed money to a
different party, say the store.

• Can model this problem with three automata
Bank Automata
Actions in bold are initiated by the entity.
Otherwise, the actions are initiated by someone else and received by the specified automata
Start

a

pay

b
ship

Store

c

redeem

transfer

d

ship
redeem

f
ship

transfer

e

g

Cancel

2
Pay

Cancel

1

Start

Customer

Start

Bank

Redeem

3

Transfer

4
Ignoring Actions
• The automata only describes actions of interest
– To be more precise, with a DFA (deterministic finite automaton)
we should specify arcs for all possible inputs.
– E.g., what should the customer automaton do if it receives a
“redeem”?
– What should the bank do if it is in state 2 and receives a
“redeem”?

• The typical behavior if we receive an unspecified action is
for the automaton to die.
– The automaton enters no state at all, and further action by the
automaton would be ignored.
– The best method though is to specify a state for all behaviors, as
indicated as follows for the bank automaton.
Complete Bank Automaton
Redeem, Transfer,
Pay, Ship, Cancel

2

Redeem, Pay,
Ship, Cancel

Cancel
Transfer, Pay,
Ship

1

Redeem

3

Redeem, Transfer,
Pay, Ship, Cancel

Transfer

4

Start

Bank
Ignores other actions that may be received
Entire System as Automaton
• When there are multiple automata for a system, it is useful to
incorporate all of the automata into a single one so that we can better
understand the interaction.
• Called the product automaton. The product automaton creates a new
state for all possible states of each automaton.
• Since the customer automaton only has one state, we only need to
consider the pair of states between the bank and the store.
– For example, we start in state (a,1) where the store is in its start state, and
the bank is in its start state. From there we can move to states (a,2) if the
bank receives a cancel, or state (b,1) if the store receives a pay.

• To construct the product automaton, we run the bank and store
automaton “in parallel” using all possible inputs and creating an edge
on the product automaton to the corresponding set of states.
Product Automaton
start

a

b
P

1
C

c

d

e

f

g

S
C

C

R

2

S
P
R

3

S
T

4

T

S
Product Automaton
• How is this useful? It can help validate our protocol.
• It tells us that not all states are reachable from the start
state.
– For example, we should never be in state (g,1) where we have
shipped and transferred cash, but the bank is still waiting for a
redeem.

• It allows us to see if potential errors can occur.
– We can reach state (c, 2). This is problematic because it allows a
product to be shipped but the money has not been transferred to
the store.
– In contrast, we can see that if we reach state (d, 3) or (e, 3) then
the store should be okay – a transfer from the bank must occur
• assuming the bank automaton doesn’t “die” which is why it is useful
to add arcs for all possible inputs to complete the automaton
Simple Example – 1 way door
• As an example, consider a
one-way automatic door.
This door has two pads
that can sense when
someone is standing on
them, a front and rear pad.
We want people to walk
through the front and
toward the rear, but not
allow someone to walk the
other direction:

Front
Pad

Rear
Pad
One Way Door
• Let’s assign the following codes to our different input cases:
a - Nobody on either pad
b - Person on front pad
c - Person on rear pad
d - Person on front and rear pad
• We can design the following automaton so that the door doesn’t open
if someone is still on the rear pad and hit them:
a,c,d

Start

b

C

b,c,d

O
a
Formal Definition of a Finite
Automaton
1.
2.
3.
4.
5.

Finite set of states, typically Q.
Alphabet of input symbols, typically ∑
One state is the start/initial state, typically q0
// q0 ∈ Q
Zero or more final/accepting states; the set is typically F. // F ⊆ Q
A transition function, typically δ. This function
•
•
•
•

Takes a state and input symbol as arguments.
Returns a state.
One “rule” would be written δ(q, a) = p, where q and p are states, and a is
an input symbol.
Intuitively: if the FA is in state q, and input a is received, then the FA
goes to state p (note: q = p OK).

1. A FA is represented as the five-tuple: A = (Q, ∑, δ,q0, F). Here, F is a
set of accepting states.
One Way Door – Formal Notation
Using our formal notation, we have:
Q = {C, O} (usually we’ll use q0 and q1 instead)
F = {}
There is no final state
q0 = C
This is the start state
∑ = {a,b,c,d}
The transition function, δ , can be specified by the table:
a
C C
O C

b
O
O

c
C
O

c
C
O

Write each δ(state,symbol)?

The start state is indicated with the 
If there are final accepting states, that is indicated with a * in the proper row.
Exercise
• Using ∑={0,1} a “clamping” circuit waits for a 1
input, and forever after makes a 1 output
regardless of the input. However, to avoid
clamping on spurious noise, design a DFA that
waits for two 1's in a row, and “clamps” only then.
• Write the transition function in table format as
well as graph format.
Formal Definition of Computation
• Let M = (Q, ∑, δ,q0, F) be a finite
automaton and let w = w1w2…wn be a string
where each wi is a member of alphabet ∑.
• M accepts w if a sequence of states r0r1…rn
in Q exists with three conditions:
1. r0 = q0
2. δ(ri, wi+1) = ri+1 for i=0, … , n-1
3. rn ∈ F
We say that M recognizes language A if A = {w | M accepts w }
In other words, the language is all of those strings that are accepted
by the finite automata.
DFA Example
• Here is a DFA for the
language that is the set
of all strings of 0’s
and 1’s whose
numbers of 0’s and 1’s
are both even:

1

Start

q0

q1
1

0

0

0

0

1

q2

q3
1
Aside: Type Errors
• A major source of confusion when dealing with
automata (or mathematics in general) is making
“type errors."
• Don't confuse A, a FA, i.e., a program, with L(A),
which is of type “set of strings."
• The start state q0 is of type “state," but the
accepting states F is of type “set of states."
• a could be a symbol or a could be a string of
length 1 depending on the context
DFA Exercise
• The following figure below is a marble-rolling
toy. A marble is dropped at A or B. Levers x1, x2,
and x3 cause the marble to fall either to the left or
to the right. Whenever a marble encounters a
lever, it causes the lever to reverse after the marble
passes, so the next marble will take the opposite
branch.
• Model this game by a finite automaton. Let
acceptance correspond to the marble exiting at D.
Non-acceptance represents a marble exiting at C.
Marble Rolling Game
A

B

x1

x3

x2

C

D
Marble Game Notation
• The inputs and outputs (A-D) become the alphabet of the automaton,
while the levers indicate the possible states.
• If we define the initial status of each lever to be a 0, then if the levers
change direction they are in state 1.
• Let’s use the format x1x2x3 to indicate a state. The initial state is 000.
If we drop a marble down B, then the state becomes to 011 and the
marble exits at C.
• Since we have three levers that can take on binary values, we have 8
possible states for levers, 000 to 111.
• Further identify the states by appending an “a” for acceptance, or “r”
for rejection.
• This leads to a total of 16 possible states. All we need to do is start
from the initial state and draw out the new states we are led to as we
get inputs from A or B.
Messy Marble DFA
A
Start

000r

B

A
100r
B
A

A
000a

A
B

111r
A

A
010r

011r

B

001a

B
A
B

A

110a
B

B
101a
B

B
100a

101r

B
A

To 010r
To 111r

A
A

B

110r
A

010a

B
Marble DFA – Table Format
• Easier to see in table
format. Note that not
all states are
accessible.

A

B

->000r 100r 011r
*000a 100r 011r
*001a 101r 000a
010r 110r 001a
*010a 110r 001a
011r 111r 010a
100r 010r 111r
*100a 010r 111r
101r 011r 100a
*101a 011r 100a
110r 000a 101a
*110a 000a 101a
111r 001a 110a
Regular Operations
• Brief intro here – will cover more on regular
expressions shortly
• In arithmetic, we have arithmetic operations
– + * / etc.

• For finite automata, we have regular operations
– Union
– Concatenation
– Star
Algebra for Languages
1.

The union of two languages L and M is the set of strings
that are in both L and M.
•

2.

Example: if L = { 0, 1} and M = {111} then L ∪ M is {0, 1,
111}.

The concatenation of languages L and M is the set of
strings that can be formed by taking any string in L and
concatenating it with any string in M. Concatenation is
denoted by LM although sometimes we’ll use L•M
(pronounced “dot”).
•

Example, if L = {0, 1} and M = {ε, 010} then LM is { 0, 1,
0010, 1010}.
Algebra for Languages
3.

The closure, star, or Kleene star of a language L is denoted L* and represents
the set of strings that can be formed by taking any number of strings from L
with repetition and concatenating them. It is a unary operator.
More specifically, L0 is the set we can make selecting zero strings from L. L 0 is
always { ε }.
L1 is the language consisting of selecting one string from L.
L2 is the language consisting of concatenations selecting two strings from L.
…
L* is the union of L0, L1, L2, … L∞
For example, if L = {0 , 10} then
L0 = { ε }.
L1 = {0, 10 }
L2 = {00, 010, 100, 1010}
L3 = {000, 0010, 0100, 01010, 10010, 1000, 10100, 101010}
… and L* is the union of all these sets, up to infinity.
Closure Properties of Regular
Languages
• Closure refers to some operation on a language, resulting
in a new language that is of the same “type” as those
originally operated on
– i.e., regular in our case

• We won’t be using the closure properties extensively here;
consequently we will state the theorems and give some
examples. See the book for proofs of the theorems.
• The regular languages are closed under union,
concatenation, and *. I.e., if A1 and A2 are regular
languages then
– A1 ∪ A2 is also regular
– A1A2 is also regular
– A1* is also regular

Later we’ll see easy ways
to prove the theorems
Nondeterministic Finite Automata
• A NFA (nondeterministic finite automata) is able to be in
several states at once.
– In a DFA, we can only take a transition to a single deterministic state
– In a NFA we can accept multiple destination states for the same input.
– You can think of this as the NFA “guesses” something about its input
and will always follow the proper path if that can lead to an accepting
state.
– Another way to think of the NFA is that it travels all possible paths,
and so it remains in many states at once. As long as at least one of the
paths results in an accepting state, the NFA accepts the input.

• NFA is a useful tool
– More expressive than a DFA.
– BUT we will see that it is not more powerful! For any NFA we can
construct a corresponding DFA
– Another way to think of this is the DFA is how an NFA would actually
be implemented (e.g. on a traditional computer)
NFA Example
• This NFA accepts only
those strings that end
in 01

0,1

0

q0

Start

1

q1
q0

• Running in “parallel
threads” for string
1100101

q0

1
1

q0

0

q0

q1 - stuck

0

q0

q1

q0

1

q2 - stuck

0

q0

q1

q0

q2 - accept

1

q2
Formal Definition of an NFA
• Similar to a DFA
1. Finite set of states, typically Q.
2. Alphabet of input symbols, typically ∑
3. One state is the start/initial state, typically q0
4. Zero or more final/accepting states; the set is typically F.
5. A transition function, typically δ . This function:
• Takes a state and input symbol as arguments.
• Returns a set of states instead of a single state, as a DFA
6. A FA is represented as the five-tuple: A = (Q, ∑, δ ,q0, F). Here, F is a set of accepting
states.
Previous NFA in Formal Notation
The previous NFA could be specified formally as:
({q0,q1,q2}, {0,1}, δ, q0, {q2})
The transition table is:
0
 q0 {q0,q1}
q1 Ø
* q2 Ø

1
{q0}
{q2}
Ø
NFA Example
• Practice with the following NFA to satisfy
yourself that it accepts ε, a, baba, baa, and
aa, but that it doesn’t accept b, bb, and
babba.
q1
b
a

q2

a
ε

a,b

q3
NFA Exercise
• Construct an NFA that will accept strings over
alphabet {1, 2, 3} such that the last symbol
appears at least twice, but without any intervening
higher symbol, in between:
– e.g., 11, 2112, 123113, 3212113, etc.

• Trick: use start state to mean “I guess I haven't
seen the symbol that matches the ending symbol
yet.” Use three other states to represent a guess
that the matching symbol has been seen, and
remembers what that symbol is.
NFA Exercise

You should be able to generate the transition table
Formal Definition of an NFA
• Same idea as the DFA
• Let N = (Q, ∑, δ,q0, F) be an NFA and let w =
w1w2…wn be a string where each wi is a member of
alphabet ∑.
• N accepts w if a sequence of states r0r1…rn in Q
exists with three conditions:
1. r0 = q0
2. ri+1 ∈ δ(ri, wi+1) for i=0, … , n-1
3. rn ∈ F
Observe that δ(ri, wi+1) is the set of allowable next states
We say that N recognizes language A if A = {w | N accepts w }
Equivalence of DFA’s and NFA’s
• For most languages, NFA’s are easier to construct than
DFA’s
• But it turns out we can build a corresponding DFA for any
NFA
– The downside is there may be up to 2n states in turning a NFA into a
DFA. However, for most problems the number of states is
approximately equivalent.

• Theorem: A language L is accepted by some DFA if and
only if L is accepted by some NFA; i.e. : L(DFA) = L(NFA)
for an appropriately constructed DFA from an NFA.
– Informal Proof: It is trivial to turn a DFA into an NFA (a DFA is
already an NFA without nondeterminism). The following slides will
show how to construct a DFA from an NFA.
NFA to DFA : Subset Construction
Let an NFA N be defined as N = (QN, ∑, δ N,q0, FN).
The equivalent DFA D = (QD, ∑,δD , {q0 }, FD) where:
1. QD = 2Qn ; i.e. QD is the set of all subsets of QN; that is, it is the power set of QN.
Often, not all of these states are accessible from the start state; these states may be
“thrown away.”
2. FD is the set of subsets S of QN such that S ∩ FN ≠ Ø. That is, FD is all sets of N’s
states that include at least one accepting state of N.
3. For each set S ⊆ QN and for each input symbol a in ∑:
δ D ( S , a ) =  δ N ( p, a )
p∈S

That is, to compute δD(S, a) we look at all the states p in S, see
what states N goes to starting from p on input a, and take the union
of all those states.
Subset Construction Example (1)
0,1

• Consider the NFA:

q0

Start

The power set of these
states is: { Ø, {q0}, {q1},
{q2}, {q0, q1}, {q0, q2},{q1,
q2}, {q0, q1, q2} }
New transition function
with all of these states and
go to the set of possible
inputs:

0

1

q1

0

1

Ø

Ø

Ø

 {q0}

{q0, q1}

{q0}

{q1}

Ø

{q2}

*{q2}

Ø

Ø

{q0, q1}

{q0, q1}

{q0, q2}

*{q0, q2}

{q0, q1}

{q0}

*{q1, q2}

Ø

{q2}

*{q0, q1,

{q0, q1}

{q0, q2}

q2
Subset Construction (2)
• Many states may be unreachable from our start state. A good way to
construct the equivalent DFA from an NFA is to start with the start
states and construct new states on the fly as we reach them.

0
Ø
{q0, q1}
{q0, q1}
{q0, q1}

Ø
 {q0}
{q0, q1}
*{q0, q2}

1
Ø
{q0}
{q0, q2}
{q0}

1
0

Graphically:

Start

{q0}

0

{q0, q1}
1

1
0

{q0,q2}
NFA to DFA Exercises
a

• Convert the following
NFA’s to DFA’s

Start

q0

a,b

b

15 possible states on
this second one (might
be easier to represent in
table format)

q1
Corollary
• A language is regular if and only if some
nondeterministic finite automaton
recognizes it
• A language is regular if and only if some
deterministic finite automaton recognizes it
Epsilon Transitions
• Extension to NFA – a “feature” called epsilon
transitions, denoted by ε, the empty string
• The ε transition lets us spontaneously take a
transition, without receiving an input symbol
• Another mechanism that allows our NFA to be in
multiple states at once.
– Whenever we take an ε edge, we must fork off a new
“thread” for the NFA starting in the destination state.

• While sometimes convenient, has no more power
than a normal NFA
– Just as a NFA has no more power than a DFA
Formal Notation – Epsilon
Transition
• Transition function δ is now a function that
takes as arguments:
– A state in Q and
– A member of ∑ ∪ {ε}; that is, an input symbol
or the symbol ε. We require that ε not be a
symbol of the alphabet ∑ to avoid any
confusion.
Epsilon NFA Example
0

Start

q

1

r

ε

s

ε

0
1

In this ε-NFA, the string “001” is accepted by the path qsrqrs,
where the first qs matches 0, sr matches ε, rq matches 0, qr
matches 1, and then rs matches ε. In other words, the accepted
string is 0ε0ε1ε.
Epsilon Closure
• Epsilon closure of a state is simply the set
of all states we can reach by following the
transition function from the given state that
are labeled ε.
0

Example:
Start

q

1

r

ε

s

ε

0
1

•
•

ε-closure(q) = { q }
ε-closure(r) = { r, s}
Epsilon NFA Exercise
• Exercise: Design an ε-NFA for the
language consisting of zero or more a’s
followed by zero or more b’s followed by
zero or more c’s.
Eliminating Epsilon Transitions
To eliminate ε-transitions, use the following to convert to a DFA:
1. Compute ε-closure for the current state, resulting in a set of states S.
2. δD(S,a) is computed for all a in Σ by
a. Let S = {p1, p2, … pk}
k

b. Compute

 δ ( p , a) and call this set {r1, r2, r3 … rm}
i

This set is achieved

i =1

by following input a, not by following any ε-transitions
m

c. Add the ε-transitions in by computing δ ( S , a ) =  ε − closure(ri )
i =1

3. Make a state an accepting state if it includes any final states in the ε-NFA.

In simple terms: Just like converting a regular NFA to a DFA
except follow the epsilon transitions whenever possible after
processing an input
Epsilon Elimination Example
0

Start

q

1

r

ε

s

ε

0
1

Converts to:
Start

q

0,1

0,1

sr
Epsilon Elimination Exercise
• Exercise: Here is the ε-NFA for the language
consisting of zero or more a’s followed by zero or
more b’s followed by zero or more c’s.
• Eliminate the epsilon transitions.
a
Start

q

b
ε

r

c
ε

s

More Related Content

What's hot

15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and boundAbhishek Singh
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
context free language
context free languagecontext free language
context free languagekhush_boo31
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and LexemeA. S. M. Shafi
 
1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automatonSampath Kumar S
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMRajendran
 
TOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataTOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataMohammad Imam Hossain
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESsuthi
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite AutomataAdel Al-Ofairi
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 

What's hot (20)

15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
Huffman coding
Huffman coding Huffman coding
Huffman coding
 
Ch2 finite automaton
Ch2 finite automatonCh2 finite automaton
Ch2 finite automaton
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Finite automata
Finite automataFinite automata
Finite automata
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
context free language
context free languagecontext free language
context free language
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEM
 
pushdown automata
pushdown automatapushdown automata
pushdown automata
 
TOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataTOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite Automata
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 

Viewers also liked

Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfadeepinderbedi
 
Finite automata
Finite automataFinite automata
Finite automataPusp Sunar
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Formal language & automata theory
Formal language & automata theoryFormal language & automata theory
Formal language & automata theoryNYversity
 
рус. язык
рус. языкрус. язык
рус. языкyankaaa
 
The futere in my hands
The futere in my handsThe futere in my hands
The futere in my handsRobert Mihail
 
Second Briefing - 1st Buikwe District Teachers' Project
Second Briefing - 1st Buikwe District Teachers' ProjectSecond Briefing - 1st Buikwe District Teachers' Project
Second Briefing - 1st Buikwe District Teachers' Projectlissalourenco
 
[ENG] 3rd International Symposium on Controversies in Psychiatry. Mexico 2014
[ENG] 3rd International Symposium on Controversies in Psychiatry. Mexico 2014[ENG] 3rd International Symposium on Controversies in Psychiatry. Mexico 2014
[ENG] 3rd International Symposium on Controversies in Psychiatry. Mexico 2014Symposiums Controversias en Psiquiatría
 
Mau san pham hoc sinh
Mau san pham hoc sinhMau san pham hoc sinh
Mau san pham hoc sinhnhomhopestar
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 

Viewers also liked (19)

Nfa egs
Nfa egsNfa egs
Nfa egs
 
Finite automata
Finite automataFinite automata
Finite automata
 
Deterministic Finite Automata
Deterministic Finite AutomataDeterministic Finite Automata
Deterministic Finite Automata
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfa
 
Lecture: Automata
Lecture: AutomataLecture: Automata
Lecture: Automata
 
Finite automata
Finite automataFinite automata
Finite automata
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Formal language & automata theory
Formal language & automata theoryFormal language & automata theory
Formal language & automata theory
 
3 convicciones que tengo
3 convicciones que tengo3 convicciones que tengo
3 convicciones que tengo
 
рус. язык
рус. языкрус. язык
рус. язык
 
DESTINOS VISITADOS
DESTINOS VISITADOSDESTINOS VISITADOS
DESTINOS VISITADOS
 
The futere in my hands
The futere in my handsThe futere in my hands
The futere in my hands
 
Second Briefing - 1st Buikwe District Teachers' Project
Second Briefing - 1st Buikwe District Teachers' ProjectSecond Briefing - 1st Buikwe District Teachers' Project
Second Briefing - 1st Buikwe District Teachers' Project
 
يناير 2013سلامتك 23
يناير 2013سلامتك 23يناير 2013سلامتك 23
يناير 2013سلامتك 23
 
[ENG] 3rd International Symposium on Controversies in Psychiatry. Mexico 2014
[ENG] 3rd International Symposium on Controversies in Psychiatry. Mexico 2014[ENG] 3rd International Symposium on Controversies in Psychiatry. Mexico 2014
[ENG] 3rd International Symposium on Controversies in Psychiatry. Mexico 2014
 
Mau san pham hoc sinh
Mau san pham hoc sinhMau san pham hoc sinh
Mau san pham hoc sinh
 
Hosobaiday
HosobaidayHosobaiday
Hosobaiday
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
Daft Punk
Daft PunkDaft Punk
Daft Punk
 

Similar to Finite automata

a simple idealized machine used to recognize patterns within input taken from...
a simple idealized machine used to recognize patterns within input taken from...a simple idealized machine used to recognize patterns within input taken from...
a simple idealized machine used to recognize patterns within input taken from...NALESVPMEngg
 
Free Ebooks Download ! Edhole
Free Ebooks Download ! EdholeFree Ebooks Download ! Edhole
Free Ebooks Download ! EdholeEdhole.com
 
Mba ebooks ! Edhole
Mba ebooks ! EdholeMba ebooks ! Edhole
Mba ebooks ! EdholeEdhole.com
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computationprasadmvreddy
 
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdf
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdfPreparatory_questions_final_exam_DigitalElectronics1 (1).pdf
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdfrdjo
 
Automata based programming
Automata based programmingAutomata based programming
Automata based programmingVisnuDharsini
 
Regular expression automata
Regular expression automataRegular expression automata
Regular expression automata성욱 유
 
Introduction state machine
Introduction state machineIntroduction state machine
Introduction state machineShreyans Pathak
 
closure properties of regular language.pptx
closure properties of regular language.pptxclosure properties of regular language.pptx
closure properties of regular language.pptxThirumoorthy64
 
Module 1 ppt class.pptx
Module 1 ppt class.pptxModule 1 ppt class.pptx
Module 1 ppt class.pptxVivekNaik55
 
Module ppt class.pptx
Module ppt class.pptxModule ppt class.pptx
Module ppt class.pptxVivekNaik71
 
state_machines1.pdf
state_machines1.pdfstate_machines1.pdf
state_machines1.pdfrdjo
 
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdfFariyaTasneem1
 
Patterns, Automata and Regular Expressions
Patterns, Automata and Regular ExpressionsPatterns, Automata and Regular Expressions
Patterns, Automata and Regular ExpressionsDarío Garigliotti
 

Similar to Finite automata (20)

a simple idealized machine used to recognize patterns within input taken from...
a simple idealized machine used to recognize patterns within input taken from...a simple idealized machine used to recognize patterns within input taken from...
a simple idealized machine used to recognize patterns within input taken from...
 
NLP_KASHK:Finite-State Automata
NLP_KASHK:Finite-State AutomataNLP_KASHK:Finite-State Automata
NLP_KASHK:Finite-State Automata
 
TOC Introduction
TOC Introduction TOC Introduction
TOC Introduction
 
Free Ebooks Download ! Edhole
Free Ebooks Download ! EdholeFree Ebooks Download ! Edhole
Free Ebooks Download ! Edhole
 
Mba ebooks ! Edhole
Mba ebooks ! EdholeMba ebooks ! Edhole
Mba ebooks ! Edhole
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
flat unit1
flat unit1flat unit1
flat unit1
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
 
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdf
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdfPreparatory_questions_final_exam_DigitalElectronics1 (1).pdf
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdf
 
Automata based programming
Automata based programmingAutomata based programming
Automata based programming
 
Regular expression automata
Regular expression automataRegular expression automata
Regular expression automata
 
Introduction state machine
Introduction state machineIntroduction state machine
Introduction state machine
 
Final fa part1
Final fa part1Final fa part1
Final fa part1
 
closure properties of regular language.pptx
closure properties of regular language.pptxclosure properties of regular language.pptx
closure properties of regular language.pptx
 
Module 1 ppt class.pptx
Module 1 ppt class.pptxModule 1 ppt class.pptx
Module 1 ppt class.pptx
 
Module ppt class.pptx
Module ppt class.pptxModule ppt class.pptx
Module ppt class.pptx
 
state_machines1.pdf
state_machines1.pdfstate_machines1.pdf
state_machines1.pdf
 
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
 
Patterns, Automata and Regular Expressions
Patterns, Automata and Regular ExpressionsPatterns, Automata and Regular Expressions
Patterns, Automata and Regular Expressions
 
CS 5th.pptx
CS 5th.pptxCS 5th.pptx
CS 5th.pptx
 

Recently uploaded

Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

Finite automata

  • 2. Finite Automata • Two types – both describe what are called regular languages – Deterministic (DFA) – There is a fixed number of states and we can only be in one state at a time – Nondeterministic (NFA) –There is a fixed number of states but we can be in multiple states at one time • While NFA’s are more expressive than DFA’s, we will see that adding nondeterminism does not let us define any language that cannot be defined by a DFA. • One way to think of this is we might write a program using a NFA, but then when it is “compiled” we turn the NFA into an equivalent DFA.
  • 3. Informal Example • Customer shopping at a store with an electronic transaction with the bank – The customer may pay the e-money or cancel the emoney at any time. – The store may ship goods and redeem the electronic money with the bank. – The bank may transfer any redeemed money to a different party, say the store. • Can model this problem with three automata
  • 4. Bank Automata Actions in bold are initiated by the entity. Otherwise, the actions are initiated by someone else and received by the specified automata Start a pay b ship Store c redeem transfer d ship redeem f ship transfer e g Cancel 2 Pay Cancel 1 Start Customer Start Bank Redeem 3 Transfer 4
  • 5. Ignoring Actions • The automata only describes actions of interest – To be more precise, with a DFA (deterministic finite automaton) we should specify arcs for all possible inputs. – E.g., what should the customer automaton do if it receives a “redeem”? – What should the bank do if it is in state 2 and receives a “redeem”? • The typical behavior if we receive an unspecified action is for the automaton to die. – The automaton enters no state at all, and further action by the automaton would be ignored. – The best method though is to specify a state for all behaviors, as indicated as follows for the bank automaton.
  • 6. Complete Bank Automaton Redeem, Transfer, Pay, Ship, Cancel 2 Redeem, Pay, Ship, Cancel Cancel Transfer, Pay, Ship 1 Redeem 3 Redeem, Transfer, Pay, Ship, Cancel Transfer 4 Start Bank Ignores other actions that may be received
  • 7. Entire System as Automaton • When there are multiple automata for a system, it is useful to incorporate all of the automata into a single one so that we can better understand the interaction. • Called the product automaton. The product automaton creates a new state for all possible states of each automaton. • Since the customer automaton only has one state, we only need to consider the pair of states between the bank and the store. – For example, we start in state (a,1) where the store is in its start state, and the bank is in its start state. From there we can move to states (a,2) if the bank receives a cancel, or state (b,1) if the store receives a pay. • To construct the product automaton, we run the bank and store automaton “in parallel” using all possible inputs and creating an edge on the product automaton to the corresponding set of states.
  • 9. Product Automaton • How is this useful? It can help validate our protocol. • It tells us that not all states are reachable from the start state. – For example, we should never be in state (g,1) where we have shipped and transferred cash, but the bank is still waiting for a redeem. • It allows us to see if potential errors can occur. – We can reach state (c, 2). This is problematic because it allows a product to be shipped but the money has not been transferred to the store. – In contrast, we can see that if we reach state (d, 3) or (e, 3) then the store should be okay – a transfer from the bank must occur • assuming the bank automaton doesn’t “die” which is why it is useful to add arcs for all possible inputs to complete the automaton
  • 10. Simple Example – 1 way door • As an example, consider a one-way automatic door. This door has two pads that can sense when someone is standing on them, a front and rear pad. We want people to walk through the front and toward the rear, but not allow someone to walk the other direction: Front Pad Rear Pad
  • 11. One Way Door • Let’s assign the following codes to our different input cases: a - Nobody on either pad b - Person on front pad c - Person on rear pad d - Person on front and rear pad • We can design the following automaton so that the door doesn’t open if someone is still on the rear pad and hit them: a,c,d Start b C b,c,d O a
  • 12. Formal Definition of a Finite Automaton 1. 2. 3. 4. 5. Finite set of states, typically Q. Alphabet of input symbols, typically ∑ One state is the start/initial state, typically q0 // q0 ∈ Q Zero or more final/accepting states; the set is typically F. // F ⊆ Q A transition function, typically δ. This function • • • • Takes a state and input symbol as arguments. Returns a state. One “rule” would be written δ(q, a) = p, where q and p are states, and a is an input symbol. Intuitively: if the FA is in state q, and input a is received, then the FA goes to state p (note: q = p OK). 1. A FA is represented as the five-tuple: A = (Q, ∑, δ,q0, F). Here, F is a set of accepting states.
  • 13. One Way Door – Formal Notation Using our formal notation, we have: Q = {C, O} (usually we’ll use q0 and q1 instead) F = {} There is no final state q0 = C This is the start state ∑ = {a,b,c,d} The transition function, δ , can be specified by the table: a C C O C b O O c C O c C O Write each δ(state,symbol)? The start state is indicated with the  If there are final accepting states, that is indicated with a * in the proper row.
  • 14. Exercise • Using ∑={0,1} a “clamping” circuit waits for a 1 input, and forever after makes a 1 output regardless of the input. However, to avoid clamping on spurious noise, design a DFA that waits for two 1's in a row, and “clamps” only then. • Write the transition function in table format as well as graph format.
  • 15. Formal Definition of Computation • Let M = (Q, ∑, δ,q0, F) be a finite automaton and let w = w1w2…wn be a string where each wi is a member of alphabet ∑. • M accepts w if a sequence of states r0r1…rn in Q exists with three conditions: 1. r0 = q0 2. δ(ri, wi+1) = ri+1 for i=0, … , n-1 3. rn ∈ F We say that M recognizes language A if A = {w | M accepts w } In other words, the language is all of those strings that are accepted by the finite automata.
  • 16. DFA Example • Here is a DFA for the language that is the set of all strings of 0’s and 1’s whose numbers of 0’s and 1’s are both even: 1 Start q0 q1 1 0 0 0 0 1 q2 q3 1
  • 17. Aside: Type Errors • A major source of confusion when dealing with automata (or mathematics in general) is making “type errors." • Don't confuse A, a FA, i.e., a program, with L(A), which is of type “set of strings." • The start state q0 is of type “state," but the accepting states F is of type “set of states." • a could be a symbol or a could be a string of length 1 depending on the context
  • 18. DFA Exercise • The following figure below is a marble-rolling toy. A marble is dropped at A or B. Levers x1, x2, and x3 cause the marble to fall either to the left or to the right. Whenever a marble encounters a lever, it causes the lever to reverse after the marble passes, so the next marble will take the opposite branch. • Model this game by a finite automaton. Let acceptance correspond to the marble exiting at D. Non-acceptance represents a marble exiting at C.
  • 20. Marble Game Notation • The inputs and outputs (A-D) become the alphabet of the automaton, while the levers indicate the possible states. • If we define the initial status of each lever to be a 0, then if the levers change direction they are in state 1. • Let’s use the format x1x2x3 to indicate a state. The initial state is 000. If we drop a marble down B, then the state becomes to 011 and the marble exits at C. • Since we have three levers that can take on binary values, we have 8 possible states for levers, 000 to 111. • Further identify the states by appending an “a” for acceptance, or “r” for rejection. • This leads to a total of 16 possible states. All we need to do is start from the initial state and draw out the new states we are led to as we get inputs from A or B.
  • 22. Marble DFA – Table Format • Easier to see in table format. Note that not all states are accessible. A B ->000r 100r 011r *000a 100r 011r *001a 101r 000a 010r 110r 001a *010a 110r 001a 011r 111r 010a 100r 010r 111r *100a 010r 111r 101r 011r 100a *101a 011r 100a 110r 000a 101a *110a 000a 101a 111r 001a 110a
  • 23. Regular Operations • Brief intro here – will cover more on regular expressions shortly • In arithmetic, we have arithmetic operations – + * / etc. • For finite automata, we have regular operations – Union – Concatenation – Star
  • 24. Algebra for Languages 1. The union of two languages L and M is the set of strings that are in both L and M. • 2. Example: if L = { 0, 1} and M = {111} then L ∪ M is {0, 1, 111}. The concatenation of languages L and M is the set of strings that can be formed by taking any string in L and concatenating it with any string in M. Concatenation is denoted by LM although sometimes we’ll use L•M (pronounced “dot”). • Example, if L = {0, 1} and M = {ε, 010} then LM is { 0, 1, 0010, 1010}.
  • 25. Algebra for Languages 3. The closure, star, or Kleene star of a language L is denoted L* and represents the set of strings that can be formed by taking any number of strings from L with repetition and concatenating them. It is a unary operator. More specifically, L0 is the set we can make selecting zero strings from L. L 0 is always { ε }. L1 is the language consisting of selecting one string from L. L2 is the language consisting of concatenations selecting two strings from L. … L* is the union of L0, L1, L2, … L∞ For example, if L = {0 , 10} then L0 = { ε }. L1 = {0, 10 } L2 = {00, 010, 100, 1010} L3 = {000, 0010, 0100, 01010, 10010, 1000, 10100, 101010} … and L* is the union of all these sets, up to infinity.
  • 26. Closure Properties of Regular Languages • Closure refers to some operation on a language, resulting in a new language that is of the same “type” as those originally operated on – i.e., regular in our case • We won’t be using the closure properties extensively here; consequently we will state the theorems and give some examples. See the book for proofs of the theorems. • The regular languages are closed under union, concatenation, and *. I.e., if A1 and A2 are regular languages then – A1 ∪ A2 is also regular – A1A2 is also regular – A1* is also regular Later we’ll see easy ways to prove the theorems
  • 27. Nondeterministic Finite Automata • A NFA (nondeterministic finite automata) is able to be in several states at once. – In a DFA, we can only take a transition to a single deterministic state – In a NFA we can accept multiple destination states for the same input. – You can think of this as the NFA “guesses” something about its input and will always follow the proper path if that can lead to an accepting state. – Another way to think of the NFA is that it travels all possible paths, and so it remains in many states at once. As long as at least one of the paths results in an accepting state, the NFA accepts the input. • NFA is a useful tool – More expressive than a DFA. – BUT we will see that it is not more powerful! For any NFA we can construct a corresponding DFA – Another way to think of this is the DFA is how an NFA would actually be implemented (e.g. on a traditional computer)
  • 28. NFA Example • This NFA accepts only those strings that end in 01 0,1 0 q0 Start 1 q1 q0 • Running in “parallel threads” for string 1100101 q0 1 1 q0 0 q0 q1 - stuck 0 q0 q1 q0 1 q2 - stuck 0 q0 q1 q0 q2 - accept 1 q2
  • 29. Formal Definition of an NFA • Similar to a DFA 1. Finite set of states, typically Q. 2. Alphabet of input symbols, typically ∑ 3. One state is the start/initial state, typically q0 4. Zero or more final/accepting states; the set is typically F. 5. A transition function, typically δ . This function: • Takes a state and input symbol as arguments. • Returns a set of states instead of a single state, as a DFA 6. A FA is represented as the five-tuple: A = (Q, ∑, δ ,q0, F). Here, F is a set of accepting states.
  • 30. Previous NFA in Formal Notation The previous NFA could be specified formally as: ({q0,q1,q2}, {0,1}, δ, q0, {q2}) The transition table is: 0  q0 {q0,q1} q1 Ø * q2 Ø 1 {q0} {q2} Ø
  • 31. NFA Example • Practice with the following NFA to satisfy yourself that it accepts ε, a, baba, baa, and aa, but that it doesn’t accept b, bb, and babba. q1 b a q2 a ε a,b q3
  • 32. NFA Exercise • Construct an NFA that will accept strings over alphabet {1, 2, 3} such that the last symbol appears at least twice, but without any intervening higher symbol, in between: – e.g., 11, 2112, 123113, 3212113, etc. • Trick: use start state to mean “I guess I haven't seen the symbol that matches the ending symbol yet.” Use three other states to represent a guess that the matching symbol has been seen, and remembers what that symbol is.
  • 33. NFA Exercise You should be able to generate the transition table
  • 34. Formal Definition of an NFA • Same idea as the DFA • Let N = (Q, ∑, δ,q0, F) be an NFA and let w = w1w2…wn be a string where each wi is a member of alphabet ∑. • N accepts w if a sequence of states r0r1…rn in Q exists with three conditions: 1. r0 = q0 2. ri+1 ∈ δ(ri, wi+1) for i=0, … , n-1 3. rn ∈ F Observe that δ(ri, wi+1) is the set of allowable next states We say that N recognizes language A if A = {w | N accepts w }
  • 35. Equivalence of DFA’s and NFA’s • For most languages, NFA’s are easier to construct than DFA’s • But it turns out we can build a corresponding DFA for any NFA – The downside is there may be up to 2n states in turning a NFA into a DFA. However, for most problems the number of states is approximately equivalent. • Theorem: A language L is accepted by some DFA if and only if L is accepted by some NFA; i.e. : L(DFA) = L(NFA) for an appropriately constructed DFA from an NFA. – Informal Proof: It is trivial to turn a DFA into an NFA (a DFA is already an NFA without nondeterminism). The following slides will show how to construct a DFA from an NFA.
  • 36. NFA to DFA : Subset Construction Let an NFA N be defined as N = (QN, ∑, δ N,q0, FN). The equivalent DFA D = (QD, ∑,δD , {q0 }, FD) where: 1. QD = 2Qn ; i.e. QD is the set of all subsets of QN; that is, it is the power set of QN. Often, not all of these states are accessible from the start state; these states may be “thrown away.” 2. FD is the set of subsets S of QN such that S ∩ FN ≠ Ø. That is, FD is all sets of N’s states that include at least one accepting state of N. 3. For each set S ⊆ QN and for each input symbol a in ∑: δ D ( S , a ) =  δ N ( p, a ) p∈S That is, to compute δD(S, a) we look at all the states p in S, see what states N goes to starting from p on input a, and take the union of all those states.
  • 37. Subset Construction Example (1) 0,1 • Consider the NFA: q0 Start The power set of these states is: { Ø, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2},{q1, q2}, {q0, q1, q2} } New transition function with all of these states and go to the set of possible inputs: 0 1 q1 0 1 Ø Ø Ø  {q0} {q0, q1} {q0} {q1} Ø {q2} *{q2} Ø Ø {q0, q1} {q0, q1} {q0, q2} *{q0, q2} {q0, q1} {q0} *{q1, q2} Ø {q2} *{q0, q1, {q0, q1} {q0, q2} q2
  • 38. Subset Construction (2) • Many states may be unreachable from our start state. A good way to construct the equivalent DFA from an NFA is to start with the start states and construct new states on the fly as we reach them. 0 Ø {q0, q1} {q0, q1} {q0, q1} Ø  {q0} {q0, q1} *{q0, q2} 1 Ø {q0} {q0, q2} {q0} 1 0 Graphically: Start {q0} 0 {q0, q1} 1 1 0 {q0,q2}
  • 39. NFA to DFA Exercises a • Convert the following NFA’s to DFA’s Start q0 a,b b 15 possible states on this second one (might be easier to represent in table format) q1
  • 40. Corollary • A language is regular if and only if some nondeterministic finite automaton recognizes it • A language is regular if and only if some deterministic finite automaton recognizes it
  • 41. Epsilon Transitions • Extension to NFA – a “feature” called epsilon transitions, denoted by ε, the empty string • The ε transition lets us spontaneously take a transition, without receiving an input symbol • Another mechanism that allows our NFA to be in multiple states at once. – Whenever we take an ε edge, we must fork off a new “thread” for the NFA starting in the destination state. • While sometimes convenient, has no more power than a normal NFA – Just as a NFA has no more power than a DFA
  • 42. Formal Notation – Epsilon Transition • Transition function δ is now a function that takes as arguments: – A state in Q and – A member of ∑ ∪ {ε}; that is, an input symbol or the symbol ε. We require that ε not be a symbol of the alphabet ∑ to avoid any confusion.
  • 43. Epsilon NFA Example 0 Start q 1 r ε s ε 0 1 In this ε-NFA, the string “001” is accepted by the path qsrqrs, where the first qs matches 0, sr matches ε, rq matches 0, qr matches 1, and then rs matches ε. In other words, the accepted string is 0ε0ε1ε.
  • 44. Epsilon Closure • Epsilon closure of a state is simply the set of all states we can reach by following the transition function from the given state that are labeled ε. 0 Example: Start q 1 r ε s ε 0 1 • • ε-closure(q) = { q } ε-closure(r) = { r, s}
  • 45. Epsilon NFA Exercise • Exercise: Design an ε-NFA for the language consisting of zero or more a’s followed by zero or more b’s followed by zero or more c’s.
  • 46. Eliminating Epsilon Transitions To eliminate ε-transitions, use the following to convert to a DFA: 1. Compute ε-closure for the current state, resulting in a set of states S. 2. δD(S,a) is computed for all a in Σ by a. Let S = {p1, p2, … pk} k b. Compute  δ ( p , a) and call this set {r1, r2, r3 … rm} i This set is achieved i =1 by following input a, not by following any ε-transitions m c. Add the ε-transitions in by computing δ ( S , a ) =  ε − closure(ri ) i =1 3. Make a state an accepting state if it includes any final states in the ε-NFA. In simple terms: Just like converting a regular NFA to a DFA except follow the epsilon transitions whenever possible after processing an input
  • 48. Epsilon Elimination Exercise • Exercise: Here is the ε-NFA for the language consisting of zero or more a’s followed by zero or more b’s followed by zero or more c’s. • Eliminate the epsilon transitions. a Start q b ε r c ε s