deterministic finite automata (dfas) · deterministic finite automata (dfas) lecture 3 september 4,...

77
CS/ECE 374: Algorithms & Models of Computation, Fall 2018 Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1 / 32

Upload: others

Post on 07-Sep-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

CS/ECE 374: Algorithms & Models of

Computation, Fall 2018

Deterministic FiniteAutomata (DFAs)Lecture 3September 4, 2018

Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1 / 32

Page 2: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Part I

DFA Introduction

Nikita Borisov (UIUC) CS/ECE 374 2 Fall 2018 2 / 32

Page 3: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFAs also called Finite State Machines (FSMs)

The “simplest” model for computers?

State machines that are very common in practice.

Vending machinesElevatorsDigital watchesSimple network protocols

Programs with fixed memory

Nikita Borisov (UIUC) CS/ECE 374 3 Fall 2018 3 / 32

Page 4: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

A simple program

Program to check if a given input string w has odd length

int n = 0While input is not finished

read next character cn ← n + 1

endWhile

If (n is odd) output YES

Else output NO

bit x = 0While input is not finished

read next character cx ← flip(x)

endWhile

If (x = 1) output YES

Else output NO

Nikita Borisov (UIUC) CS/ECE 374 4 Fall 2018 4 / 32

Page 5: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

A simple program

Program to check if a given input string w has odd length

int n = 0While input is not finished

read next character cn ← n + 1

endWhile

If (n is odd) output YES

Else output NO

bit x = 0While input is not finished

read next character cx ← flip(x)

endWhile

If (x = 1) output YES

Else output NO

Nikita Borisov (UIUC) CS/ECE 374 4 Fall 2018 4 / 32

Page 6: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Another view

Machine has input written on a read-only tape

Start in specified start state

Start at left, scan symbol, change state and move right

Circled states are accepting

Machine accepts input string if it is in an accepting state afterscanning the last symbol.

Nikita Borisov (UIUC) CS/ECE 374 5 Fall 2018 5 / 32

Page 7: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Graphical Representation/State Machine

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Directed graph with nodes representing states and edge/arcsrepresenting transitions labeled by symbols in Σ

For each state (vertex) q and symbol a ∈ Σ there is exactly oneoutgoing edge labeled by aInitial/start state has a pointer (or labeled as s, q0 or “start”)

Some states with double circles labeled as accepting/final states

Nikita Borisov (UIUC) CS/ECE 374 6 Fall 2018 6 / 32

Page 8: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Graphical Representation

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Convention: Machine reads symbols from left to right

Where does 001 lead? 10010?

Which strings end up in accepting state?

Every string w has a unique walk that it follows from a givenstate q by reading one letter of w from left to right.

Nikita Borisov (UIUC) CS/ECE 374 7 Fall 2018 7 / 32

Page 9: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Graphical Representation

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Convention: Machine reads symbols from left to right

Where does 001 lead? 10010?

Which strings end up in accepting state?

Every string w has a unique walk that it follows from a givenstate q by reading one letter of w from left to right.

Nikita Borisov (UIUC) CS/ECE 374 7 Fall 2018 7 / 32

Page 10: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Graphical Representation

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Convention: Machine reads symbols from left to right

Where does 001 lead? 10010?

Which strings end up in accepting state?

Every string w has a unique walk that it follows from a givenstate q by reading one letter of w from left to right.

Nikita Borisov (UIUC) CS/ECE 374 7 Fall 2018 7 / 32

Page 11: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Graphical Representation

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

DefinitionA DFA M accepts a string w iff the unique walk starting at the startstate and spelling out w ends in an accepting state.

DefinitionThe language accepted (or recognized) by a DFA M is denote byL(M) and defined as: L(M) = {w | M accepts w}.

Nikita Borisov (UIUC) CS/ECE 374 8 Fall 2018 8 / 32

Page 12: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Graphical Representation

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

DefinitionA DFA M accepts a string w iff the unique walk starting at the startstate and spelling out w ends in an accepting state.

DefinitionThe language accepted (or recognized) by a DFA M is denote byL(M) and defined as: L(M) = {w | M accepts w}.

Nikita Borisov (UIUC) CS/ECE 374 8 Fall 2018 8 / 32

Page 13: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Warning

“M accepts language L” does not mean simply that that M acceptseach string in L.

It means that M accepts each string in L and no others. EquivalentlyM accepts each string in L and does not accept/rejects strings inΣ∗ \ L.

M “recognizes” L is a better term but “accepts” is widely accepted(and recognized) (joke attributed to Lenny Pitt)

Nikita Borisov (UIUC) CS/ECE 374 9 Fall 2018 9 / 32

Page 14: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Warning

“M accepts language L” does not mean simply that that M acceptseach string in L.

It means that M accepts each string in L and no others. EquivalentlyM accepts each string in L and does not accept/rejects strings inΣ∗ \ L.

M “recognizes” L is a better term but “accepts” is widely accepted(and recognized) (joke attributed to Lenny Pitt)

Nikita Borisov (UIUC) CS/ECE 374 9 Fall 2018 9 / 32

Page 15: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal Tuple Notation

DefinitionA deterministic finite automata (DFA) M = (Q,Σ, δ, s,A) is a fivetuple where

Q is a finite set whose elements are called states,

Σ is a finite set called the input alphabet,

δ : Q × Σ→ Q is the transition function,

s ∈ Q is the start state,

A ⊆ Q is the set of accepting/final states.

Common alternate notation: q0 for start state, F for final states.

Nikita Borisov (UIUC) CS/ECE 374 10 Fall 2018 10 / 32

Page 16: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal Tuple Notation

DefinitionA deterministic finite automata (DFA) M = (Q,Σ, δ, s,A) is a fivetuple where

Q is a finite set whose elements are called states,

Σ is a finite set called the input alphabet,

δ : Q × Σ→ Q is the transition function,

s ∈ Q is the start state,

A ⊆ Q is the set of accepting/final states.

Common alternate notation: q0 for start state, F for final states.

Nikita Borisov (UIUC) CS/ECE 374 10 Fall 2018 10 / 32

Page 17: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal Tuple Notation

DefinitionA deterministic finite automata (DFA) M = (Q,Σ, δ, s,A) is a fivetuple where

Q is a finite set whose elements are called states,

Σ is a finite set called the input alphabet,

δ : Q × Σ→ Q is the transition function,

s ∈ Q is the start state,

A ⊆ Q is the set of accepting/final states.

Common alternate notation: q0 for start state, F for final states.

Nikita Borisov (UIUC) CS/ECE 374 10 Fall 2018 10 / 32

Page 18: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal Tuple Notation

DefinitionA deterministic finite automata (DFA) M = (Q,Σ, δ, s,A) is a fivetuple where

Q is a finite set whose elements are called states,

Σ is a finite set called the input alphabet,

δ : Q × Σ→ Q is the transition function,

s ∈ Q is the start state,

A ⊆ Q is the set of accepting/final states.

Common alternate notation: q0 for start state, F for final states.

Nikita Borisov (UIUC) CS/ECE 374 10 Fall 2018 10 / 32

Page 19: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal Tuple Notation

DefinitionA deterministic finite automata (DFA) M = (Q,Σ, δ, s,A) is a fivetuple where

Q is a finite set whose elements are called states,

Σ is a finite set called the input alphabet,

δ : Q × Σ→ Q is the transition function,

s ∈ Q is the start state,

A ⊆ Q is the set of accepting/final states.

Common alternate notation: q0 for start state, F for final states.

Nikita Borisov (UIUC) CS/ECE 374 10 Fall 2018 10 / 32

Page 20: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal Tuple Notation

DefinitionA deterministic finite automata (DFA) M = (Q,Σ, δ, s,A) is a fivetuple where

Q is a finite set whose elements are called states,

Σ is a finite set called the input alphabet,

δ : Q × Σ→ Q is the transition function,

s ∈ Q is the start state,

A ⊆ Q is the set of accepting/final states.

Common alternate notation: q0 for start state, F for final states.

Nikita Borisov (UIUC) CS/ECE 374 10 Fall 2018 10 / 32

Page 21: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal Tuple Notation

DefinitionA deterministic finite automata (DFA) M = (Q,Σ, δ, s,A) is a fivetuple where

Q is a finite set whose elements are called states,

Σ is a finite set called the input alphabet,

δ : Q × Σ→ Q is the transition function,

s ∈ Q is the start state,

A ⊆ Q is the set of accepting/final states.

Common alternate notation: q0 for start state, F for final states.

Nikita Borisov (UIUC) CS/ECE 374 10 Fall 2018 10 / 32

Page 22: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal Tuple Notation

DefinitionA deterministic finite automata (DFA) M = (Q,Σ, δ, s,A) is a fivetuple where

Q is a finite set whose elements are called states,

Σ is a finite set called the input alphabet,

δ : Q × Σ→ Q is the transition function,

s ∈ Q is the start state,

A ⊆ Q is the set of accepting/final states.

Common alternate notation: q0 for start state, F for final states.

Nikita Borisov (UIUC) CS/ECE 374 10 Fall 2018 10 / 32

Page 23: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q =

{q0, q1, q1, q3}Σ = {0, 1}δ

s = q0

A = {q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 24: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q = {q0, q1, q1, q3}

Σ = {0, 1}δ

s = q0

A = {q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 25: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q = {q0, q1, q1, q3}Σ =

{0, 1}δ

s = q0

A = {q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 26: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q = {q0, q1, q1, q3}Σ = {0, 1}

δ

s = q0

A = {q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 27: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q = {q0, q1, q1, q3}Σ = {0, 1}δ

s = q0

A = {q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 28: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q = {q0, q1, q1, q3}Σ = {0, 1}δ

s =

q0

A = {q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 29: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q = {q0, q1, q1, q3}Σ = {0, 1}δ

s = q0

A = {q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 30: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q = {q0, q1, q1, q3}Σ = {0, 1}δ

s = q0

A =

{q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 31: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Q = {q0, q1, q1, q3}Σ = {0, 1}δ

s = q0

A = {q0}

Nikita Borisov (UIUC) CS/ECE 374 11 Fall 2018 11 / 32

Page 32: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Extending the transition function to strings

Given DFA M = (Q,Σ, δ, s,A), δ(q, a) is the state that M goesto from q on reading letter a

Useful to have notation to specify the unique state that M will reachfrom q on reading string w

Transition function δ∗ : Q × Σ∗ → Q defined inductively asfollows:

δ∗(q,w) = q if w = ε

δ∗(q,w) = δ∗(δ(q, a), x) if w = ax .

Nikita Borisov (UIUC) CS/ECE 374 12 Fall 2018 12 / 32

Page 33: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Extending the transition function to strings

Given DFA M = (Q,Σ, δ, s,A), δ(q, a) is the state that M goesto from q on reading letter a

Useful to have notation to specify the unique state that M will reachfrom q on reading string w

Transition function δ∗ : Q × Σ∗ → Q defined inductively asfollows:

δ∗(q,w) = q if w = ε

δ∗(q,w) = δ∗(δ(q, a), x) if w = ax .

Nikita Borisov (UIUC) CS/ECE 374 12 Fall 2018 12 / 32

Page 34: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Formal definition of language accepted by M

DefinitionThe language L(M) accepted by a DFA M = (Q,Σ, δ, s,A) is

{w ∈ Σ∗ | δ∗(s,w) ∈ A}.

Nikita Borisov (UIUC) CS/ECE 374 13 Fall 2018 13 / 32

Page 35: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

What is:

δ∗(q1, ε)

δ∗(q0, 1011)

δ∗(q1, 010)

δ∗(q4, 10)

Nikita Borisov (UIUC) CS/ECE 374 14 Fall 2018 14 / 32

Page 36: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example continued

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

What is L(M) if start state is changed to q1?

What is L(M) if final/accepting states are set to {q2, q3}instead of {q0}?

Nikita Borisov (UIUC) CS/ECE 374 15 Fall 2018 15 / 32

Page 37: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Advantages of formal specification

Necessary for proofs

Necessary to specify abstractly for class of languages

Exercise: Prove by induction that for any two strings u, v , and anystate q,

δ∗(q, uv) = δ∗(δ∗(q, u), v)

.

Nikita Borisov (UIUC) CS/ECE 374 16 Fall 2018 16 / 32

Page 38: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Part II

Constructing DFAs

Nikita Borisov (UIUC) CS/ECE 374 17 Fall 2018 17 / 32

Page 39: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFAs: State = Memory

How do we design a DFA M for a given language L? That isL(M) = L.

DFA is a like a program that has fixed amount of memoryindependent of input size.

The memory of a DFA is encoded in its states

The state/memory must capture enough information from theinput seen so far that it is sufficient for the suffix that is yet tobe seen (note that DFA cannot go back)

Nikita Borisov (UIUC) CS/ECE 374 18 Fall 2018 18 / 32

Page 40: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFA Construction: Example

Assume Σ = {0, 1}L = ∅, L = Σ∗, L = {ε}, L = {0}.

L = {w ∈ {0, 1}∗ | |w | is divisible by 5}L = {w ∈ {0, 1}∗ | w ends with 01}L = {w ∈ {0, 1}∗ | w contains 001 as substring}L = {w ∈ {0, 1}∗ | w contains 001 or 010 as substring}L = {w | w has a 1 k positions from the end}

Nikita Borisov (UIUC) CS/ECE 374 19 Fall 2018 19 / 32

Page 41: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFA Construction: Example

Assume Σ = {0, 1}L = ∅, L = Σ∗, L = {ε}, L = {0}.L = {w ∈ {0, 1}∗ | |w | is divisible by 5}

L = {w ∈ {0, 1}∗ | w ends with 01}L = {w ∈ {0, 1}∗ | w contains 001 as substring}L = {w ∈ {0, 1}∗ | w contains 001 or 010 as substring}L = {w | w has a 1 k positions from the end}

Nikita Borisov (UIUC) CS/ECE 374 19 Fall 2018 19 / 32

Page 42: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFA Construction: Example

Assume Σ = {0, 1}L = ∅, L = Σ∗, L = {ε}, L = {0}.L = {w ∈ {0, 1}∗ | |w | is divisible by 5}L = {w ∈ {0, 1}∗ | w ends with 01}

L = {w ∈ {0, 1}∗ | w contains 001 as substring}L = {w ∈ {0, 1}∗ | w contains 001 or 010 as substring}L = {w | w has a 1 k positions from the end}

Nikita Borisov (UIUC) CS/ECE 374 19 Fall 2018 19 / 32

Page 43: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFA Construction: Example

Assume Σ = {0, 1}L = ∅, L = Σ∗, L = {ε}, L = {0}.L = {w ∈ {0, 1}∗ | |w | is divisible by 5}L = {w ∈ {0, 1}∗ | w ends with 01}L = {w ∈ {0, 1}∗ | w contains 001 as substring}

L = {w ∈ {0, 1}∗ | w contains 001 or 010 as substring}L = {w | w has a 1 k positions from the end}

Nikita Borisov (UIUC) CS/ECE 374 19 Fall 2018 19 / 32

Page 44: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFA Construction: Example

Assume Σ = {0, 1}L = ∅, L = Σ∗, L = {ε}, L = {0}.L = {w ∈ {0, 1}∗ | |w | is divisible by 5}L = {w ∈ {0, 1}∗ | w ends with 01}L = {w ∈ {0, 1}∗ | w contains 001 as substring}L = {w ∈ {0, 1}∗ | w contains 001 or 010 as substring}

L = {w | w has a 1 k positions from the end}

Nikita Borisov (UIUC) CS/ECE 374 19 Fall 2018 19 / 32

Page 45: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFA Construction: Example

Assume Σ = {0, 1}L = ∅, L = Σ∗, L = {ε}, L = {0}.L = {w ∈ {0, 1}∗ | |w | is divisible by 5}L = {w ∈ {0, 1}∗ | w ends with 01}L = {w ∈ {0, 1}∗ | w contains 001 as substring}L = {w ∈ {0, 1}∗ | w contains 001 or 010 as substring}L = {w | w has a 1 k positions from the end}

Nikita Borisov (UIUC) CS/ECE 374 19 Fall 2018 19 / 32

Page 46: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFA Construction: Example

L = {Binary numbers congruent to 0 mod 5}Example: 1101011 = 107 = 2 mod 5, 1010 = 10 = 0 mod 5

Key observation:w mod 5 = a impliesw0 mod 5 = 2a mod 5 and w1 mod 5 = (2a + 1) mod 5

Nikita Borisov (UIUC) CS/ECE 374 20 Fall 2018 20 / 32

Page 47: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

DFA Construction: Example

L = {Binary numbers congruent to 0 mod 5}Example: 1101011 = 107 = 2 mod 5, 1010 = 10 = 0 mod 5Key observation:w mod 5 = a impliesw0 mod 5 = 2a mod 5 and w1 mod 5 = (2a + 1) mod 5

Nikita Borisov (UIUC) CS/ECE 374 20 Fall 2018 20 / 32

Page 48: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Part III

Complement

Nikita Borisov (UIUC) CS/ECE 374 21 Fall 2018 21 / 32

Page 49: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Complement

Question: If M is a DFA, is there a DFA M ′ such thatL(M ′) = Σ∗ \ L(M)? That is, are languages recognized by DFAsclosed under complement?

Definition 4. A deterministic finite automaton (DFA) is M = (Q,⌃, �, s, A) where

• Q is a finite set whose element are called states,

• ⌃ is a finite set called the input alphabet,

• � : Q ⇥ ⌃ ! Q is the transition function,

• s 2 Q is the start state,

• A ✓ Q is the set of accepting/final states.

Definition 5. For a DFA M = (Q,⌃, �, s, A), string w = w1w2 · · · wk, where for each i, wi 2 ⌃, and states

p, q 2 Q, we say pw�!M q if there is a sequence of states r0, r1, . . . rk such that (a) r0 = p, (b) for each i,

�(ri, wi+1) = ri+1, and (c) rk = q.

Problem 4. Prove that for any state p, and string w 2 ⌃⇤, there is a unique state q such that pw�!M q.

Notation. �⇤M (p, w) = q where pw�!M q

Definition 6. Consider a DFA M = (Q,⌃, �, s, A).

• M accepts string w 2 ⌃⇤ i↵ �⇤M (s, w) 2 A.

• The language accepted/recognized by a DFA M is L(M) = {w 2 ⌃⇤ | M accepts w}.

• A set L ✓ ⌃⇤ is said to accepted/recognized by M i↵ L = L(M).

Problem 5.

1. Which of the following is true?

• B✏�!M B

• A01�!M D

• D111�!M C

• A101�!M2

B

2. What is the following?

• �⇤M2(A, 1011) =

• �⇤M2(B, 010) =

• �⇤M2(C, 100) =

q0

q1 q2

q3

0

1

1 0

1

0

0, 1

Figure 1: DFA M for problem 5

3. What is L(M)?

4. What is the language recognized if we change the initial state to B?

5. What is the language recognized if we change the set of final states to be {B} (with initial state A)?

3

Nikita Borisov (UIUC) CS/ECE 374 22 Fall 2018 22 / 32

Page 50: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Complement

TheoremLanguages accepted by DFAs are closed under complement.

Proof.Let M = (Q,Σ, δ, s,A) such that L = L(M).Let M ′ = (Q,Σ, δ, s,Q \ A). Claim: L(M ′) = L̄. Why?δ∗M = δ∗M′ . Thus, for every string w , δ∗M(s,w) = δ∗M′(s,w).δ∗M(s,w) ∈ A⇒ δ∗M′(s,w) 6∈ Q \ A.δ∗M(s,w) 6∈ A⇒ δ∗M′(s,w) ∈ Q \ A.

Nikita Borisov (UIUC) CS/ECE 374 23 Fall 2018 23 / 32

Page 51: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Complement

TheoremLanguages accepted by DFAs are closed under complement.

Proof.Let M = (Q,Σ, δ, s,A) such that L = L(M).Let M ′ = (Q,Σ, δ, s,Q \ A). Claim: L(M ′) = L̄. Why?

δ∗M = δ∗M′ . Thus, for every string w , δ∗M(s,w) = δ∗M′(s,w).δ∗M(s,w) ∈ A⇒ δ∗M′(s,w) 6∈ Q \ A.δ∗M(s,w) 6∈ A⇒ δ∗M′(s,w) ∈ Q \ A.

Nikita Borisov (UIUC) CS/ECE 374 23 Fall 2018 23 / 32

Page 52: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Complement

TheoremLanguages accepted by DFAs are closed under complement.

Proof.Let M = (Q,Σ, δ, s,A) such that L = L(M).Let M ′ = (Q,Σ, δ, s,Q \ A). Claim: L(M ′) = L̄. Why?δ∗M = δ∗M′ . Thus, for every string w , δ∗M(s,w) = δ∗M′(s,w).δ∗M(s,w) ∈ A⇒ δ∗M′(s,w) 6∈ Q \ A.δ∗M(s,w) 6∈ A⇒ δ∗M′(s,w) ∈ Q \ A.

Nikita Borisov (UIUC) CS/ECE 374 23 Fall 2018 23 / 32

Page 53: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Part IV

Product Construction

Nikita Borisov (UIUC) CS/ECE 374 24 Fall 2018 24 / 32

Page 54: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Union and Intersection

Question: Are languages accepted by DFAs closed under union?That is, given DFAs M1 and M2 is there a DFA that acceptsL(M1) ∪ L(M2)?How about intersection L(M1) ∩ L(M2)?

Idea from programming: on input string wSimulate M1 on wSimulate M2 on wIf both accept than w ∈ L(M1) ∩ L(M2). If at least oneaccepts then w ∈ L(M1) ∪ L(M2).

Catch: We want a single DFA M that can only read w once.

Solution: Simulate M1 and M2 in parallel by keeping track ofstates of both machines

Nikita Borisov (UIUC) CS/ECE 374 25 Fall 2018 25 / 32

Page 55: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Union and Intersection

Question: Are languages accepted by DFAs closed under union?That is, given DFAs M1 and M2 is there a DFA that acceptsL(M1) ∪ L(M2)?How about intersection L(M1) ∩ L(M2)?

Idea from programming: on input string wSimulate M1 on wSimulate M2 on wIf both accept than w ∈ L(M1) ∩ L(M2). If at least oneaccepts then w ∈ L(M1) ∪ L(M2).

Catch: We want a single DFA M that can only read w once.

Solution: Simulate M1 and M2 in parallel by keeping track ofstates of both machines

Nikita Borisov (UIUC) CS/ECE 374 25 Fall 2018 25 / 32

Page 56: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Union and Intersection

Question: Are languages accepted by DFAs closed under union?That is, given DFAs M1 and M2 is there a DFA that acceptsL(M1) ∪ L(M2)?How about intersection L(M1) ∩ L(M2)?

Idea from programming: on input string wSimulate M1 on wSimulate M2 on wIf both accept than w ∈ L(M1) ∩ L(M2). If at least oneaccepts then w ∈ L(M1) ∪ L(M2).

Catch: We want a single DFA M that can only read w once.

Solution: Simulate M1 and M2 in parallel by keeping track ofstates of both machines

Nikita Borisov (UIUC) CS/ECE 374 25 Fall 2018 25 / 32

Page 57: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Union and Intersection

Question: Are languages accepted by DFAs closed under union?That is, given DFAs M1 and M2 is there a DFA that acceptsL(M1) ∪ L(M2)?How about intersection L(M1) ∩ L(M2)?

Idea from programming: on input string wSimulate M1 on wSimulate M2 on wIf both accept than w ∈ L(M1) ∩ L(M2). If at least oneaccepts then w ∈ L(M1) ∪ L(M2).

Catch: We want a single DFA M that can only read w once.

Solution: Simulate M1 and M2 in parallel by keeping track ofstates of both machines

Nikita Borisov (UIUC) CS/ECE 374 25 Fall 2018 25 / 32

Page 58: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

0

1

1

0

0

1

M2 accepts #1 = odd

0 110

0

1

M1 accepts #0 = odd

Nikita Borisov (UIUC) CS/ECE 374 26 Fall 2018 26 / 32

Page 59: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Example

Cross-product machine

0 110

0

1

M1 accepts #0 = odd

0

1

1

0

0

1

M2 accepts #1 = odd

0

00 10

01 11

0

0

01 1 1 1

Nikita Borisov (UIUC) CS/ECE 374 27 Fall 2018 27 / 32

Page 60: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 61: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q =

Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 62: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}

s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 63: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s =

(s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 64: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 65: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) =

(δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 66: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 67: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A =

A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 68: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 69: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for intersection

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = A1 × A2 = {(q1, q2) | q1 ∈ A1, q2 ∈ A2}

TheoremL(M) = L(M1) ∩ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 28 Fall 2018 28 / 32

Page 70: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Correctness of construction

LemmaFor each string w , δ∗(s,w) = (δ∗1 (s1,w), δ∗2 (s2,w)).

Exercise: Assuming lemma prove the theorem in previous slide.Proof of lemma by induction on |w |

Nikita Borisov (UIUC) CS/ECE 374 29 Fall 2018 29 / 32

Page 71: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Correctness of construction

LemmaFor each string w , δ∗(s,w) = (δ∗1 (s1,w), δ∗2 (s2,w)).

Exercise: Assuming lemma prove the theorem in previous slide.

Proof of lemma by induction on |w |

Nikita Borisov (UIUC) CS/ECE 374 29 Fall 2018 29 / 32

Page 72: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Correctness of construction

LemmaFor each string w , δ∗(s,w) = (δ∗1 (s1,w), δ∗2 (s2,w)).

Exercise: Assuming lemma prove the theorem in previous slide.Proof of lemma by induction on |w |

Nikita Borisov (UIUC) CS/ECE 374 29 Fall 2018 29 / 32

Page 73: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for union

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A =

{(q1, q2) | q1 ∈ A1 or q2 ∈ A2}

TheoremL(M) = L(M1) ∪ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 30 Fall 2018 30 / 32

Page 74: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Product construction for union

M1 = (Q1,Σ, δ1, s1,A1) and M2 = (Q1,Σ, δ2, s2,A2)

Create M = (Q,Σ, δ, s,A) where

Q = Q1 × Q2 = {(q1, q2) | q1 ∈ Q1, q2 ∈ Q2}s = (s1, s2)

δ : Q × Σ→ Q where

δ((q1, q2), a) = (δ1(q1, a), δ2(q2, a))

A = {(q1, q2) | q1 ∈ A1 or q2 ∈ A2}

TheoremL(M) = L(M1) ∪ L(M2).

Nikita Borisov (UIUC) CS/ECE 374 30 Fall 2018 30 / 32

Page 75: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Set Difference

TheoremM1,M2 DFAs. There is a DFA M such thatL(M) = L(M1) \ L(M2).

Exercise: Prove the above using two methods.

Using a direct product construction

Using closure under complement and intersection and union

Nikita Borisov (UIUC) CS/ECE 374 31 Fall 2018 31 / 32

Page 76: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Things to know: 2-way DFA

Question: Why are DFAs required to only move right?Can we allow DFA to scan back and forth? Caveat: Tape is read-onlyso only memory is in machine’s state.

Can define a formal notion of a “2-way” DFA

Can show that any language recognized by a 2-way DFA can berecognized by a regular (1-way) DFA

Proof is tricky simulation via NFAs

Nikita Borisov (UIUC) CS/ECE 374 32 Fall 2018 32 / 32

Page 77: Deterministic Finite Automata (DFAs) · Deterministic Finite Automata (DFAs) Lecture 3 September 4, 2018 Nikita Borisov (UIUC) CS/ECE 374 1 Fall 2018 1/32. Part I DFA Introduction

Things to know: 2-way DFA

Question: Why are DFAs required to only move right?Can we allow DFA to scan back and forth? Caveat: Tape is read-onlyso only memory is in machine’s state.

Can define a formal notion of a “2-way” DFA

Can show that any language recognized by a 2-way DFA can berecognized by a regular (1-way) DFA

Proof is tricky simulation via NFAs

Nikita Borisov (UIUC) CS/ECE 374 32 Fall 2018 32 / 32