 Download Presentation Theory of Computation

# Theory of Computation - PowerPoint PPT Presentation Download Presentation ## Theory of Computation

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Theory of Computation Lecture#03-08 Unit-I

2. 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

3. 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

4. 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

5. 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

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

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

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

9. 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}

10. 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?

11. 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.

12. 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?

13. 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.

14. 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?

15. 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.

16. “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

17. 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

18. Extended transition function • Given: a b c q0 q1 q2 q3 What is δ* (q0, abc) ? Unit-I

19. 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

20. 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

21. 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

22. 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

23. 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

24. 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

25. 1 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

26. a 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

27. 1 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

28. a 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

29. 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

30. 1 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

31. 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

32. 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

33. 0/1 q2 0/1 0/1 q0 q1 • Give a DFA M such that: L(M) = {x | x is a string of 0’s and 1’s and |x| >= 2} Unit-I

34. b/c 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

35. b/c 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

36. b 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

37. 0/1 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

38. 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.

39. 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

40. q2 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

41. 0/1 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

42. 0 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

43. 1 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

44. 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.

45. 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 q0q1q1q2 and the other one is q0q2q0q1. 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.

46. More Examples of NFA a b Start q0 q1 q2 b b 0-9 0-9 0-9 q1 q4 q6 0-9 . E 0-9 0-9 0-9 q0 q3 q5 Start 0-9 0-9 +,- +,- q2 q7 0-9 0-9

47. 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?

48. a/b/c 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

49. 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

50. 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