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

Finite Automata

Uploaded by

alibayhya7
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Finite Automata

Uploaded by

alibayhya7
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Contents

Contents
Deterministic Finite Automata
(DFA) Regular Languages
Regular Expressions
Nondeterministic Finite Automata
(NFA) Transformations
Non-Regular Languages
Deterministic Finite Automata (DFA)
Electric bulb

Problem
Design
the logic
behind
an
electric
bulb.
Electric bulb

Problem
Design the logic behind an electric
bulb.
Solution
Diagra
m.

Analysis.
States = {nolight, light}, Input = {off,
on} Finite Automaton.
on

of
f
Automatic doors

Problem
Design the logic behind automatic doors in
Walmart.
Automatic doors
Solution
Diagra
m.

Analysis.
States = {close, open}, Input = {left, right,
neither} Finite Automaton.
neither
left, right left,
right

close open

neither
Basic features of finite automata

A finite automaton is a simple computer with


extremely limited memory
A finite automaton has a finite set of states
Current state of a finite automaton changes when it
reads an input symbol
A finite automaton acts as a language acceptor i.e.,
outputs “yes” or “no”
Why should you care?

Deterministic Finite Automata (DFA) are


everywhere. ATMs
Ticket machines
Vending
machines Traffic
signal systems
Calculators
Digital watches
Automatic
doors
Elevators
Washing machines
Dishwashing
machines
Thermostats
Train switches
(CS)
What is a decision problem?

Definition
A decision problem is a computational problem with
a ‘yes’ or ‘no’ answer.
A computer that solves a decision problem is a
decider. Input to a decider: A string w
Output of a decider: Accept (w is in the language) or
Reject (w is not in the language)
w Decid yes/
er no
What is a decision problem?

English Acce
word pt

Other Rejec
word t

Language = English language = {milk, food, sleep, . . .}


D Accept Not in language = {zffgb, cdcapqw, . . .} D
Reject
How does a DFA work?
Problem
Does the DFA accept the string
bbab?
a
a b b
star q0 q2
t q1 a,
b
How does a DFA work?
Problem
Does the DFA accept the string
bbab?
a a
b
star q0 q2
t qb1 a, b
Solution
The DFA accepts the string bbab. The computation is:
1. Start in state q0
2. Read b, follow transition from q0 to q1.
3. Read b, follow transition from q1 to q1.
4. Read a, follow transition from q1 to q2.
5. Read b, follow transition from q2 to q1.
6. Accept because the DFA is in an accept state q1 at
the end of the input.
How does a DFA work?
Problem
Does the DFA accept the string
aaba?
a
a b b
star q0 q2
t q1 a,
b
How does a DFA work?
Problem
Does the DFA accept the string
aaba?
a a
b
star q0 q2
t qb1 a, b
Solution
The DFA rejects the string aaba. The computation is:
1. Start in state q0
2. Read a, follow transition from q0 to q0.
3. Read a, follow transition from q0 to q0.
4. Read b, follow transition from q0 to q1.
5. Read a, follow transition from q1 to q2.
6. Reject because the DFA is in a reject state q2 at the
end of the input.
How does a DFA work?

a b
a
b
bbab q0 q1 q2 Acce
pt
a,
b

a b
a
b
aaba q0 q1 q2 Rejec
t
a,
b
How does a DFA work?

Problem
What language does the DFA
accept?

a b b
a
start q0 q2
q1 a,
b
How does a DFA work?

Problem
What language does the DFA
accept?
a a
b
start q0 q2
q1 b a, b
Examples
The DFA accepts the following strings:
b, ab, bb, aabbbb, ababababab, . . . D ends
with b baa, abaa, ababaaaaaa, . . . D ends with b followed
by even a’s The DFA rejects the following strings:
a, ba, babaaa, . . .
What language does the DFA accept?
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {ϵ, a, aa, aaa, aaaa, . . .}
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {ϵ, a, aa, aaa, aaaa, . . .}
Solution
Language L: Σ∗ = {ϵ, a, aa, aaa, aaaa, . . .}
Expression: a∗
Deterministic Finite Automaton (DFA) M :
a

start q0
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {}
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {}
Solution
Language L: $ = D Empty
{} language
Expression: $
DFA M : a

start
q0
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {a, aa, aaa, aaaa, . . .}
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {a, aa, aaa, aaaa, . . .}
Solution
Language L: Σ∗ − { ϵ} = {a, aa, aaa, aaaa, . . .}
Expression: a +
DFA M :
a
a
start q0 q1
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {aaa}
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {aaa}
Solution
Language L:
{aaa}
Expression: aaa
DFA M :
a
a

a
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with even size}
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with even size}
Solution
Language L: {ϵ, aa, aaaa, aaaaaa, . . .}
Expression: (aa)∗
DFA M :
a
start q0

q a
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with odd size}
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with odd size}
Solution
Language L: {a, aaa, aaaaa, . . .}
Expression: a(aa)∗
DFA M :
a
start q0

q a
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with size n where n mod 4 = 2}
Construct DFA for Σ = { a }

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with size n where n mod 4 = 2}
Solution
Language L: {aaa, aaaaaaa, aaaaaaaaaaa, . . .}
Expression: aa(aaaa)∗
DFA M :
a a a
start rem 0 rem 1 rem 2 rem
3

a
What about strings with size n where n mod k = i?
Specifying a DFA

The specification of DFA consists of:


A (finite) alphabet
A (finite) set of states
Which state is the start
state? Which states are the
final states?
What is the transition from
each state, on each input
character?
What is a deterministic finite automaton (DFA)?

Deterministic = Events can be determined


precisely Finite = Finite and small amount
of space used Automaton = Computing
machine

Definition
A deterministic finite automaton (DFA) M is
a 5-tuple
M = (Q , Σ, δ, q0, F ), where,
1. Q: A finite set (set of states). D Space
(computer memory)
2. Σ: A finite set (alphabet).
3. δ : Q × Σ → Q is the transition function.
D Time
(comput
ation)
Acceptance and rejection of strings

Definition
A DFA accepts a string w = w1w2 . . . wk iff there
exists a sequence of states r0, r 1 , . . . , r k such that
the current state starts from the start state and
ends at a final state when all the symbols of w have
been read.
A DFA rejects a string iff it does not accept it.
What is a regular language?

Definition
We say that a DFA M accepts a language L if
L = {w | M accepts w}.
A language is called a regular language if some DFA
accepts or recognizes it.
Construct DFA for Σ = {a, b}

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with odd number of b’s}
Construct DFA for Σ = {a, b}

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with odd number of b’s}
Solutio
n
States
qodd: DFA is in this state if it has read odd
b’s. qeven: DFA is in this state if it has read
even b’s.
Construct DFA for Σ = {a, b}

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with odd number of b’s}
Solution
Language L: {strings with odd number
of b’s} Expression: a∗b(a ∪ ba∗b)∗ or
a∗ba∗(ba∗ba∗)∗ DFA M : a a
b

star
qeve qodd
t n b
Construct DFA for Σ = {a, b}

Problem
Construct a DFA that accepts all strings from the
language
L = {strings with odd number of b’s}
Solution (continued)
DFA M is specified
as
Set of states is Q = {qeven,
qodd} Set of symbols is Σ =
{a, b} Start state is qeven a b
Set of accept states qis F =qeven
even qodd

{qodd} qodd qodd qeven

Transition function δ is:


δ
Construct DFA for Σ = {a, b}

Problem
Construct a DFA that accepts all strings from the
language
L = {strings containing bab}
Construct DFA for Σ = {a, b}

Problem
Construct a DFA that accepts all strings from the
language
L = {strings containing bab}
Solutio
n
States
qb: DFA is in this state if the last symbol read was b,
but the substring bab has not been read.
qba: DFA is in this state if the last two symbols read
were ba, but the substring bab has not been read.
qbab: DFA is in this state if the substring bab has been
read in the input string.
q: In all other cases, the DFA is in this state.
Construct DFA for Σ = {a, b}

Problem
Construct a DFA that accepts all strings from the
language
L = {strings containing bab}
Solution (continued)
Language L: {strings containing
bab} Expression: (a∗b+aa)∗bab(a
∪ b)∗ DFA M : a,
a
b
b b a b
start q qb qba qbab

a
Construct DFA for Σ = {a, b}

Problem
Construct a DFA that accepts all strings from the
language
L = {strings containing bab}
Solution (continued)
DFA M is specified
as
Set of states is Q =
{q, qb, qba, qbab}
Transition function δ is:
Set of symbols is Σ δ a b
= {a, b} q q qb
Start state is q qb qba qb
Set of accept states qba q qbab
is F = {qbab} qbab qbab qbab
Equivalence of different computation models

Two machines or computational models are


computationally equivalent if they accept/recognize
the same language.
The following models are computationally
equivalent: DFA, regular expressions, NFA, and
regular grammars.

DFA

Regular Regular Regula


expressio Languag r
ns es gramm
ar

NFA

You might also like