CS 374: Algorithms & Models of Computation Chandra Chekuri - - PowerPoint PPT Presentation

cs 374 algorithms models of computation
SMART_READER_LITE
LIVE PREVIEW

CS 374: Algorithms & Models of Computation Chandra Chekuri - - PowerPoint PPT Presentation

CS 374: Algorithms & Models of Computation Chandra Chekuri University of Illinois, Urbana-Champaign Spring 2017 Chandra Chekuri (UIUC) CS374 1 Spring 2017 1 / 34 CS 374: Algorithms & Models of Computation, Spring 2017


slide-1
SLIDE 1

CS 374: Algorithms & Models of Computation

Chandra Chekuri

University of Illinois, Urbana-Champaign

Spring 2017

Chandra Chekuri (UIUC) CS374 1 Spring 2017 1 / 34

slide-2
SLIDE 2

CS 374: Algorithms & Models of Computation, Spring 2017

Deterministic Finite Automata (DFAs)

Lecture 3

January 24, 2017

Chandra Chekuri (UIUC) CS374 2 Spring 2017 2 / 34

slide-3
SLIDE 3

Part I DFA Introduction

Chandra Chekuri (UIUC) CS374 3 Spring 2017 3 / 34

slide-4
SLIDE 4

DFAs also called Finite State Machines (FSMs)

The “simplest” model for computers? State machines that are very common in practice.

Vending machines Elevators Digital watches Simple network protocols

Programs with fixed memory

Chandra Chekuri (UIUC) CS374 4 Spring 2017 4 / 34

slide-5
SLIDE 5

A simple program

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

int n = 0 While input is not finished read next character c n ← n + 1 endWhile If (n is odd) output YES Else output NO

Chandra Chekuri (UIUC) CS374 5 Spring 2017 5 / 34

slide-6
SLIDE 6

A simple program

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

int n = 0 While input is not finished read next character c n ← n + 1 endWhile If (n is odd) output YES Else output NO bit x = 0 While input is not finished read next character c x ← flip(x) endWhile If (x = 1) output YES Else output NO

Chandra Chekuri (UIUC) CS374 5 Spring 2017 5 / 34

slide-7
SLIDE 7

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 after scanning the last symbol.

Chandra Chekuri (UIUC) CS374 6 Spring 2017 6 / 34

slide-8
SLIDE 8

Graphical Representation/State Machine

q0 q1 q2 q3 1 1 1 0, 1

Directed graph with nodes representing states and edge/arcs representing transitions labeled by symbols in Σ For each state (vertex) q and symbol a ∈ Σ there is exactly one

  • utgoing edge labeled by a

Initial/start state has a pointer (or labeled as s, q0 or “start”) Some states with double circles labeled as accepting/final states

Chandra Chekuri (UIUC) CS374 7 Spring 2017 7 / 34

slide-9
SLIDE 9

Graphical Representation

q0 q1 q2 q3 1 1 1 0, 1

Where does 001 lead? 10010?

Chandra Chekuri (UIUC) CS374 8 Spring 2017 8 / 34

slide-10
SLIDE 10

Graphical Representation

q0 q1 q2 q3 1 1 1 0, 1

Where does 001 lead? 10010? Which strings end up in accepting state?

Chandra Chekuri (UIUC) CS374 8 Spring 2017 8 / 34

slide-11
SLIDE 11

Graphical Representation

q0 q1 q2 q3 1 1 1 0, 1

Where does 001 lead? 10010? Which strings end up in accepting state? Can you prove it?

Chandra Chekuri (UIUC) CS374 8 Spring 2017 8 / 34

slide-12
SLIDE 12

Graphical Representation

q0 q1 q2 q3 1 1 1 0, 1

Where does 001 lead? 10010? Which strings end up in accepting state? Can you prove it? Every string w has a unique walk that it follows from a given state q by reading one letter of w from left to right.

Chandra Chekuri (UIUC) CS374 8 Spring 2017 8 / 34

slide-13
SLIDE 13

Graphical Representation

q0 q1 q2 q3 1 1 1 0, 1

Definition

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

Chandra Chekuri (UIUC) CS374 9 Spring 2017 9 / 34

slide-14
SLIDE 14

Graphical Representation

q0 q1 q2 q3 1 1 1 0, 1

Definition

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

Definition

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

Chandra Chekuri (UIUC) CS374 9 Spring 2017 9 / 34

slide-15
SLIDE 15

Warning

“M accepts language L” does not mean simply that that M accepts each string in L. It means that M accepts each string in L and no others. Equivalently M accepts each string in L and does not accept/rejects strings in Σ∗ \ L.

Chandra Chekuri (UIUC) CS374 10 Spring 2017 10 / 34

slide-16
SLIDE 16

Warning

“M accepts language L” does not mean simply that that M accepts each string in L. It means that M accepts each string in L and no others. Equivalently M 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)

Chandra Chekuri (UIUC) CS374 10 Spring 2017 10 / 34

slide-17
SLIDE 17

Formal Tuple Notation

Definition

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

Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

slide-18
SLIDE 18

Formal Tuple Notation

Definition

A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states,

Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

slide-19
SLIDE 19

Formal Tuple Notation

Definition

A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet,

Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

slide-20
SLIDE 20

Formal Tuple Notation

Definition

A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple 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,

Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

slide-21
SLIDE 21

Formal Tuple Notation

Definition

A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple 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,

Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

slide-22
SLIDE 22

Formal Tuple Notation

Definition

A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple 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.

Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

slide-23
SLIDE 23

Formal Tuple Notation

Definition

A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple 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.

Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

slide-24
SLIDE 24

Formal Tuple Notation

Definition

A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple 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.

Chandra Chekuri (UIUC) CS374 11 Spring 2017 11 / 34

slide-25
SLIDE 25

Example

q0 q1 q2 q3 1 1 1 0, 1

Q =

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-26
SLIDE 26

Example

q0 q1 q2 q3 1 1 1 0, 1

Q = {q0, q1, q1, q3}

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-27
SLIDE 27

Example

q0 q1 q2 q3 1 1 1 0, 1

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

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-28
SLIDE 28

Example

q0 q1 q2 q3 1 1 1 0, 1

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

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-29
SLIDE 29

Example

q0 q1 q2 q3 1 1 1 0, 1

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

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-30
SLIDE 30

Example

q0 q1 q2 q3 1 1 1 0, 1

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

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-31
SLIDE 31

Example

q0 q1 q2 q3 1 1 1 0, 1

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

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-32
SLIDE 32

Example

q0 q1 q2 q3 1 1 1 0, 1

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

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-33
SLIDE 33

Example

q0 q1 q2 q3 1 1 1 0, 1

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

Chandra Chekuri (UIUC) CS374 12 Spring 2017 12 / 34

slide-34
SLIDE 34

Extending the transition function to strings

Given DFA M = (Q, Σ, δ, s, A), δ(q, a) is the state that M goes to from q on reading letter a Useful to have notation to specify the unique state that M will reach from q on reading string w

Chandra Chekuri (UIUC) CS374 13 Spring 2017 13 / 34

slide-35
SLIDE 35

Extending the transition function to strings

Given DFA M = (Q, Σ, δ, s, A), δ(q, a) is the state that M goes to from q on reading letter a Useful to have notation to specify the unique state that M will reach from q on reading string w Transition function δ∗ : Q × Σ∗ → Q defined inductively as follows: δ∗(q, w) = q if w = ǫ δ∗(q, w) = δ∗(δ(q, a), x) if w = ax.

Chandra Chekuri (UIUC) CS374 13 Spring 2017 13 / 34

slide-36
SLIDE 36

Formal definition of language accepted by M

Definition

The language L(M) accepted by a DFA M = (Q, Σ, δ, s, A) is {w ∈ Σ∗ | δ∗(s, w) ∈ A}.

Chandra Chekuri (UIUC) CS374 14 Spring 2017 14 / 34

slide-37
SLIDE 37

Example

q0 q1 q2 q3 1 1 1 0, 1

What is: δ∗(q1, ǫ) δ∗(q0, 1011) δ∗(q1, 010) δ∗(q4, 10)

Chandra Chekuri (UIUC) CS374 15 Spring 2017 15 / 34

slide-38
SLIDE 38

Example continued

q0 q1 q2 q3 1 1 1 0, 1

What is L(M) if start state is changed to q1? What is L(M) if final/accepte states are set to {q2, q3} instead

  • f {q0}?

Chandra Chekuri (UIUC) CS374 16 Spring 2017 16 / 34

slide-39
SLIDE 39

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, any state q, δ∗(q, uv) = δ∗(δ∗(q, u), v).

Chandra Chekuri (UIUC) CS374 17 Spring 2017 17 / 34

slide-40
SLIDE 40

Part II Constructing DFAs

Chandra Chekuri (UIUC) CS374 18 Spring 2017 18 / 34

slide-41
SLIDE 41

DFAs: State = Memory

How do we design a DFA M for a given language L? That is L(M) = L. DFA is a like a program that has fixed amount of memory independent of input size. The memory of a DFA is encoded in its states The state/memory must capture enough information from the input seen so far that it is sufficient for the suffix that is yet to be seen (note that DFA cannot go back)

Chandra Chekuri (UIUC) CS374 19 Spring 2017 19 / 34

slide-42
SLIDE 42

DFA Construction: Example

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

Chandra Chekuri (UIUC) CS374 20 Spring 2017 20 / 34

slide-43
SLIDE 43

DFA Construction: Example

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

Chandra Chekuri (UIUC) CS374 20 Spring 2017 20 / 34

slide-44
SLIDE 44

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}

Chandra Chekuri (UIUC) CS374 20 Spring 2017 20 / 34

slide-45
SLIDE 45

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}

Chandra Chekuri (UIUC) CS374 20 Spring 2017 20 / 34

slide-46
SLIDE 46

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}

Chandra Chekuri (UIUC) CS374 20 Spring 2017 20 / 34

slide-47
SLIDE 47

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}

Chandra Chekuri (UIUC) CS374 20 Spring 2017 20 / 34

slide-48
SLIDE 48

DFA Construction: Example

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

Chandra Chekuri (UIUC) CS374 21 Spring 2017 21 / 34

slide-49
SLIDE 49

DFA Construction: Example

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

Chandra Chekuri (UIUC) CS374 21 Spring 2017 21 / 34

slide-50
SLIDE 50

Part III Product Construction and Closure Properties

Chandra Chekuri (UIUC) CS374 22 Spring 2017 22 / 34

slide-51
SLIDE 51

Part IV Complement

Chandra Chekuri (UIUC) CS374 23 Spring 2017 23 / 34

slide-52
SLIDE 52

Complement

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

q0 q1 q2 q3 1 1 1 0, 1

Chandra Chekuri (UIUC) CS374 24 Spring 2017 24 / 34

slide-53
SLIDE 53

Complement

Theorem

Languages accepted by DFAs are closed under complement.

Chandra Chekuri (UIUC) CS374 25 Spring 2017 25 / 34

slide-54
SLIDE 54

Complement

Theorem

Languages 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?

Chandra Chekuri (UIUC) CS374 25 Spring 2017 25 / 34

slide-55
SLIDE 55

Complement

Theorem

Languages 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) ∈ Q \ A.

δ∗

M(s, w) ∈ A ⇒ δ∗ M′(s, w) ∈ Q \ A.

Chandra Chekuri (UIUC) CS374 25 Spring 2017 25 / 34

slide-56
SLIDE 56

Part V Product Construction

Chandra Chekuri (UIUC) CS374 26 Spring 2017 26 / 34

slide-57
SLIDE 57

Union and Intersection

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

Chandra Chekuri (UIUC) CS374 27 Spring 2017 27 / 34

slide-58
SLIDE 58

Union and Intersection

Question: Are languages accepted by DFAs closed under union? That is, given DFAs M1 and M2 is there a DFA that accepts L(M1) ∪ L(M2)? How about intersection L(M1) ∩ L(M2)? Idea from programming: on input string w Simulate M1 on w Simulate M2 on w If both accept than w ∈ L(M1) ∩ L(M2). If at least one accepts then w ∈ L(M1) ∪ L(M2).

Chandra Chekuri (UIUC) CS374 27 Spring 2017 27 / 34

slide-59
SLIDE 59

Union and Intersection

Question: Are languages accepted by DFAs closed under union? That is, given DFAs M1 and M2 is there a DFA that accepts L(M1) ∪ L(M2)? How about intersection L(M1) ∩ L(M2)? Idea from programming: on input string w Simulate M1 on w Simulate M2 on w If both accept than w ∈ L(M1) ∩ L(M2). If at least one accepts then w ∈ L(M1) ∪ L(M2). Catch: We want a single DFA M that can only read w once.

Chandra Chekuri (UIUC) CS374 27 Spring 2017 27 / 34

slide-60
SLIDE 60

Union and Intersection

Question: Are languages accepted by DFAs closed under union? That is, given DFAs M1 and M2 is there a DFA that accepts L(M1) ∪ L(M2)? How about intersection L(M1) ∩ L(M2)? Idea from programming: on input string w Simulate M1 on w Simulate M2 on w If both accept than w ∈ L(M1) ∩ L(M2). If at least one accepts 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 of states of both machines

Chandra Chekuri (UIUC) CS374 27 Spring 2017 27 / 34

slide-61
SLIDE 61

Example

1 1 1 M2 accepts #1 = odd 1 1 1 M1 accepts #0 = odd

Chandra Chekuri (UIUC) CS374 28 Spring 2017 28 / 34

slide-62
SLIDE 62

Example

Cross-product machine

1 1 1 M1 accepts #0 = odd 1 1 1 M2 accepts #1 = odd 00 10 01 11 1 1 1 1

Chandra Chekuri (UIUC) CS374 29 Spring 2017 29 / 34

slide-63
SLIDE 63

Product construction for intersection

M1 = (Q1, Σ, δ1, s1, A1) and M2 = (Q1, Σ, δ2, s2, A2) Create M = (Q, Σ, δ, s, A) where

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-64
SLIDE 64

Product construction for intersection

M1 = (Q1, Σ, δ1, s1, A1) and M2 = (Q1, Σ, δ2, s2, A2) Create M = (Q, Σ, δ, s, A) where Q =

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-65
SLIDE 65

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}

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-66
SLIDE 66

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 =

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-67
SLIDE 67

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)

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-68
SLIDE 68

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) =

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-69
SLIDE 69

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))

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-70
SLIDE 70

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 =

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-71
SLIDE 71

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}

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-72
SLIDE 72

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}

Theorem

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

Chandra Chekuri (UIUC) CS374 30 Spring 2017 30 / 34

slide-73
SLIDE 73

Correctness of construction

Lemma

For each string w, δ∗(s, w) = (δ∗

1(s1, w), δ∗ 2(s2, w)).

Chandra Chekuri (UIUC) CS374 31 Spring 2017 31 / 34

slide-74
SLIDE 74

Correctness of construction

Lemma

For each string w, δ∗(s, w) = (δ∗

1(s1, w), δ∗ 2(s2, w)).

Exercise: Assuming lemma prove the theorem in previous slide.

Chandra Chekuri (UIUC) CS374 31 Spring 2017 31 / 34

slide-75
SLIDE 75

Correctness of construction

Lemma

For 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|

Chandra Chekuri (UIUC) CS374 31 Spring 2017 31 / 34

slide-76
SLIDE 76

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 =

Chandra Chekuri (UIUC) CS374 32 Spring 2017 32 / 34

slide-77
SLIDE 77

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}

Theorem

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

Chandra Chekuri (UIUC) CS374 32 Spring 2017 32 / 34

slide-78
SLIDE 78

Set Difference

Theorem

M1, M2 DFAs. There is a DFA M such that L(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

Chandra Chekuri (UIUC) CS374 33 Spring 2017 33 / 34

slide-79
SLIDE 79

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-only so only memory is in machine’s state.

Chandra Chekuri (UIUC) CS374 34 Spring 2017 34 / 34

slide-80
SLIDE 80

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-only so 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 be recognized by a regular (1-way) DFA Proof is tricky simulation via NFAs

Chandra Chekuri (UIUC) CS374 34 Spring 2017 34 / 34