Introduction to the theory of computation
Download
1 / 47

Introduction to the Theory of Computation - PowerPoint PPT Presentation


  • 97 Views
  • Uploaded on

Introduction to the Theory of Computation. Part I: Automata and Languages. 1. Regular Languages. 1.1 Finite Automata Deterministic FA Non-Deterministic FA -NFA 1.2 Regular Expressions RE = FA 1.3 Properties of Regular Languages Pumping lemma Closure properties Decision properties.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Introduction to the Theory of Computation' - kiona-lindsay


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Introduction to the theory of computation

Introduction to the Theory of Computation

Part I: Automata and Languages


1 regular languages
1. Regular Languages

  • 1.1 Finite Automata

    • Deterministic FA

    • Non-Deterministic FA

    • -NFA

  • 1.2 Regular Expressions

    • RE = FA

  • 1.3 Properties of Regular Languages

    • Pumping lemma

    • Closure properties

    • Decision properties


1 1 finite automata
1.1 Finite Automata

  • Deterministic FA

  • Non-Deterministic FA

  • NFA = DFA

  • -NFA

  • -NFA = NFA


Finite automata
Finite Automata

  • The simplest computational model, with very limited memory, but highly useful

  • Example: a finite automaton modeling an on/off switch

push

Start

off

on

push


State diagram of fa

1

0

1

0

q1

q2

q3

0, 1

State Diagram of FA

transitions

states

M1:

start state

accept state


M1 cont d

1

0

1

0

q1

q2

q3

0, 1

M1 Cont’d

on input “0110”, the machine goes:

q1q1q2q2q3 = “reject”


M1 cont d1

1

0

1

0

q1

q2

q3

0, 1

M1 Cont’d

on input “101”, the machine goes:

q1q2q3q2 = “accept”


M1 cont d2

What is the language accepted by M1?

1

0

1

0

q1

q2

q3

0, 1

M1 Cont’d

010:

11:

0110100:

010000010010:

reject

accept

accept

reject


Formal definition of fa
Formal Definition of FA

  • A finite automaton is defined by a 5-tuple (Q, Σ, , q0, F)

    • Q: finite set of states

    • Σ: finite alphabet

    • : transition function, : Q x ΣQ, takes a state and input symbol as arguments, and returns a state

    • q0Q: start state

    • FQ: set of accept states


M1 s formal definition

1

0

1

0

q1

q2

q3

0

1

0, 1

q1

q1

q2

q2

q3

q2

q3

q2

q2

M1’s Formal Definition

  • M1 = (Q, Σ, , q0, F), where

    • Q = {q1, q2, q3}

    • Σ = {0, 1}

    • (q1,0)=q1, (q1,1)=q2, (q2,0)=q3, (q2,1)=q2, (q3,0)=q2, (q3,1)=q2

    • q1 is the start state

    • F = {q2}


Extension of to strings
Extension of  to Strings

  • Intuitively, an FA accepts a string w = a1a2…an if there is a path in the state diagram that:

    • Begins at the start state,

    • Ends at an accept state, and

    • Has sequence of labels a1, a2, …, an.

  • Formally, the transition function  can be extended to *(q, w), where w is any string of input symbols.

    • Basis: *(q, ) = q

    • Induction: *(q, wa) =  (*(q, w), a)


Language of an fa
Language of an FA

  • An FA M = (Q, Σ, , q0, F) accepts a string w if *(q0, w) F.

  • The language recognized by an FA M= (Q, Σ, , q0, F) is

    L(M) = {w | *(q0, w) F}.

  • A language is called a regular language if some finite automaton recognizes it.


Designing finite automata
Designing Finite Automata

  • Given some language, design a FA that recognizes it.

  • Pretending to be a FA,

    • You see the input symbols one by one

    • You have finite memory, i.e. finite set of states, so remember only the crucial information (finite set of possibilities) about the string seen so far.


Example
Example

  • Σ ={0,1}, L = {w | w has odd number of 1s}, design a FA to recognize L.

    • What is the necessary information to remember? --- Is the number of 1s seen so far even or odd? Two possibilities.


Example1
Example

  • Σ ={0,1}, L = {w | w has odd number of 1s}, design a FA to recognize L.

    • What is the necessary information to remember? --- Is the number of 1s seen so far even or odd? Two possibilities.

    • Assign a state to each possibility.

qeven

qodd


Example2

0

0

1

1

Example

  • Σ ={0,1}, L = {w | w has odd number of 1s}, design a FA to recognize L.

    • What is the necessary information to remember? --- Is the number of 1s seen so far even or odd? Two possibilities.

    • Assign a state to each possibility.

    • Assign the transitions from one possibility to another upon reading a symbol.

qeven

qodd


Example3
Example

  • Σ ={0,1}, L = {w | w has odd number of 1s}, design a FA to recognize L.

    • What is the necessary information to remember? --- Is the number of 1s seen so far even or odd? Two possibilities.

    • Assign a state to each possibility.

    • Assign the transitions from one possibility to another upon reading a symbol.

    • Set the start and accept states.

0

0

1

qeven

qodd

1


Exercise
Exercise

  • Σ ={0,1}, L = {w | w has even number of 0s and even number of 1s}, design a FA to recognize L.

    • What to remember?

    • How many possibilities?


Exercise1
Exercise

1

q00

q01

1

0

0

0

0

1

q10

q11

1


Example 1 9
Example 1.9

  • Σ ={0,1}, L = {w | w contains 001 as a substring}, design a FA to recognize L.

    • four possibilities:

    • haven’t just seen any symbols of 001 --- q

    • have just seen a 0 --- q0

    • have just seen a 00 --- q00

    • have seen the entire pattern 001 --- q001


Example 1 91
Example 1.9

1

0

0, 1

0

0

1

q

q0

q00

q001

1


1 1 finite automata1
1.1 Finite Automata

  • Deterministic FA

  • Non-Deterministic FA

  • NFA = DFA

  • -NFA

  • -NFA = NFA


Nondeterministic finite automata

0, 1

0

1

q0

q1

q2

Nondeterministic Finite Automata

  • Deterministic: At any point when the machine is in a state with an input symbol, there is a unique next state to go.

  • Non-Deterministic: There can be more than one next state for each state-input pair.

  • Example: an automaton that accepts all strings ending in 01.

M2:


How an nfa computes

0, 1

0

1

q0

q1

q2

How an NFA computes?

q0

q0

q0

q0

q0

q0

q1

q1

q1

(die)

q2

q2

(die)

Input:

0

0

1

0

1


Formal definition of nfa
Formal Definition of NFA

  • An NFA can be in several states at once, or viewed in another way, it can “guess” which state to go next.

  • Formally, an NFA is a 5-tuple N = (Q, Σ, , q0, F), where all is as DFA, but

    • : Q x ΣP (Q) is a transition function from Q x Σ to the power set of Q.


M2 s formal definition

0, 1

0

1

q0

q1

q2

M2’s Formal Definition

  • M2 = (Q, Σ, , q0, F), where

    • Q = {q0, q1, q2}

    • Σ = {0, 1}

    • (q0,0)={q0,q1}, (q0,1)={q0}, (q1,1)={q2}

    • q0 is the start state

    • F = {q2}

0

1

q0

{q0,q1}

{q0}

q1

{q2}

q2


Language of an nfa
Language of an NFA

  • Extension of  to *(q, w):

    • Basis: *(q, ) = {q}

    • Induction: *(q, wa) = ∪p *(q, w)(p, a)

  • Formally, the language recognized by N = (Q, Σ, , q0, F) is

    L(M) = {w | *(q0, w) ∩ F ≠ }.

    (i.e. if any path from the start state to an accept state is labeled w.)


1 1 finite automata2
1.1 Finite Automata

  • Deterministic FA

  • Non-Deterministic FA

  • NFA = DFA

  • -NFA

  • -NFA = NFA


Equivalence of nfa and dfa
Equivalence of NFA and DFA

  • NFA’s are usually easier to “program” in.

  • Surprisingly, for each NFA there is an equivalent (recognizes the same language) DFA.

  • But the DFA can have exponentially many states.


Subset construction
Subset Construction

  • Given an NFA N=(QN, Σ, N, q0, FN), we will construct an DFA D=(QD, Σ, D, {q0}, FD), such that L(D) = L(N).

  • Subset construction:

    • QD = {S | S  QN}, i.e. power set of QN

    • D(S, a) = ∪p  S N(p, a)

    • FD = {S | S ∩ F ≠ , S ∈ QD}


Construct dfa from m2

1

0

{q0}

0

{q0,q1}

1

{q0,q2}

0

1

Construct DFA from M2

  • Subset construction:

8 possible subsets, 3 accessible:


Example nfa

1, 2, 3

q

1

1

2

2

p

r

t

1

3

3

s

1, 2

Example NFA

  • Design an NFA to accept strings over alphabet {1, 2, 3} such that the last symbol appears previously, without any intervening higher symbol, e.g., …11, …21112, …312123.


Equivalent dfa
Equivalent DFA

  • 32 possible subsets, 15 accessible:

  • DFA is much larger than NFA


Proof l d l n
Proof: L(D)=L(N)

  • Induction on |w| to show that

    *D({q0}, w) = *N(q0, w)

    • Basis: w=, the claim follows from the def.

    • Induction: *D({q0}, wa) = D(*D({q0}, w), a)

      = D(*N(q0, w), a)

      = ∪p*N(q0, w)N(p, a)

      = *N(q0, wa)

  • Then it follows that L(D) = L(N), why?


1 1 finite automata3
1.1 Finite Automata

  • Deterministic FA

  • Non-Deterministic FA

  • NFA = DFA

  • -NFA

  • -NFA = NFA


Finite automata with transitions
Finite Automata with -Transitions

  • Allow  to be a label on arcs.

  • Formally the transition function  of an -NFA is from Q x Σ∪{} to P (Q).

  • Nothing else changes: acceptance of w is still the existence of a path from the start state to an accept state with label w. But  can appear on arcs, and means the empty string (i.e., no visible contribution to w).


Example of an nfa
Example of an -NFA

0

1

q

r

s

0

1

“001” is accepted by the path

qsrqrs with label 001 = 001


1 1 finite automata4
1.1 Finite Automata

  • Deterministic FA

  • Non-Deterministic FA

  • NFA = DFA

  • -NFA

  • -NFA = NFA


Elimination of transitions
Elimination of -Transitions

  • -transitions are a convenience, but do not increase the power of FA's. To eliminate -transitions:

    • Compute the transitive closure of the -arcs only.

    • If a state p can reach state q by -arcs, and there is a transition from q to r on input a (not ), then add a transition from p to r on input a.

    • Make state p an accept state if p can reach some accept state q by -arcs.

    • Remove all -transitions.


Closure
-CLOSURE

  • -CLOSURE(q): all states reachable from q by a sequence …

    • q-CLOSURE(q);

    • p-CLOSURE(q) and r(p, )  r-CLOSURE(q)


Example4
Example

  • -CLOSURE(q)={q}, -CLOSURE(r)={r,s}, -CLOSURE(s)={r,s}

0

1

q

r

s

0

1


Example5
Example

  • -CLOSURE(q)={q}, -CLOSURE(r)={r,s}, -CLOSURE(s)={r,s}

  • Add (s, 0)={q}, (r, 1)={q}

0

1

q

r

s

0, 1

0, 1


Example6
Example

  • -CLOSURE(q)={q}, -CLOSURE(r)={r,s}, -CLOSURE(s)={r,s}

  • Add (s, 0)={q}, (r, 1)={q}

  • Add r into F as an accept state

0

1

q

r

s

0, 1

0, 1


Example7
Example

  • -CLOSURE(q)={q}, -CLOSURE(r)={r,s}, -CLOSURE(s)={r,s}

  • Add (s, 0)={q}, (r, 1)={q}

  • Add r into F as an accept state

  • Remove (s, )={r}, (r, )={s}

0

1

q

r

s

0, 1

0, 1


Summary of finite automata
Summary of Finite Automata

  • DFA, NFA, and -NFA are all equivalent.

-NFA  NFA  DFA

-elimination

subset construction


Example 1 21
Example 1.21

a

1

b

2

a,b

3

a


Assignment 1
Assignment 1

  • Exercise 1.4: (a)(b)(g)(i)(j)

  • Exercise 1.5: (b)(c)

  • Exercise 1.12


ad