- By
**winka** - Follow User

- 230 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about 'Theory of Computation' - winka

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

Computer ???

- What is a computer?
- A computer is a machine that manipulates data according to a list of instructions.
- What does the computer do?
- Any thing that can be expressed with that list of instructions.

Unit-I

Computer ??? (Cont.)

- Is there anything that a computer cannot do?
- The efforts to answer to this question are started even before the creation of the computer !!
- The question leads us to the concept of Automata theory.

Unit-I

Automata theory

- The word “Automata“ is the plural of “automaton" which simply means any machine.
- automata theory is the study of abstract machines and problems they are able to solve.
- Automata theory is closely related to formal language theory as the automata are often classified by the class of formal languages they are able to recognize.

Unit-I

Abstract Machine

- An abstract machine, also called an abstract computer, is a theoretical model of a computer hardware or software system used in Automata theory.
- Abstraction of computing processes is used in both the computer science and computer engineering disciplines and usually assumes discrete timeparadigm.
- abstract machines are often used in thought experiments regarding computability or to analyze the complexity of algorithms

Unit-I

Finite Automata ( or Finite State Machines)

- This is the simplest kind of machine.
- We will study 3 types of Finite Automata:
- Deterministic Finite Automata (DFA)
- Non-deterministic Finite Automata (NFA)
- Finite Automata with -transitions (-NFA)

Deterministic Finite Automata (DFA)

- We have seen a simple example before:

1

on

start

off

1

There are some states and transitions (edges)

between the states. The edge labels tell when

we can move from one state to another.

Definition of DFA

- A DFA is a 5-tuple (Q, , , q0, F) where
- Q is a finite set of states
- is a finite input alphabet
- is the transition function mapping Q to Q
- q0 in Q is the initial state (only one)
- F Q is a set of final states (zero or more)

Definition of DFA

- For example:

1

on

start

off

1

Q is the set of states: {on, off}

is the set of input symbols: {1}

is the transitions: off 1 on; on 1 off

q0 is the initial state: off

F is the set of final states: {on}

Definition of DFA

- Another Example:

1

0

0

q2

q1

q0

start

1

0

1

We use double circle to specify a final state.

What are Q, , , q0 and F in this DFA?

Transition Table

We can also use a table to specify the transitions.

- For the previous example, the DFA is (Q,,,q0,F) whereQ = {q0,q1,q2}, = {0,1}, F = {q2} and is such that

Inputs

States

0

1

q0

q1

q0

q1

q2

q0

q2

q1

q0

Note that there is one transition only for each input

symbol from each state.

DFA Example

- Consider the DFA M=(Q,,,q0,F) where Q = {q0,q1,q2,q3}, = {0,1}, F = {q0} and is:

Inputs

1

q0

Start

q1

States

0

1

1

q0

q2

q1

0

0

0

0

q1

q3

q0

OR

1

q2

q0

q3

q3

q2

1

q3

q1

q2

We can use a transition table or a transition diagram to specify

the transitions. What input can take you to the final state in M?

Language of a DFA

- Given a DFA M, the language accepted (or recognized) by M is the set of all strings that, starting from the initial state, will reach one of the final states after the whole string is read.
- For example, the language accepted by the previous example is the set of all 0 and 1 strings with even number of 0’s and 1’s.

Class Discussion

0

0

1

q0

q1

Start

1

0

1

1

q0

q1

Start

0

0

1

0,1

1

0

q0

q1

q2

Start

What are the languages accepted by these DFA?

Class Discussion

- Construct a DFA that accepts a language L over = {0, 1} such that:
- L is the set of all strings which starts with ‘0’

and ends with 1’s.

(b) L is the set of all strings ending with “101”.

(c) L is the set of all strings containing no consecutive “1”s nor consecutive “0”s.

“Yields” relation

- Indicates a transition from one configuration of a DFA to the next configuration, which is equivalent to one step in a computation
- notation: (q0, abba) |= (q1,bba)
- |=n denotes a transition from one configuration of a DFA to another after n steps
- |=* denotes the reflexive, transitive closure of the relation |=, i.e., it denotes a transition from one configuration of a DFA to another after zero or more steps

Unit-I

Extended transition function

- The extended transition function is represented by:

δ* : Q * Q

- The * denotes a string instead of a single character
- Q will represent the state the automaton will be in after reading the entire string instead of a single character

Unit-I

Extended transition function

Let M = (Q, S, q0, d, A) be an FA. We can define the function d* : Q S * Q as follows:

- For any q Q, d* (q, ) = q
- For any y S * , a S, and q Q,

d* (q, ya) = d (d* (q, y) , a)

Unit-I

Computation

- Since a DFA is an abstract model of computation, we can now define mathematically what we mean by “computation”
- A computation is a sequence of transitions from one configuration to another
- A computation proceeds according to a finite set of rules or instructions -- the transition function (or program) of the DFA

Unit-I

Finite State Machines with output

- Moore Machine: Output depends on only current state.
- Mealy Machine : Output depends on current state as well as on input.

Unit-I

Accepting

Let M = (Q, S, q0, d, F) be an FA.

- A string w S*is accepted by M if

d*(q0, w) F

- The language accepted (or recognized) by M is the set of all strings on S that are accepted by M
- Formally:

L(M) = {w * : δ* (q0, w) F}

Unit-I

L = {awa : w {a,b}*}

a

a

q0

q1

q2

b

a,b

q3

This finite accepter accepts all and only the strings of the language given above. But note that there are two arcs out of q1 labeled a. How does the FA know which path to take on an a? It doesn’t; it has to magically guess right. Also, there are no arcs out of q2. So this FA is nondeterministic.

Unit-I

L = {awa : w {a,b}*}

a

b

a

a

q0

q1

q2

b

b

q3

This finite accepter accepts all and only the strings of the language given above. This FA is Deterministic.

Unit-I

0

q1

q0

1

0

- The finite control can be described by a transition diagram:
- Example #1:

1 0 0 1 1

q0 q0 q1 q0 q0 q0

- One state is final/accepting, all others are rejecting.
- The above DFA accepts those strings that contain an even number of 0’s

Unit-I

a/b/c

a

c

c

q0

q1

q2

b

b

- Example #2:

a c c c b accepted

q0 q0 q1 q2 q2 q2

a a crejected

q0 q0 q0 q1

- Accepts those strings that contain at least two c’s

Unit-I

0

q1

q0

1

0

- For example #1:

Q = {q0, q1}

Σ = {0, 1}

Start state is q0

F = {q0}

δ:

0 1

q0 q1 q0

q1 q0 q1

Unit-I

a/b/c

a

c

c

q0

q1

q2

b

b

- For example #2:

Q = {q0, q1, q2}

Σ = {a, b, c}

Start state is q0

F = {q2}

δ: a b c

q0 q0 q0 q1

q1 q1 q1 q2

q2 q2 q2 q2

- Since δ is a function, at each step M has exactly one option.
- It follows that for a given string, there is exactly one computation.

Unit-I

Extension of δ to Strings

δ^ : (Q x Σ*) –> Q

δ^(q,w) – The state entered after reading string w having started in state q.

Formally:

1) δ^(q, ε) = q, and

2) For all w in Σ* and a in Σ

δ^(q,wa) = δ (δ^(q,w), a)

Unit-I

0

q1

q0

1

0

- Recall Example #1:
- What is δ^(q0, 011)? Informally, it is the state entered by M after processing 011 having started in state q0.
- Formally:

δ^(q0, 011) = δ (δ^(q0,01), 1)

= δ (δ ( δ(q0,0), 1), 1)

= δ (δ (q1, 1), 1)

= δ (q1, 1)

= q1

- Is 011 accepted? No, since δ^(q0, 011) = q1 is not a final state.

Unit-I

Definitions for DFAs

- Let M = (Q, Σ, δ,q0,F) be a DFA and let w be in Σ*. Then w is accepted by M iff δ^(q0,w) = p for some state p in F.
- Let M = (Q, Σ, δ,q0,F) be a DFA. Then the language accepted by M is the set:

L(M) = {w | w is in Σ* and δ^(q0,w) is in F}

- Another equivalent definition:

L(M) = {w | w is in Σ* and w is accepted by M}

- Let L be a language. Then L is a regular language iff there exists a DFA M such that L = L(M).
- Let M1 = (Q1, Σ1, δ1, q0, F1) and M2 = (Q2, Σ2, δ2, p0, F2) be DFAs. Then M1 and M2 are equivalent iff L(M1) = L(M2).

Unit-I

Notes:

- A DFA M = (Q, Σ, δ,q0,F) partitions the set Σ* into two sets: L(M) and

Σ* - L(M).

- If L = L(M) then L is a subset of L(M) and L(M) is a subset of L.
- Similarly, if L(M1) = L(M2) then L(M1) is a subset of L(M2) and L(M2) is a subset of L(M1).
- Some languages are regular, others are not. For example, if

L1 = {x | x is a string of 0's and 1's containing an even number of 1's} and

L2 = {x | x = 0n1n for some n >= 0}

then L1 is regular but L2 is not.

- Questions:
- How do we determine whether or not a given language is regular?
- How could a program “simulate” a DFA?

Unit-I

a/b/c

q0

q1

a

a

q2

b/c

- Give a DFA M such that:

L(M) = {x | x is a string of (zero or more) a’s, b’s and c’s such

that x does not contain the substring aa}

Unit-I

a

a/b/c

q3

a

a

b

q0

q1

q2

c

b/c

- Give a DFA M such that:

L(M) = {x | x is a string of a’s, b’s and c’s such that x

contains the substring aba}

Unit-I

a

b

b

a

q4

q1

q5

q2

q6

q3

q7

b

a

b

a/b

a

q0

a

b

a

b

a

- Give a DFA M such that:

L(M) = {x | x is a string of a’s and b’s such that x

contains both aa and bb}

Unit-I

0/1

0/1

q1

q0

q0

q0

q1

0/1

0/1

q0

- Let Σ = {0, 1}. Give DFAs for {}, {ε}, Σ*, and Σ+.

For {}: For {ε}:

For Σ*: For Σ+:

0/1

Unit-I

Non-deterministic FA (NFA)

- For each state, zero, one or more transitions are allowed on the same input symbol.
- An input is accepted if there is a path leading to a final state.

Nondeterministic Finite StateAutomata (NFA)

- An NFA is a five-tuple:

M = (Q, Σ, δ, q0, F)

Q A finite set of states

Σ A finite input alphabet

q0 The initial/starting state, q0 is in Q

F A set of final/accepting states, which is a subset of Q

δ A transition function, which is a total function from Q x Σ to 2Q

δ: (Q x Σ) –>2Q -2Q is the power set of Q, the set of all subsets of Q δ(q,s) -The set of all states p such that there is a transition

labeled s from q to p

δ(q,s) is a function from Q x S to 2Q (but not to Q)

Unit-I

0/1

0

1

0

- Example #1: some 0’s followed by some 1’s

Q = {q0, q1, q2}

Σ = {0, 1}

Start state is q0

F = {q2}

δ: 0 1

q0

q1

q2

1

q0

q1

Unit-I

0/1

0

0

q0

q3

1

0/1

q4

q2

q1

- Example #2: pair of 0’s or pair of 1’s

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

Σ = {0, 1}

Start state is q0

F = {q2, q4}

δ: 0 1

q0

q1

q2

q3

q4

1

Unit-I

1

0

- Determining if a given NFA (example #2) accepts a given string (001) can be done algorithmically:

q0 q0 q0 q0

q3 q3 q1

q4q4accepted

- Each level will have at most n states

Unit-I

0

0

- Another example (010):

q0 q0 q0 q0

q3 q1 q3

not accepted

- All paths have been explored, and none lead to an accepting state.

Unit-I

An Example of NFA

In this NFA (Q,,,q0,F), Q = {q0,q1,q2}, = {0,1},

F = {q2} and is:

Start

q1

0

Inputs

1

States

0

1

q0

q0

1

OR

{q1,q2}

q1

{q1 }

{q2 }

0

q2

1

{q0 }

q2

Note that each transition can lead to a set of states,

which can be empty.

Language of an NFA

- Given an NFA M, the language recognized by M is the set of all strings that, starting from the initial state, has at least one path reaching a final state after the whole string is read.
- Consider the previous example:
- For input “101”, one path is q0q1q1q2 and the other one is q0q2q0q1. Since q2 is a final state, so “101” is accepted. For input “1010”, none of its paths can reach a final state, so it is rejected.

Class Discussion

- Consider the language L that consists of all the strings over = {0, 1} such that the third last symbol is a “1”.

(a) Construct a DFA for L.

(b) Construct an NFA for L.

Is NFA more powerful than DFA?

a/b/c

q2

a

b

q0

q1

- Let Σ = {a, b, c}. Give an NFA M that accepts:

L = {x | x is in Σ* and x contains ab}

Is L a subset of L(M)?

Is L(M) a subset of L?

- Is an NFA necessary? Could a DFA accept L? Try and give an equivalent DFA as an exercise.
- Designing NFAs is not a typical task.

Unit-I

Nondeterminism

A finite automaton is deterministic if:

from every node there is exactly one arc labeled for each character in the alphabet of the language. But in case of Non – deterministic from every node more that one transition can take place.

Unit-I

L = {ambn : m, n 0}

a

b

a

q0

q1

q2

b

a,b

Does this automaton correspond to (represent, accept) the above language? Is it deterministic?

Unit-I

b

a,b

b

a

Some exercises

q0

q1

q2

Use set notation to describe the language accepted by the above DFA

Unit-I

Use set notation to describe the language

accepted by the following DFA.

b

a

b

c

c

a

a,b,c

b,c

a

Can you give a DFA that accepts the

complement of this language?

Unit-I

NDFA

Differences between a DFA and an NDFA:

(1) in an NDFA, the range of is in the powerset of Q (instead of just Q), so that from the current state, upon reading a symbol:

(a) more than one state might be the next state of the NDFA, or

(b) no state may be defined as the next state of the NDFA, and

(2) -moves are possible; that is, a transition from one state to another may occur without reading a symbol from the input string.

Unit-I

NDFA = DFA

One kind of automaton is more powerful than another if it can accept and reject some kinds of languages that the other cannot.

Two finite accepters are equivalent if both accept the same language, that is,

L(M1) = L(M2)

As mentioned previously, we can always find an equivalent DFA for any given NDFA.

Therefore, NDFA’s are no more powerful than DFA’s.

Unit-I

DFA and NFA

- Is NFA more powerful than DFA?
- NO! NFA is equivalent to DFA.

Trivial

DFA

NFA

Constructive

Proof

Constructing DFA from NFA

- Given any NFA M=(Q,,,q0,F)recognizing a language L over , we can construct a DFA N=(Q’, ,’,q0’,F’) which also recognizes L:
- Q’ = set of all subsets of Q
- e.g., if Q = {q0, q1}, Q’ = {{}, {q0}, {q1}, {q0, q1}}
- q0’ = {q0}
- F’ = set of all states in Q’ containing a final state of M
- ’({q1,q2, … qi}, a) = (q1,a) (q2,a) ... (qi,a)

a state in N

a state in M

NDFA DFA

- Create a graph GD with vertex {q0}. Identify this vertex as the initial vertex.
- OK; here it is:

{q0}

Unit-I

NDFA DFA

- Repeat the following steps until no more edges are missing:
- Take any vertex {qi, qj, …, qk} of GD that has no outgoing edge for some a .
- OK. Vertex q0 in our new DFA has no outgoing edge for a yet.
- Compute δ* (qi, a), δ* (qj, a), …, δ* (qk, a).
- OK. From q0 in our NDFA, upon reading an a the extended transition function leaves us in state q1, or q2 via a “free” lambda-move.

Unit-I

NDFA DFA

- Then form the union of all these δ*, yielding the set {ql, qm, …, qn}.
- So our new DFA will have a state labeled {q1, q2}.
- Create a vertex for GD labeled {ql, qm, …, qn} if it does not already exist.
- So create a vertex for our new DFA and label it {q1, q2}.
- Add to GD an edge from {qi, qj, …, qk} to {ql, qm, …, qn} and label it with a.
- So add a transition labeled a to {q1, q2} from q0.

Unit-I

NDFA DFA

- Repeat the following steps until no more edges are missing:
- Take any vertex {qi, qj, …, qk} of GD that has no outgoing edge for some a .
- OK. Vertex q0 in our new DFA has no outgoing edge for b yet.
- Compute δ* (qi, b), δ* (qj, b), …, δ* (qk, b).
- Well, there is no transition specified in our NDFA from state q0 upon reading a b.Therefore, δ* ({q0}, b) = .

Unit-I

NDFA DFA

- Then form the union of all these δ*, yielding the set {ql, qm, …, qn}.
- So our new DFA will have a state labeled .
- Create a vertex for GD labeled {ql, qm, …, qn} if it does not already exist.
- So create a vertex for our new DFA and label it .
- Add to GD an edge from {qi, qj, …, qk} to {ql, qm, …, qn} and label it with a.
- So add a transition labeled b to from q0.

Unit-I

NDFA DFA

So now we have:

{q0}

{q1, q2}

b

a

Any state labeled represents an impossible move and thus is a non-final trap state.

a, b

Unit-I

NDFA DFA

- Repeat the following steps until no more edges are missing:
- Take any vertex {qi, qj, …, qk} of GD that has no outgoing edge for some a .
- OK. Vertex {q1, q2} in our new DFA has no outgoing edge for a yet.
- Compute δ* (qi, b), δ* (qj, b), …, δ* (qk, b).
- OK. From q1 in our NDFA, upon reading an a the extended transition function leaves us in state q1, or q2 via a “free” lambda-move.From q2 in our NDFA, upon reading an a there is no specified transition.

Unit-I

NDFA DFA

- Then form the union of all these δ*, yielding the set {ql, qm, …, qn}.
- The union is {q1, q2} .
- Create a vertex for GD labeled {ql, qm, …, qn} if it does not already exist.
- It does.
- Add to GD an edge from {qi, qj, …, qk} to {ql, qm, …, qn} and label it with a.
- So add a transition labeled a to {q1, q2} from {q1, q2} .

Unit-I

NDFA DFA

- Repeat the following steps until no more edges are missing:
- Take any vertex {qi, qj, …, qk} of GD that has no outgoing edge for some a .
- OK. Vertex {q1, q2} in our new DFA has no outgoing edge for b yet.
- Compute δ* (qi, b), δ* (qj, b), …, δ* (qk, b).
- OK. From q2 in our NDFA, upon reading a b the extended transition function leaves us in state q0. From q1 in our NDFA, upon reading a b there is no specified transition. However, we can make a free lambda-move to q2, and thence to q0.

Unit-I

NDFA DFA

- Then form the union of all these δ*, yielding the set {ql, qm, …, qn}.
- The union is {q1, q2} .
- Create a vertex for GD labeled {ql, qm, …, qn} if it does not already exist.
- It does.
- Add to GD an edge from {qi, qj, …, qk} to {ql, qm, …, qn} and label it with a.
- So add a transition labeled b to q0 from {q1, q2} .

Unit-I

NDFA DFA

- Exit from loop.
- Every state of GD whose label contains and qf FN is identified as a final vertex.
- OK. State q1 in the NDFA is a final state, so state {q1, q2} in the DFA will be a final state.
- If MN accepts , the vertex q0 in GD is also made a final vertex.

Unit-I

An Example of NFA DFA

- Consider a simple NFA:
- Construct a corresponding DFA:

0

1

0

q0

q1

1

Start

1

1

Start

{q1}

{q0}

1

0

0

{q0, q1}

{}

1,0

1,0

Minimal DFA’s

Two states p and q of a DFA are called indistinguishable if

* (p, w) F implies * (q, w) F ,

and

* (p, w) F implies * (q, w) F ,

for all w *.

If there exists some string w * such that

* (p, w) F

and

* (q, w) F

or vice versa, then the states p and q are said to be distinguishable by string w.

Unit-I

The “Mark” procedure

This procedure marks all pairs of distinguishable states.

1. Remove all inaccessible states.

2. Consider all pairs of states (p, q). If p F and q F or vice versa, mark the pair (p, q) as distinguishable.

3. Repeat the following step until no previously unmarked pairs are marked:

For all pairs (p, q) and all a , compute (p, a) = pa and (q, a) = qa. If the pair (pa, qa) is marked as distinguishable, mark (p, q) as distinguishable.

Unit-I

The “Reduce” procedure

Given a DFA M = (Q, , , q0, F), we construct a reduced DFA M’ = (Q’, , ’, q0’, F’) as follows:

1. Use procedure Mark to find all pairs of distinguishable states. Then from this find the sets of indistinguishable states by partitioning the state set Q of the DFA into disjoint subsets {qi, qj, …, qk}, {ql, qm, …, qn}, …, such that any q Q occurs in exactly one of these subsets, that elements in each subset are indistinguishable, and that any two elements from different subsets are distinguishable.

Unit-I

The “Reduce” procedure, cont.

2. For each set {qi, qj, …, qk} of such indistinguishable states, create a state labeled ij…k for M.

3. For each transition rule of the form (qr, a) = qp, find the sets to which qr and qp belong. If qr {qi, qj, …, qk} and qp {ql, qm, …, qn}, add to ’ a rule ’ (ij…k, a) = lm…n.

4. The initial state q0’ is that state of M’ whose label includes the 0.

5. F’ is the set of all the states whose label contains i such that qi F.

Unit-I

Theorem 2.4

Given any DFA M, application of the procedure Reduce yields another DFA M’ such that

L(M) = L(M’)

Furthermore, M’ is minimal in the sense that there is no other DFA with a smaller number of states which also accepts L(M).

Unit-I

Minimal DFA’s

What are the distinguishable pairs?

Mark step 2 gives (q0, q4), (q1, q4), (q2, q4) and (q3, q4).

Step 3 computes (q1, 1) = q4 and (q0, 1) = q3. Since (q3, q4) is a distinguishable pair, (q0, q1) is also marked as a distinguishable pair. Eventually the pairs (q0, q1), (q0, q2), (q0, q3), (q0, q4), (q1, q4), (q2, q4) and (q3, q4) are marked as distinguishable.

The remaining pairs, (q1, q2), (q1, q3), and (q2, q3) are undistinguishable.

The states are partitioned into the sets {q0}, {q1, q2, q3}, and {q4}.

Unit-I

Minimum number of states in an FA

If there are n distinguishable strings in a language, then there must be at least n states in the finite automata that accepts it.

The FA has no memory, other than the current state.

This puts a lower bound on the number of states in a FA recognizing a language.

Unit-I

For

Equivalence of DFA and NFA, refer page no 33

FA’s with ε-transitions, refer page no. 43

Equivalence and minimization of DFA, refer page no. 118

All from Lecture Notes#01

Unit-I

Unit-I

Download Presentation

Connecting to Server..