Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Similar documents
Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

Introduction to Turing Machines. Reading: Chapters 8 & 9

CS21 Decidability and Tractability

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Chapter 3: The Church-Turing Thesis

An example of a decidable language that is not a CFL Implementation-level description of a TM State diagram of TM

CSCC63 Worksheet Turing Machines

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

jflap demo Regular expressions Pumping lemma Turing Machines Sections 12.4 and 12.5 in the text

Turing Machines A Turing Machine is a 7-tuple, (Q, Σ, Γ, δ, q0, qaccept, qreject), where Q, Σ, Γ are all finite

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Nondeterministic Finite Automata

An example of a decidable language that is not a CFL Implementation-level description of a TM State diagram of TM

Introduction to Turing Machines

CSE 105 THEORY OF COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

The Church-Turing Thesis

ECS 120 Lesson 15 Turing Machines, Pt. 1

Chapter 6: NFA Applications

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Deterministic Finite Automata (DFAs)

Automata and Languages

CSC236 Week 11. Larry Zhang

Deterministic Finite Automata (DFAs)

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

More Turing Machines. CS154 Chris Pollett Mar 15, 2006.

Chapter Five: Nondeterministic Finite Automata

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

1 Unrestricted Computation

CSE 105 THEORY OF COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Pushdown Automata. Reading: Chapter 6

Theory of Computation

Most General computer?

Lecture 1: Finite State Automaton

CSE 105 THEORY OF COMPUTATION

Turing Machines Part II

Finite Automata and Regular languages

Undecidable Problems and Reducibility

Examples of Regular Expressions. Finite Automata vs. Regular Expressions. Example of Using flex. Application

Theory of Computation (IX) Yijia Chen Fudan University

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

The Turing machine model of computation

Finite Automata. Finite Automata

CS 525 Proof of Theorems 3.13 and 3.15

Part I: Definitions and Properties

Foundations of

Turing Machines. 22c:135 Theory of Computation. Tape of a Turing Machine (TM) TM versus FA, PDA

Equivalence of TMs and Multitape TMs. Theorem 3.13 and Corollary 3.15 By: Joseph Lauman

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

V Honors Theory of Computation

Turing machines COMS Ashley Montanaro 21 March Department of Computer Science, University of Bristol Bristol, UK

CS4026 Formal Models of Computation

Extended transition function of a DFA

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CSE 2001: Introduction to Theory of Computation Fall Suprakash Datta

Lecture 3: Nondeterministic Finite Automata

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

SE 3310b Theoretical Foundations of Software Engineering. Turing Machines. Aleksander Essex

Finite Automata. Mahesh Viswanathan

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Deterministic Finite Automata (DFAs)

Turing machines and linear bounded automata

INF Introduction and Regular Languages. Daniel Lupp. 18th January University of Oslo. Department of Informatics. Universitetet i Oslo

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Theory of Computation (I) Yijia Chen Fudan University

COMPARATIVE ANALYSIS ON TURING MACHINE AND QUANTUM TURING MACHINE

Non-deterministic Finite Automata (NFAs)

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

Computational Models Lecture 2 1

Chapter 1 - Time and Space Complexity. deterministic and non-deterministic Turing machine time and space complexity classes P, NP, PSPACE, NPSPACE

Languages, regular languages, finite automata

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Chapter 8. Turing Machine (TMs)

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Finite Automata. Seungjin Choi

CS243, Logic and Computation Nondeterministic finite automata

Computability and Complexity

Griffith University 3130CIT Theory of Computation (Based on slides by Harald Søndergaard of The University of Melbourne) Turing Machines 9-0

Turing Machines Part III

TURING MAHINES

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

FORMAL LANGUAGES AND AUTOMATA THEORY

Turing machines and linear bounded automata

Turing machines and linear bounded automata

1 Showing Recognizability

Please give details of your answer. A direct answer without explanation is not counted.

September 7, Formal Definition of a Nondeterministic Finite Automaton

Theory of Computation Turing Machine and Pushdown Automata

Transcription:

Recap DFA,NFA, DTM Slides by Prof. Debasis Mitra, FIT. 1

Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { {, } } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language, or, {strings starting with 0} an infinite language Σ* is a special language with all possible strings on Σ 2

Hierarchy of languages Non-Recursively Enumerable Languages Recursively Enumerable Languages Recursive Languages Context-Free Languages Regular Languages 3

Deterministic Finite State Automata (DFA) 0 1 1 0 0.. Finite Control One-way, infinite tape, broken into cells One-way, read-only tape head. Finite control, i.e., a program, containing the position of the read head, current symbol being scanned, and the current state. A string is placed on the tape, read head is positioned at the left end, and the DFA will read the string one symbol at a time until all symbols have been read. The DFA will then either accept or reject. 4

The finite control can be described by a transition diagram: Example #1: 1 q 0 q 1 0 0 1 1 0 0 1 1 q 0 q 0 q 1 q 0 q 0 q 0 One state is final/accepting, all others are rejecting. Accepts strings that contain an even number of 0 s 5

Example #2: a a a/b/c c c q 0 q 2 q 1 b b a c c c b accepted q 0 q 0 q 1 q 2 q 2 q 2 a a c rejected q 0 q 0 q 0 q 1 Accepts those strings that contain at least two c s 6

Formal Definition of a DFA A DFA is a five-tuple: M = (Q, Σ, δ, q 0, F) Q A finite set of states Σ A finite input alphabet q 0 The initial/starting state, q 0 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 Q δ: (Q x Σ) > Q δ is defined for any q in Q and s in Σ, and δ(q,s) = q is equal to some state q in Q, could be q =q Intuitively, δ(q,s) is the state entered by M after reading symbol s while in state q. 7

For example #1: Q = {q 0, q 1 } Σ = {0, 1} Start state is q 0 F = {q 0 } 1 0 q 0 q 1 0 1 δ: 0 1 q 0 q 1 q 0 q 1 q 0 q 1 8

For example #2: Q = {q 0, q 1, q 2 } Σ = {a, b, c} Start state is q 0 F = {q 2 } a a a/b/c c c q 0 q 2 q 1 b b δ: a b c q 0 q 0 q 0 q 1 q 1 q 1 q 1 q 2 q 2 q 2 q 2 q 2 Since δ is a function, at each step M has exactly one option. It follows that for a given string, there is exactly one computation. 9

Definitions for DFAs Let M = (Q, Σ, δ,q 0,F) be a DFA and let w be in Σ *. Then w is accepted by M iff δ(q 0,w) = p for some state p in F. Let M = (Q, Σ, δ,q 0,F) be a DFA. Then the language accepted by M is the set: L(M) = {w w is in Σ * and δ(q 0,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 M 1 = (Q 1, Σ 1, δ 1, q 0, F 1 ) and M 2 = (Q 2, Σ 2, δ 2, p 0, F 2 ) be DFAs. Then M 1 and M 2 are equivalent iff L(M 1 ) = L(M 2 ). 10

Nondeterministic Finite State Automata (NFA) An NFA is a five-tuple: M = (Q, Σ, δ, q 0, F) Q A finite set of states Σ A finite input alphabet q 0 The initial/starting state, q 0 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 2 Q δ: (Q x Σ) > 2 Q :2 Q 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 2 Q (but not only to Q) 11

NFA State Diagram L = Strings over {a,b} ending in bb a b q0 b q1 b q2 Q = {q0,q1,q2} Σ = {a,b} F = {q2} d a b q0 {q0} {q0,q1} q1 f {q2} q2 f f 12

L = {a i b i i n} a0 a a1 a a2 a a3 a an b1 b b b b b b b b2 b3 bn This construction cannot be generalized to recognize because the machine will have infinite number of states. 13

Example #2: pair of 0 s or pair of 1 s as substring Q = {q 0, q 1, q 2, q 3, q 4 } Σ = {0, 1} Start state is q 0 F = {q 2, q 4 } δ: 0 1 q 0 {q 0, q 3 } {q 0, q 1 } 0/1 q 0 0 0 q 3 q 4 1 1 q 1 q 2 0/1 0/1 q 1 q 2 {} {q 2 } {q 2 } {q 2 } q 3 q 4 {q 4 } {} {q 4 } {q 4 } 14

Let Σ = {a, b, c}. Give an NFA M that accepts: L = {x x is in Σ * and x contains ab} a/b/c a/b/c a b q 0 q 2 q 1 Is L a subset of L(M)? Or, does M accepts all string in L? Is L(M) a subset of L? Or, does M rejects all strings not in L? Is an NFA necessary? Could a DFA accept L? Try and give an equivalent DFA as an exercise. Designing NFAs is not as trivial as it seems: easy to create bug accepting string outside language 15

Let Σ = {a, b}. Give an NFA M that accepts: L = {x x is in Σ * and the third to the last symbol in x is b} a/b q 0 b q 1 a/b q 2 a/b q 3 Is L a subset of L(M)? Is L(M) a subset of L? Give an equivalent DFA as an exercise. 16

Definitions for NFAs Let M = (Q, Σ, δ,q 0,F) be an NFA and let w be in Σ *. Then w is accepted by M iff δ({q 0 }, w) contains at least one state in F. Let M = (Q, Σ, δ,q 0,F) be an NFA. Then the language accepted by M is the set: L(M) = {w w is in Σ * and δ({q 0 },w) contains at least one state in F} Another equivalent definition: L(M) = {w w is in Σ * and w is accepted by M} 17

Equivalence of DFAs and NFAs Do DFAs and NFAs accept the same class of languages? Is there a language L that is accepted by a DFA, but not by any NFA? Is there a language L that is accepted by an NFA, but not by any DFA? Observation: Every DFA is an NFA, DFA is only restricted NFA. Therefore, if L is a regular language then there exists an NFA M such that L = L(M). It follows that NFAs accept all regular languages. But do NFAs accept more? 18

Lemma 2: Let M be an NFA. Then there exists a DFA M such that L(M) = L(M ). Proof: (sketch) Let M = (Q, Σ, δ,q 0,F). Define a DFA M = (Q, Σ, δ,q 0,F ) as: Q = 2 Q Each state in M corresponds to a = {Q 0, Q 1,,} subset of states from M where Q u = [q i0, q i1, q ij ] F = {Q u Q u contains at least one state in F} q 0 = [q 0 ] δ (Q u, a) = Q v iff δ(q u, a) = Q v 19

Example: empty string or start and end with 0 Q = {q 0, q 1 } Σ = {0, 1} Start state is q 0 F = {q 1 } q 0 0 0 0/1 q 1 δ: 0 1 q 0 {q 1 } {} q 1 {q 0, q 1 } {q 1 } 20

Construct DFA M as follows: [ ] 0/1 1 0 [q 0 ] 0 1 [q 1 ] [q 0 q 1 ] 1 δ({q 0 }, 0) = {q 1 } => δ ([q 0 ], 0) = [q 1 ] δ({q 0 }, 1) = {} => δ ([q 0 ], 1) = [ ] δ({q 1 }, 0) = {q 0, q 1 } => δ ([q 1 ], 0) = [q 0 q 1 ] δ({q 1 }, 1) = {q 1 } => δ ([q 1 ], 1) = [q 1 ] δ({q 0, q 1 }, 0) = {q 0, q 1 } => δ ([q 0 q 1 ], 0) = [q 0 q 1 ] δ({q 0, q 1 }, 1) = {q 1 } => δ ([q 0 q 1 ], 1) = [q 1 ] δ({}, 0) = {} => δ ([ ], 0) = [ ] δ({}, 1) = {} => δ ([ ], 1) = [ ] 0 21

Note: Suppose R = {} δ(r, 0) = δ(δ(r, ε), 0) = δ(r, 0) = δ(q, 0) = {} Since R = {} Exercise - Convert the following NFA to a DFA: Q = {q 0, q 1, q 2 } δ: 0 1 Σ = {0, 1} Start state is q 0 q 0 F = {q 0 } q 1 {q 0, q 1 } { } {q 1 } {q 2 } q 2 {q 2 } {q 2 } 22

Problem: Third symbol from last is 1 0/1 1 0/1 0/1 q 0 q 2 q 3 q 1 Now, can you convert this NFA to a DFA? 23

Deterministic Turing Machine (DTM).. B B 0 1 1 0 0 B B.. Finite Control Two-way, infinite tape, broken into cells, each containing one symbol. Two-way, read/write tape head. An input string is placed on the tape, padded to the left and right infinitely with blanks, read/write head is positioned at the left end of input string. Finite control, i.e., a program, containing the position of the read head, current symbol being scanned, and the current state. In one move, depending on the current state and the current symbol being scanned, the TM 1) changes state, 2) prints a symbol over the cell being scanned, and 3) moves its tape head one cell left or right. Many modifications possible, but Church-Turing declares equivalence of all. 24

Formal Definition of a DTM A DTM is a seven-tuple: M = (Q, Σ, Γ, δ, q 0, B, F) Q A finite set of states Σ A finite input alphabet, which is a subset of Γ {B} Γ A finite tape alphabet, which is a strict superset of Σ B A distinguished blank symbol, which is in Γ q 0 The initial/starting state, q 0 is in Q F A set of final/accepting states, which is a subset of Q δ A next-move function, which is a mapping (i.e., may be undefined) from Q x Γ > Q x Γ x {L,R} Intuitively, δ(q,s) specifies the next state, symbol to be written, and the direction of tape head movement by M after reading symbol s while in state q. 25

Turing Machine The idea behind digital computers may be explained by saying that these machines are intended to carry out any operations which could be done by a human computer. The human computer is supposed to be following fixed rules; he has no authority to deviate from them in any detail. We may suppose that these rules are supplied in a book, which is altered whenever he is put on to a new job. He has also an unlimited supply of paper on which he does his calculations. Alan Turing 26

K-tape Turing Machine finite control q 0 work tapes input tape 0 1 1 0 0 1 1 1 0 1 0 0 0 1 1 0 0 1 k read/write heads 0 1 1 0 0 1 1 1 0 1 0 0 0 27

K-tape Turing Machine Input written on left-most squares of tape #1 Rest of squares are blank on all tapes At each point, take a step determined by current k symbols being read on k tapes current state of finite control A step consists of writing k new symbols on k tapes moving each of k read/write heads left or right changing state 28

K-tape Turing Machine Theorem: Every k-tape TM has an equivalent single-tape TM. Proof: Simulate k-tape TM on a 1-tape TM. a b a b a a b b c d (input tape)......... add new symbol x for each old x marks location of virtual heads # a b a b # a a # b b c d #... 29

Theorem: The time taken by the one-tape TM to simulate n moves of the k-tape TM is O(n 2 ). Proof on page 17 of text (thm 1.6) 30