0% found this document useful (0 votes)
72 views54 pages

4 Dfa

Uploaded by

Ramya Samala
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)
72 views54 pages

4 Dfa

Uploaded by

Ramya Samala
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/ 54

Finite Automata

Ziwen Pan
Email: [email protected]
Basic model for machines

 An automatic door opens in one direction


Basic model for machines

 An automatic door opens in one direction


-- Open to let people in
-- Do not knock people on the opening side

How to design a machine fulfilling the function?


Basic model for machines

 An automatic door opens in one direction


-- Check front people: Yes/No
-- Check rear people: Yes/No
-- Check current status: Open/Close
-- Determine the next status: Open/Close
Basic model for machines

 An automatic door opens in one direction


-- Check front people: Yes/No
-- Check rear people: Yes/No
-- Check current status: Open/Close
-- Determine the next status: Open/Close
Basic model for machines

 An automatic door opens in one direction


Finite Automata -- informal

 An automatic door opens in one direction

State Diagram
Finite Automata -- informal

 An automatic door opens in one direction

Two states: Open/Closed


Finite Automata -- informal

 An automatic door opens in one direction

Start states: Closed


Finite Automata -- informal

 An automatic door opens in one direction

Transitions: arrows that bring


the machine from one state to
another
Finite Automata -- informal

 An automatic door opens in one direction

Accept state/final state: state


with a double cycle

We want to restrict our attention to a simplified scenario


where machines are used to ”compute”Yes/No
Finite Automata -- informal

 Example

Start states Final/Accept states


Finite Automata -- informal

 Example

What happens when we input 1101?


Finite Automata -- informal

 Example

What happens when we input 1101?


Finite Automata -- informal

 Example

What happens when we input 1101?


Finite Automata -- informal

 Example

What happens when we input 1101?


Finite Automata -- informal

 Example

What happens when we input 1101?


Finite Automata -- informal

 Example

What happens when we input 1101?

Machines ends at an accept state, i.e., machine output: Yes


Finite Automata -- informal

 Example

What happens when we input 1101?

Machines ends at an accept state, i.e., machine output: Yes

What happens when we input 101000?


Deterministic Finite Automata -- Formal

 A quintuple 𝑀 = (𝑄, Σ, 𝛿, 𝑞0 , 𝐹) where


- 𝑄 is a finite set of states
- Σ is an alphabet
- q0 ∈ 𝑄 is the initial state
- 𝐹 ⊆ 𝑄 is the set of final/accept states (can be multiple)

- 𝛿, the transition function, a function from Q × Σ to 𝑄


Deterministic Finite Automata

 Example
Deterministic Finite Automata

 A deterministic finite automaton 𝑀 can be viewed as a classifier that filters out all the
strings it accepts
-- The set 𝐴 of all the strings 𝑀 accepts is the language of machine 𝑀
-- Denote as 𝐿 𝑀 = 𝐴
-- 𝑀 recognizes/accepts 𝐴
Deterministic Finite Automata

 A deterministic finite automaton 𝑀 can be viewed as a classifier that filters out all the
strings it accepts
-- The set 𝐴 of all the strings 𝑀 accepts is the language of machine 𝑀
-- Denote as 𝐿 𝑀 = 𝐴
-- 𝑀 recognizes/accepts 𝐴

0,1

What if 𝑀 rejects all inputs? 𝑀 accepts ∅


0,1
𝑞0 𝑞1
DFA Examples

𝑏 𝑏 𝑏 𝑎, 𝑏
• 𝑄 = {𝑞 0 , 𝑞1, 𝑞2, 𝑞 3 }
𝑎 𝑎 𝑎
• Σ = {𝑎, 𝑏 } 𝑞0 𝑞1 𝑞2 𝑞3
• 𝛿=
{((𝑞0 , 𝑎), 𝑞1), ((𝑞0, 𝑏), 𝑞0), ((𝑞1, 𝑎), 𝑞2), ((𝑞1, 𝑏), 𝑞1),
((𝑞2, 𝑎), 𝑞3), ((𝑞2, 𝑏), 𝑞2), ((𝑞3, 𝑎), 𝑞3), ((𝑞3, 𝑏), 𝑞 3 )}
• start state = 𝑞0
• 𝐹 = {𝑞 2 }
DFA Configurations

 Deterministic finite automata are


- Deterministic: given the current state and next input symbol, it moves
deterministically to a next state.
DFA Configurations

 Deterministic finite automata are


- Deterministic: given the current state and next input symbol, it moves
deterministically to a next state.
- Finite: consists of finite number of states
- Automata: machine
DFA Configurations

 We have learned two ways of describing a DFA


- A quintuple 𝑀 = (𝑄, Σ, 𝛿, 𝑞0 , 𝐹)
- A state diagram
 How do we characterize the computation of a DFA?
DFA Configurations

 We have learned two ways of describing a DFA


- A quintuple 𝑀 = (𝑄, Σ, 𝛿, 𝑞0 , 𝐹)
- A state diagram
 How do we characterize the computation of a DFA?
- the computation of a DFA has to be defined on a specific input
- use a sequence of configurations to represent the computation
DFA Configurations

 Configuration for a DFA 𝑀 = (𝐾, Σ, 𝛿, 𝑠, 𝐹)


- any element of 𝐾 × Σ ∗
- the state the DFA currently in
- the remaining part of the string to be processed
DFA Configurations

 Configuration for a DFA 𝑀 = (𝐾, Σ, 𝛿, 𝑠, 𝐹)


- any element of 𝐾 × Σ ∗
- the state the DFA currently in
- the remaining part of the string to be processed

Input string: 𝑎𝑎𝑏𝑏𝑎


DFA Configurations

 We use a binary relation ⊢ M to denote that DFA pass from one state to
another state as a result of a single move
 ⊢ M is a function from 𝐾 × Σ + to 𝐾 × Σ ∗ (L+ = 𝐿𝐿∗ )

Input string: 𝑎𝑎𝑏𝑏𝑎


DFA Configurations
0 1

1 1 1
𝑞0 𝑞1 𝑞2 𝑞3
0 0 0

(q0, 11101) ⊢ M (q1, 1101)


⊢ M (q2, 101)
⊢ M (q3, 01)
⊢ M (q0, 1)
⊢ M (q1, e)
(q0, 11101) ⊢∗𝑀(q1, e) ⊢∗𝑀 : yields in 0 or more steps
DFA Configurations
0 1

1 1 1
𝑞0 𝑞1 𝑞2 𝑞3
0 0 0

(q0, 10111) ⊢ M (q1, 0111)


⊢M (q0, 111)
⊢M (q1, 11)
⊢M (q2, 1)
⊢M (q3, e)
(q0, 10111) ⊢∗𝑀(q3, e) ⊢∗𝑀 : yields in 0 or more steps
Regular language

 𝑀 accepts a string 𝑤 if (𝑞0 , 𝑤) ⊢∗𝑀 (𝑞,𝑒) for some 𝑞 ∈ 𝐹


 𝑀 recognize language 𝐴 if 𝐴 = {𝑤: 𝑀 accepts 𝑤}
 A language is regular if some finite automaton recognizes it.
DFA –> regular language

 All binary strings containing an odd number of 1s


DFA –> regular language

 Example Deterministic Finite Automaton


- All strings over {𝑎, 𝑏} that have length 3.
𝑎, 𝑏

𝑎, 𝑏 𝑎, 𝑏 𝑎, 𝑏 𝑎, 𝑏
𝑞0 𝑞1 𝑞2 𝑞3 𝑞4
DFA –> regular language

 All strings over {0, 1} that contain the substring 101


DFA –> regular language

 All strings over {𝑎, 𝑏} that does not contain three consecutive 𝑏’s
DFA Examples

 All strings over {𝑎, 𝑏} that contains three consecutive 𝑏’s

𝑎
Regular language

 So far we have learned: given an automaton, determine the language it


accepts
 Given a regular language, can we design an automaton recognizing it?
Regular language -> DFA

 All strings consisting of {0,1} and have an odd number of 1s.


Regular language -> DFA

 All strings consisting of {0,1} and have an odd number of 1s.


-- how would you design an algorithm achieving this?
1. read every symbol and check if it is 1;
2. set up a counter, counter -> counter +1 if the symbol is 1;
3. check odd/even of the counter
Regular language -> DFA

 All strings consisting of {0,1} and have an odd number of 1s.


-- how would you design an algorithm achieving this?
1. read every symbol and check if it is 1;
2. set up a counter, counter -> counter +1 if the symbol is 1;
3. check odd/even of the counter

Can we do better without memory?


Regular language -> DFA

 All strings consisting of {0,1} and have an odd number of 1s.


-- how would you design an algorithm achieving this?
1. read every symbol and check if it is 1;
2. set up a counter, counter -> counter +1 if the symbol is 1;
3. check odd/even of the counter

Identify states
Regular language -> DFA

 All strings consisting of {0,1} and have an odd number of 1s.


-- how would you design an algorithm achieving this?
1. read every symbol and check if it is 1;
2. set up a counter, counter -> counter +1 if the symbol is 1;
3. check odd/even of the counter

Identify transitions
Regular language -> DFA

 All strings consisting of {0,1} and have an odd number of 1s.


-- how would you design an algorithm achieving this?
1. read every symbol and check if it is 1;
2. set up a counter, counter -> counter +1 if the symbol is 1;
3. check odd/even of the counter

Identify start and final states


Regular language -> DFA

 All strings consisting of {0,1} and have 001 as a substring.

Identify states: what are the states?


Regular language -> DFA

 All strings consisting of {0,1} and have 001 as a substring.

Identify states: what are the states?

𝑞 𝑞0 𝑞00 𝑞001
Regular language -> DFA

 All strings consisting of {0,1} and have 001 as a substring.

Start and final states?

𝑞 𝑞0 𝑞00 𝑞001
Regular language -> DFA

 All strings consisting of {0,1} and have 001 as a substring.

Transitions
Regular operations

 How to design DFA for very complicated regular language? Is there a


systematic way (or “Algorithm”or designing DFA)?
Regular operations
Regular operations

𝐴 = good, bad , 𝐵 = {boy, girl}


Regular operations

 How to design DFA for very complicated regular language? Is there a


systematic way (or “Algorithm”or designing DFA)?
 Regular language is closed under union, concatenation and star, but how can
we prove it?

You might also like