0% found this document useful (0 votes)
19 views58 pages

1 Dfa

The document provides an introduction to Deterministic Finite Automata (DFA) as part of a theoretical computer science course. It covers key concepts such as the structure of a DFA, transition functions, and examples of languages accepted by DFAs. Additionally, it discusses the formal definition of DFAs and illustrates how to design DFAs for specific languages.

Uploaded by

Alena Croft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views58 pages

1 Dfa

The document provides an introduction to Deterministic Finite Automata (DFA) as part of a theoretical computer science course. It covers key concepts such as the structure of a DFA, transition functions, and examples of languages accepted by DFAs. Additionally, it discusses the formal definition of DFAs and illustrates how to design DFAs for specific languages.

Uploaded by

Alena Croft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

COMP 335: Introduction to

Theoretical Computer Science

Deterministic
Finite Automata
(DFA)

The content on this video was originally provided by Dr. Shiri,


and modified by Drs. Pankratov and Narayanan.
Previous video
• Why study theoretical CS?
• Math preliminaries:
• Sets
• Functions
• Relations
• Graphs
• Proofs
• Languages
Automaton (singular) / Automata (plural)

From Wikipedia:
An automaton is a self-operating machine, or a
machine or control mechanism designed to
automatically follow a predetermined sequence of
operations, or respond to predetermined instructions.
Finite Automaton

Input tape
String

Output
Finite String
Automaton
Finite Accepter

Input
String
Output
“Accept”
Finite
or
Automaton
“Reject”
Transition Graph/Diagram for a DFA
Input string: abba a, b

q5
a a, b
b a b accept state: double
q0 a q1 b q2 b q3 a q4 circle

initial final/accept
state state
transition
state
Initial Configuration
Input String
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Reading the Input

a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Input finished

a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4 Final state
Input finished AND Final state
è
Output: “accept”
a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Rejection

a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Input finished

a b a

a, b
Non-final state
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Input finished AND Non-Final state
è Output: “reject”

a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Another input here the input is lambda

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
a, b
Output:
“reject” q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Does the following DFA accept the input
string aab? accepted

a a b

a a, b

q0 b q1 a, b q2
a a b

a a, b

q0 b q1 a, b q2
a a b

a a, b

q0 b q1 a, b q2
Input finished

a a b

a a, b
Output: “accept”

q0 b q1 a, b q2
Does M accept the string bab?

b a b

a a, b

q0 b q1 a, b q2
b a b

a a, b

q0 b q1 a, b q2
b a b

a a, b

q0 b q1 a, b q2
Input finished

b a b

a a, b
Output: “reject” trap state.
a state which is not a final
state and from which it can
q0 b q1 a, b q2 not escape
Formal definition of DFA 𝑀 = (𝑄, Σ, 𝛿, 𝑞) , 𝐹)
deterministic machine:
Deterministic Finite Accepter/Automaton 𝑀 : for each node there should be
an outgoing arrow for each
• 𝑄 : States (a finite set of states) alphabets. But should not be 2
arrows for single alphabet.
• Σ : Alphabet (a finite set of input symbols)
• 𝛿 : Transition function (𝛿: 𝑄×Σ → 𝑄)
• 𝑞) : Initial state (an element of 𝑄)
• 𝐹 : Final states (a subset of 𝑄)
Input Alphabet Σ

Σ = {𝑎, 𝑏}
a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
Set of States 𝑄 infinity > |Q| >= 1

𝑄 = {𝑞) , 𝑞3 , 𝑞4 , 𝑞5 , 𝑞6 , 𝑞7 }
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Initial State 𝑞)

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Final State(s) 𝐹

𝐹 = {𝑞6 } a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Transition Function 𝛿

𝛿: 𝑄×Σ → 𝑄
a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

COMP 335 33
𝛿 𝑞) , 𝑎 = 𝑞3

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
𝛿 𝑞) , 𝑏 = 𝑞7

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
d (q2 , b ) = q3

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
Transition Function 𝛿

d a b
q0 q1 q5
q1 q5 q2 a, b
q2 q5 q3
q3 q4 q5 q5
q4 q5 q5 b a a, b
a b
q5 q5 q5 q0 a q1 b q2 b q3 a q4
∗ ∗
Extended Transition Function 𝛿 : 𝑄×Σ → 𝑄
Informal definition: 𝛿 ∗ (q, w) is the state in which the DFA is, after
it processes string w, starting from state q.
a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
d * (q0 , ab ) = q2
shai star (q1 , abba) = q4

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
d * (q0 , abba ) = q4

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
shai * (q2 , ba) = q4

d * (q0 , abbbaa ) = q5

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
Observation: there is a walk from 𝑞 to 𝑞′ with label 𝑤
if and only if understanding this is very
𝛿 ∗ 𝑞, 𝑤 = 𝑞′ enough, recursive defn is just
formality

q w q¢

𝑤 = 𝜎3 𝜎4 … 𝜎A
s1 s2 sk
q q¢
Example: there is a walk from 𝑞) to 𝑞7 with label 𝑎𝑏𝑏𝑏𝑎𝑎

𝛿 ∗ 𝑞) , 𝑎𝑏𝑏𝑏𝑎𝑎 = 𝑞7

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
Recursive Definition
𝛿 ∗ 𝑞, 𝜆 = 𝑞 base case
𝛿 ∗ 𝑞, 𝑤𝜎 = 𝛿 𝛿 ∗ 𝑞, 𝑤 , 𝜎

q w q1 s q¢

𝛿 ∗ 𝑞, 𝑤 = 𝑞3 𝛿 𝑞3 , 𝜎 = 𝑞′

𝛿 ∗ 𝑞, 𝑤𝜎 = 𝑞′
𝛿 ∗ 𝑞) , 𝑎𝑏 =
𝛿 𝛿 ∗ 𝑞) , 𝑎 , 𝑏 =
𝛿 𝛿 𝛿 ∗ 𝑞) , 𝜆 , 𝑎 , 𝑏 =
𝛿 𝛿 𝑞) , 𝑎 , 𝑏 =
𝛿 𝑞3 , 𝑏 =
a, b 𝑞4

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
Languages Accepted by DFAs
The language accepted by a DFA 𝑀 is denoted L(M) and is the set of all
strings accepted by 𝑀. every string that is not here, is rejected
2 conditions: 1) accept what is here, 2) reject what is not
𝐿 𝑀 is the set of all strings that drive M to a Tinal state.

Formally, given a DFA 𝑀 = 𝑄, Σ, 𝛿, 𝑞) , 𝐹

𝐿 𝑀 = 𝑤 ∈ Σ ∗ ∶ 𝛿 ∗ 𝑞) , 𝑤 ∈ 𝐹

only accepts 1 language


Example: 𝐿 𝑀 = 𝑎𝑏𝑏𝑎

a, b

q5 trap state
b a a , b
a b
q0 a q1 b q2 b q3 a q 4
accept
Another Example 𝐿 𝑀 = {𝜆, 𝑎𝑏, 𝑎𝑏𝑏𝑎}

a, b

q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4
accept accept accept
Consider the DFA M given below.
What is L(M)? = { a^n b : n>=0}
Q: if L1 = {a^2n b : n>= 0}
does M accepts L1?
NO, because it does not reject L1(compliment)
a a, b

q0 b q1 a, b q2

accept trap state


Design a DFA 𝑀 that accepts all strings on
the alphabet {a, b} that start with ab.
a, b

q0 a q1 b q2

b a accept
dfa can not do infinity
q3 a, b memory, but can do finite
memory
Design a DFA M such that:
L(M) = 𝑤 ∶ 𝑤 contains the substring 001

to accept the compliment: accept the non accepted states and do not accept the accepted
states
Design a DFA M such that:
L(M) = 𝑤 ∶ 𝑤 does not contain the substring 001

1 0 0,1
1

l 0 1
0 00 001

0
Regular Languages
Definition: A language 𝐿 is regular if there is a DFA 𝑀 that accepts 𝐿:

𝐿 = 𝐿(𝑀)

The set of all regular languages forms a family of languages.

To show that a language L is regular, it is enough to design a DFA that


accepts L.
Examples of Regular Languages
• 𝑎𝑏𝑏𝑎
• {𝜆, 𝑎𝑏, 𝑎𝑏𝑏𝑎}
• {𝑎` 𝑏 ∶ 𝑛 ≥ 0}
• Set of all strings with preTix 𝑎𝑏
• {w: w = vab for some string v }
• 𝑤: 𝑤 does not contain the substring 001

For each of the above languages we can design a DFA that accepts it.

Show that the language 𝐿 = 𝑎𝑤𝑎 ∶ 𝑤 ∈ 𝑎, 𝑏 is regular.
in this kind of question, we need to design a DFA.

a a
There are languages that are not regular.
Example: 𝐿 = {𝑎` 𝑏 ` ∶ 𝑛 ≥ 0}

As we will learn later, there is no DFA for this and (infinitely) many
other languages.
Review questions
• What is a Deterministic Finite Automaton (DFA)?

• When do we say a string w is accepted by a DFA M?

• What is the language accepted by a given DFA M?

• What is a regular language?


You should now be able to…
• Given a DFA M, and a string w:
say whether M accepts w , or if M rejects w.

• Given a DFA M, describe L(M).

• Given a regular language L, design a DFA that accepts L.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy