• No results found

Deterministic Finite Automata (DFAs)

N/A
N/A
Protected

Academic year: 2021

Share "Deterministic Finite Automata (DFAs)"

Copied!
51
0
0

Loading.... (view fulltext now)

Full text

(1)

Deterministic Finite Automata (DFAs)

Grammars generate strings.

Automata recognize strings:

Given some input string x, an automata M either outputs

I “accept” if x ∈ L(M ), or

I “reject” if x /∈ L(M ).

An automata has:

I A set of states.

I One special state is the start state.

I A subset of the states are “accept” states. The remainder are “reject” states.

I A set of labeled transitions from one state to another.

(2)

Deterministic Finite Automata (DFAs)

Grammars generate strings.

Automata recognize strings:

Given some input string x, an automata M either outputs

I “accept” if x ∈ L(M ), or

I “reject” if x /∈ L(M ).

An automata has:

I A set of states.

I One special state is the start state.

I A subset of the states are “accept” states. The remainder are “reject” states.

I A set of labeled transitions from one state to another.

(3)

Deterministic Finite Automata (DFAs)

Grammars generate strings.

Automata recognize strings:

Given some input string x, an automata M either outputs

I “accept” if x ∈ L(M ), or

I “reject” if x /∈ L(M ).

An automata has:

I A set of states.

I One special state is the start state.

I A subset of the states are “accept” states. The remainder are “reject” states.

I A set of labeled transitions from one state to another.

(4)

Deterministic Finite Automata (DFAs)

Grammars generate strings.

Automata recognize strings:

Given some input string x, an automata M either outputs

I “accept” if x ∈ L(M ), or

I “reject” if x /∈ L(M ).

An automata has:

I A set of states.

I One special state is the start state.

I A subset of the states are “accept” states. The remainder are “reject” states.

I A set of labeled transitions from one state to another.

(5)

DFAs: removing the trap state.

On input x, follow the transitions as you process each character of x, in order.

Accept if and only if you end in an accept state.

L(M ) = {a, bc}

Note that D is a special state, called a “trap” state. c(a + b + c)terminates in D and is rejected. b(a + b)(a + b + c)terminates in D and is rejected. a(a + b + c)(a + b + c)terminates in D and is rejected. bc(a + b + c)(a + b + c)terminates in D and is rejected.

(6)

DFAs: removing the trap state.

On input x, follow the transitions as you process each character of x, in order.

Accept if and only if you end in an accept state.

L(M ) = {a, bc}

Note that D is a special state, called a “trap” state. c(a + b + c)terminates in D and is rejected. b(a + b)(a + b + c)terminates in D and is rejected. a(a + b + c)(a + b + c)terminates in D and is rejected. bc(a + b + c)(a + b + c)terminates in D and is rejected.

(7)

DFAs: removing the trap state.

On input x, follow the transitions as you process each character of x, in order.

Accept if and only if you end in an accept state.

L(M ) = {a, bc}

Note that D is a special state, called a “trap” state.

c(a + b + c)terminates in D and is rejected. b(a + b)(a + b + c)terminates in D and is rejected. a(a + b + c)(a + b + c)terminates in D and is rejected. bc(a + b + c)(a + b + c)terminates in D and is rejected.

(8)

DFAs: removing the trap state.

On input x, follow the transitions as you process each character of x, in order.

Accept if and only if you end in an accept state.

L(M ) = {a, bc}

Note that D is a special state, called a “trap” state.

c(a + b + c)terminates in D and is rejected.

b(a + b)(a + b + c)terminates in D and is rejected. a(a + b + c)(a + b + c)terminates in D and is rejected. bc(a + b + c)(a + b + c)terminates in D and is rejected.

(9)

DFAs: removing the trap state.

On input x, follow the transitions as you process each character of x, in order.

Accept if and only if you end in an accept state.

L(M ) = {a, bc}

Note that D is a special state, called a “trap” state.

c(a + b + c)terminates in D and is rejected.

b(a + b)(a + b + c)terminates in D and is rejected.

a(a + b + c)(a + b + c)terminates in D and is rejected. bc(a + b + c)(a + b + c)terminates in D and is rejected.

(10)

DFAs: removing the trap state.

On input x, follow the transitions as you process each character of x, in order.

Accept if and only if you end in an accept state.

L(M ) = {a, bc}

Note that D is a special state, called a “trap” state.

c(a + b + c)terminates in D and is rejected.

b(a + b)(a + b + c)terminates in D and is rejected.

a(a + b + c)(a + b + c)terminates in D and is rejected.

bc(a + b + c)(a + b + c)terminates in D and is rejected.

(11)

DFAs: removing the trap state.

On input x, follow the transitions as you process each character of x, in order.

Accept if and only if you end in an accept state.

L(M ) = {a, bc}

Note that D is a special state, called a “trap” state.

c(a + b + c)terminates in D and is rejected.

b(a + b)(a + b + c)terminates in D and is rejected.

a(a + b + c)(a + b + c)terminates in D and is rejected.

bc(a + b + c)(a + b + c)terminates in D and is rejected.

(12)

DFAs

If there is no transition from the current state labeled with the current input character, simply reject.

(13)

DFAs

If there is no transition from the current state labeled with the current input character, simply reject.

(14)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language: L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}} L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(15)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language: L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}} L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(16)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language: L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}} L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(17)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language: L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}} L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(18)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language: L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}} L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(19)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language: L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}} L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(20)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language:

L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}}

L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(21)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language:

L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}} L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(22)

Example 2

L = {x | x ∈ {a, b}and every a precedes every b}

Alternative ways of specifying the same language:

L = {x | x = yz ∧ y ∈ {a}∧ z ∈ {b}} L = {x | x ∈ L(ab)}

L = {x | x ∈ {a, b}and there is no occurrence of ba in x}

(23)

Example 3

L = {x | x ∈ {a, b}and every block of bs has even length}

(24)

Example 3

L = {x | x ∈ {a, b}and every block of bs has even length}

(25)

Example 3

L = {x | x ∈ {a, b}and every block of bs has even length}

(26)

Example 3

L = {x | x ∈ {a, b}and every block of bs has even length}

(27)

Example 3

L = {x | x ∈ {a, b}and every block of bs has even length}

(28)

Example 3

L = {x | x ∈ {a, b}and every block of bs has even length}

(29)

Example 4

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd between these 2 substrings.

First attempt (WRONG!):

A correct machine:

(30)

Example 4

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd between these 2 substrings.

First attempt (WRONG!):

A correct machine:

(31)

Example 4

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd between these 2 substrings.

First attempt (WRONG!):

A correct machine:

(32)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”)

First attempt (WRONG!):

A correct machine:

Claim: If M (x) = 1, then x ∈ L. Property 1: Clearly x starts with dc.

Property 2: It must end with cd, because any string leading to state 5 must end in c: all transitions to 5 are labeled c. We can verify by hand that M (dcd) = 0.

Property 3: any sub-string ending in c is either in state 3 or 5. Neither of those states have an out-transition labeled d, except the one leading to 6.

(33)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If M (x) = 1, then x ∈ L. Property 1: Clearly x starts with dc.

Property 2: It must end with cd, because any string leading to state 5 must end in c: all transitions to 5 are labeled c. We can verify by hand that M (dcd) = 0.

Property 3: any sub-string ending in c is either in state 3 or 5. Neither of those states have an out-transition labeled d, except the one leading to 6.

(34)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If M (x) = 1, then x ∈ L.

Property 1: Clearly x starts with dc.

Property 2: It must end with cd, because any string leading to state 5 must end in c: all transitions to 5 are labeled c. We can verify by hand that M (dcd) = 0.

Property 3: any sub-string ending in c is either in state 3 or 5. Neither of those states have an out-transition labeled d, except the one leading to 6.

(35)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If M (x) = 1, then x ∈ L.

Property 1: Clearly x starts with dc.

Property 2: It must end with cd, because any string leading to state 5 must end in c: all transitions to 5 are labeled c. We can verify by hand that M (dcd) = 0.

Property 3: any sub-string ending in c is either in state 3 or 5. Neither of those states have an out-transition labeled d, except the one leading to 6.

(36)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If M (x) = 1, then x ∈ L.

Property 1: Clearly x starts with dc.

Property 2: It must end with cd, because any string leading to state 5 must end in c:

all transitions to 5 are labeled c. We can verify by hand that M (dcd) = 0.

Property 3: any sub-string ending in c is either in state 3 or 5. Neither of those states have an out-transition labeled d, except the one leading to 6.

(37)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If M (x) = 1, then x ∈ L.

Property 1: Clearly x starts with dc.

Property 2: It must end with cd, because any string leading to state 5 must end in c:

all transitions to 5 are labeled c. We can verify by hand that M (dcd) = 0.

Property 3: any sub-string ending in c is either in state 3 or 5. Neither of those states have an out-transition labeled d, except the one leading to 6.

(38)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If x ∈ L, then M (x) = 1.

Let w be such that x = dcwcd. The first dc leave us in state 3.

By the definition of L, w cannot start with a d, so x is not rejected when M is in state 3. Also, M will never return to state 3.

The other two states in the triangle have 4 transitions out, so neither causes a rejection on w.

Finally, since we know that x ends in cd, regardless of where in the triangle w leaves us (even if w = Λ), cd carries us to the accept state.

(39)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If x ∈ L, then M (x) = 1.

Let w be such that x = dcwcd. The first dc leave us in state 3.

By the definition of L, w cannot start with a d, so x is not rejected when M is in state 3. Also, M will never return to state 3.

The other two states in the triangle have 4 transitions out, so neither causes a rejection on w.

Finally, since we know that x ends in cd, regardless of where in the triangle w leaves us (even if w = Λ), cd carries us to the accept state.

(40)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If x ∈ L, then M (x) = 1.

Let w be such that x = dcwcd. The first dc leave us in state 3.

By the definition of L, w cannot start with a d, so x is not rejected when M is in state 3. Also, M will never return to state 3.

The other two states in the triangle have 4 transitions out, so neither causes a rejection on w.

Finally, since we know that x ends in cd, regardless of where in the triangle w leaves us (even if w = Λ), cd carries us to the accept state.

(41)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If x ∈ L, then M (x) = 1.

Let w be such that x = dcwcd. The first dc leave us in state 3.

By the definition of L, w cannot start with a d, so x is not rejected when M is in state 3. Also, M will never return to state 3.

The other two states in the triangle have 4 transitions out, so neither causes a rejection on w.

Finally, since we know that x ends in cd, regardless of where in the triangle w leaves us (even if w = Λ), cd carries us to the accept state.

(42)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If x ∈ L, then M (x) = 1.

Let w be such that x = dcwcd. The first dc leave us in state 3.

By the definition of L, w cannot start with a d, so x is not rejected when M is in state 3. Also, M will never return to state 3.

The other two states in the triangle have 4 transitions out, so neither causes a rejection on w.

Finally, since we know that x ends in cd, regardless of where in the triangle w leaves us (even if w = Λ), cd carries us to the accept state.

(43)

Example 4b

L over Σ = {a, b, c, d} which contains exactly the strings x such that 1. x begins with dc

2. x ends in a substring cd (but x 6= dcd) and

3. x has no other occurrence of cd. (Previous example said:

“x has no other occurrence of cd between these 2 substrings.”) A correct machine:

Claim: If x ∈ L, then M (x) = 1.

Let w be such that x = dcwcd. The first dc leave us in state 3.

By the definition of L, w cannot start with a d, so x is not rejected when M is in state 3. Also, M will never return to state 3.

The other two states in the triangle have 4 transitions out, so neither causes a rejection on w.

Finally, since we know that x ends in cd, regardless of where in the triangle w leaves us (even if w = Λ), cd carries us to the accept state.

(44)

Example 5

(45)

Example 5

(46)

Example 5

(47)

Example 5

(48)

Example 5

(49)

Example 5

(50)

Example 5

(51)

Example 5

References

Related documents

A phase III randomized trial (WJTOG 3405) of gefitinib compared with cisplatin/ docetaxel as first-line treatment for EGFR-mutant NSCLC revealed that gefitinib provided a 3-year

If this happens, after replacing the lamp, connect the power cord and then press and hold the HELP button on the remote control at least 10 seconds. This will allow you to turn on

In this paper, we specifically explore gender differences in immobility and report upon its socioeconomic determinants by exploiting the 2007 Pakistan Time Use Survey (PTUS). We

(2007) Technology Acquisition and Innovation in the Developing World: Wind Turbine Development in India and China.. Studies in Comparative International Development,

As a result, we can affirm that the establishment of key risk indicators within the Risk Monitoring and Control process following the guidelines of ISO/IEC 27005 [2] and ISO/IEC 31000

Accrding to this, the work included four main research contents: (i) the raw (untreated), sonicated and irradiated WAS samples were analyzed for the calculation

We quantitatively characterize early reviewers based on their rating behaviors, the helpfulness scores received from others and the correlation of their reviews with

The constitutional property clause itself envisages reforms to land and natural resources that may interfere with property rights, providing in section 25(8) that