30
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003

Introduction to the Theory of Computation

  • Upload
    iden

  • View
    31

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to the Theory of Computation. John Paxton Montana State University Summer 2003. Humor. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to the Theory of Computation

Introduction to the Theory of Computation

John Paxton

Montana State University

Summer 2003

Page 2: Introduction to the Theory of Computation

Humor• A busload of politicians were driving down a country road when, all

of a sudden, the bus ran off the road and crashed into a tree in an old farmer's field. The old farmer, after seeing what had happened, went over to investigate. He then proceeded to dig a hole to bury the politicians.              A few days later the local sheriff came out, saw the crashed bus, and asked the old farmer where all the politicians had gone.              The old farmer said he had buried them.              The sheriff asked the old farmer, "Were they all dead?"              The old farmer replied, "Well, some of them said they weren't, but you know how them politicians lie."

Page 3: Introduction to the Theory of Computation

1.2 Nondeterminism

• In a nondeterministic machine, several choices might exist at a given point instead of only one.

Page 4: Introduction to the Theory of Computation

Example 2

0,

0

1

q0

q1

q2

Page 5: Introduction to the Theory of Computation

Example 3

• Write an NDFA that recognizes the language consisting of all strings over {0, 1} containing a 1 in the third position from the end.

Page 6: Introduction to the Theory of Computation

Example 3

1 0,1 0,1

0,1

q0 q1q2

q3

Page 7: Introduction to the Theory of Computation

Exercises

• Give a 3 state NFA that accepts the language: zero or more 0s, followed by zero or more ones, followed by zero or more 0s followed by a 0.

• Give a 1 state NFA that accepts the language {}.

Page 8: Introduction to the Theory of Computation

Formal Definition

A nondeterministic finite automaton is a 5-tuple (Q, , , q0, F) where

1. Q is a finite set called the states

2. is a finite set called the alphabet

3. : Q x P(Q) is the transition function

4. q0 Q is the start state

5. F Q is the set of accept states

Page 9: Introduction to the Theory of Computation

P(Q)

• The power set of states

• Consider Q = { q0, q1, q2 }

• Then P(Q) = { {}, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2}, {q1, q2}, {q0, q1, q2} }

Page 10: Introduction to the Theory of Computation

Example 3

• Q = {q0, q1, q2, q3}

• = {0, 1}

• q0

• F = {q3}

Page 11: Introduction to the Theory of Computation

Example 3,

0 1

q0 {q0} {q0, q1} {}

q1 {q2} {q2} {}

q2 {q3} {q3} {}

q3 {q3} {q3} {}

Page 12: Introduction to the Theory of Computation

Acceptance

Let N = (Q, , , q0, F) be an NFA and w = w1w2 …wn be a string over the alphabet . Then N “accepts” w if a sequence of states r0r1…rn exists in Q with the following three conditions:

1. r0 = q0

2. ri+1 (ri, wi+1) for 0 <= i <= n – 1

3. rn F

Page 13: Introduction to the Theory of Computation

Theorem

• Every nondeterministic finite automaton has an equivalent deterministic finite automaton.

Page 14: Introduction to the Theory of Computation

Proof

• Part 1

• Given a deterministic finite automaton, there is an equivalent nondeterministic finite automaton.

• Proof. Trivial!

Page 15: Introduction to the Theory of Computation

Proof

• Part II.

• Given a nondeterministic finite automaton, there is an equivalent deterministic finite automaton.

• Proof. A bit harder …

Page 16: Introduction to the Theory of Computation

Proof by Construction

• Let N = (Q, , , q0, F)

• Construct M = (Q’, , ’, q0’, F’)

• Q’ = P(Q)

• q0’ = E [ {q0} ]

Page 17: Introduction to the Theory of Computation

Proof by Construction

• F’ = {R Q’ | R contains an accept state in N}

• For R Q’ and a , let ’(R, a) = {q Q | q E[(r, a)] for some r R}

Page 18: Introduction to the Theory of Computation

Convert Example 2

{q0, q1}

{q1, q2}

0

{q2}1

1

Page 19: Introduction to the Theory of Computation

Exercise

• Convert the following NFA into an equivalent DFA.

a

aa,b

b

q0 q1

q2

Page 20: Introduction to the Theory of Computation

Theorems

• The class of regular languages is closed under the union operation.

• The class of regular languages is closed under the concatenation operation.

• The class of regular languages is closed under the star operation.

Page 21: Introduction to the Theory of Computation

Closure Under Union

• Note: we already proved this once using DFAs.

• However, using NFAs, the proof is even easier so we will do it again!

Page 22: Introduction to the Theory of Computation

Closure Under Union

• Let N1 = (Q1, , , q1, F1)

• Let N2 = (Q2, , 2, q2, F2)

• Construct N = (Q, , , q0, F)

• Q = q0 U Q1 U Q2

Page 23: Introduction to the Theory of Computation

Closure Under Union

• F = F1 U F2

• (q, a) =1(q, a) if q Q1

2(q, a) if q Q2

{q1, q2} if q = q0 and a = {} if q = q0 and a <>

Page 24: Introduction to the Theory of Computation

Exercises

• Draw a picture that graphically displays how the preceding proof works.

• Draw an NFA that accepts the union of {w | w begins with a 1 and ends with a 0} and {w | w contains at least three 1s}

Page 25: Introduction to the Theory of Computation

Closure Under Concatenation

• Let N1 = (Q1, , , q1, F1)

• Let N2 = (Q2, , 2, q2, F2)

• Construct N = (Q, , , q0, F)

• Q = Q1 U Q2

Page 26: Introduction to the Theory of Computation

Closure Under Concatenation

• q0 = q1

• F = F2

• (q, a) =1(q, a) if q Q1 and !(q F1)1(q, a) if q F1 and a <> 1(q, a) U {q2} if q F1 and a = 2(q, a) if q Q2

Page 27: Introduction to the Theory of Computation

Exercises

• Draw a picture that graphically displays how the preceding proof works.

• Draw an NFA that accepts the concatenation of {w | w begins with a 1 and ends with a 0} and {w | w contains at least three 1s}

Page 28: Introduction to the Theory of Computation

Closure Under Star

• Let N1 = (Q1, , , q1, F1)

• Construct N = (Q, , , q0, F)

• Q = {q0} U Q1

• F = {q0} U F1

Page 29: Introduction to the Theory of Computation

Closure Under Star

(q, a) =

1(q, a) if q Q1 and !(q F1)

1(q, a) if q F1 and a <>

1(q, a) U {q1} if q F1 and a =

{q1} if q = q0 and a =

{} if q = q0 and a <>

Page 30: Introduction to the Theory of Computation

Exercises

• Draw a picture that graphically displays how the preceding proof works.

• Draw an NFA that accepts the star of {w | w begins with a 1 and ends with a 0}.