CSC236 Week 11. Larry Zhang

Similar documents
CSC236 Week 10. Larry Zhang

September 7, Formal Definition of a Nondeterministic Finite Automaton

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

Fooling Sets and. Lecture 5

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

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

Lecture 3: Nondeterministic Finite Automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS21 Decidability and Tractability

Chap. 1.2 NonDeterministic Finite Automata (NFA)

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,

Automata: a short introduction

Lecture 1: Finite State Automaton

Nondeterministic Finite Automata

Chapter 6: NFA Applications

CS 322 D: Formal languages and automata theory

Deterministic Finite Automaton (DFA)

Nondeterministic Finite Automata

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

Chapter Five: Nondeterministic Finite Automata

Finite Automata Part Two

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

Theory of Computation (I) Yijia Chen Fudan University

CS 154, Lecture 3: DFA NFA, Regular Expressions

Decision, Computation and Language

CS 208: Automata Theory and Logic

Theory of Computation Prof. Raghunath Tewari Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Nondeterministic finite automata

Nondeterministic Finite Automata

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

Nondeterministic Finite Automata and Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Finite Automata and Languages

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

Non-deterministic Finite Automata (NFAs)

Nondeterministic Finite Automata

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CMSC 330: Organization of Programming Languages

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

Formal Definition of Computation. August 28, 2013

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

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

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

Intro to Theory of Computation

CSE 105 THEORY OF COMPUTATION

Inf2A: Converting from NFAs to DFAs and Closure Properties

Classes and conversions

Mapping Reducibility. Human-aware Robotics. 2017/11/16 Chapter 5.3 in Sipser Ø Announcement:

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

Nonregular Languages

Nondeterminism. September 7, Nondeterminism

CSE 105 Theory of Computation Professor Jeanne Ferrante

Equivalence of DFAs and NFAs

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

Languages, regular languages, finite automata

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

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

2017/08/29 Chapter 1.2 in Sipser Ø Announcement:

CS 121, Section 2. Week of September 16, 2013

Lecture 4 Nondeterministic Finite Accepters

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Finite Automata (contd)

Uses of finite automata

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

CS243, Logic and Computation Nondeterministic finite automata

Constructions on Finite Automata

CS 455/555: Finite automata

Finite Automata and Regular languages

Nondeterminism and Epsilon Transitions

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

Chapter Two: Finite Automata

Computer Sciences Department

CMP 309: Automata Theory, Computability and Formal Languages. Adapted from the work of Andrej Bogdanov

Extended transition function of a DFA

Takeaway Notes: Finite State Automata

Regular Language Equivalence and DFA Minimization. Equivalence of Two Regular Languages DFA Minimization

CSE 105 THEORY OF COMPUTATION

Name: Student ID: Instructions:

CSC173 Workshop: 13 Sept. Notes

Automata and Languages

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

CSCI 2670 Introduction to Theory of Computing

Finite Automata. Finite Automata

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Harvard CS 121 and CSCI E-207 Lecture 4: NFAs vs. DFAs, Closure Properties

Theory of Computation

(Refer Slide Time: 0:21)

Finite Automata Part One

Incorrect reasoning about RL. Equivalence of NFA, DFA. Epsilon Closure. Proving equivalence. One direction is easy:

Computational Models Lecture 2 1

Theory of computation: initial remarks (Chapter 11)

CSE 105 THEORY OF COMPUTATION

Finite State Machines 2

Further discussion of Turing machines

Transcription:

CSC236 Week 11 Larry Zhang 1

Announcements Next week s lecture: Final exam review This week s tutorial: Exercises with DFAs PS9 will be out later this week s. 2

Recap Last week we learned about Deterministic Finite Automata. It is a model of the computation performed when the computer checks if a string belongs to a regular language. Every regular language can be recognized by a DFA with a finite number of states. An irregular languages would need an infinite number of states in the DFA, so it cannot be recognized by a computer efficiently. 3

Number of DFA States Normally, we would expect that the number of states needed by the DFA somehow reflects how complicated it is to describe the regular languages. But sometimes, similar languages require quite different numbers of states. For example, (0+1)(0+1)1(0+1)* all strings whose third symbol from the left is 1. 5 states needed by the DFA (Home exercise: draw the DFA) (0+1)*1(0+1)(0+1) all strings whose third symbol from the right is 1. 8 states needed by the DFA (Home exercise: draw the DFA) Hint: need to remember the last three symbols read, of which there are 8 possibilities. 4

Why more states? (0+1)(0+1)1(0+1)* vs (0+1)*1(0+1)(0+1) This has to do with how DFA works. Read string from the left to the right. It is easier to deal with what s on the left (making decisions with what has happened already) It is harder to deal with what s on the right (making decisions for the future!) For the second regex, we don t know when we are at the third-last symbol, so we have to be prepared for everything that could happen in three steps into the future, therefore needing more states. It would be nice to have a simpler model for this. 5

Nondeterministic Finite Automata (NFA) 6

Here is an NFA. What s different? From q0, reading symbol 1 leads to two possible transitions! q3 has no outgoing transition at all! Basically, scanning a given string will gives a set of multiple possible paths in the diagram, compared to only one path for DFA. (Nondeterministic) For NFAs, we say a string w is accepted if one of the possible paths got by scanning the string reaches the accepting state. The above NFA actually checks if the third-last symbol is 1. 7

Scan string 010110 Start from q0 Read 0, reach q0 Read 01, reach q0, or q1 Read 010, reach q0, or q2 Read 0101, reach q0, or q1, or q3 (accepting) Read 01011, reach q0, or q1, or q2, or nowhere (from q3) Read 010110, reach q0, or q2, or q3 (accepting) 8

Formal Definition of NFA 9

NFA: Formal Definition 10

one more thing... ε-transition Transition from one state to another without reading a symbol. q0 ε q1 If you are reaching q0, then you are reaching q1 for free (without needing to read a symbol)! In other words, reaching state q0 is equivalent to reaching the set of states {q0, q1} 11

another example q0 ε q1 ε q2 ε q3 Reaching q0 is equivalent to reaching the set {q0, q1, q2, q3}. Reaching q1 is equivalent to reaching the set {q1, q2}. Note: no free ε-transition from q1 back to q0 12

Exercise 13

Does this NFA accept abbb? Initial state s = q0 Actual initial set of states δ(s, ε) = {q0, q1, q2} δ(s, a) = {q3, q2} # ε-transition q3 to q2 δ(s, ab) = {q4, q5} δ(s, abb) = {q4, q5} δ(s, abbb) = {q4, q5} accepting because q4 is an accepting state 14

So, Regex, DFA, NFA, they all recognize regular languages. How are they related to each other? 15

Equivalence of Representations Let L be a languages over an alphabet. Then the following are equivalent. There is a regular expression that matches L. There is a DFA that accepts L There is an NFA with ε-transitions that accepts L There is an NFA without ε-transitions that accepts L 16

In other words Given a regex, we can construct a DFA that accepts the same language Given a regex, we can construct an NFA that accepts the same language Given a DFA, we can construct a regex that accepts the same language Given a DFA, we can construct an NFA that accepts the same language Given an NFA, we can construct a regex that accepts the same language Given an NFA we can construct a DFA that accepts the same language We now show how this is done. 17

Subset Construction an algorithm that converts NFA to DFA 18

Subset Construction Each state Q in the DFA represents a set of states in the NFA {q0,q2} The algorithm: Let Q0 = δ(s, ε), i.e., the set of states that reachable from initial NFA state s via zero or more ε-transitions Repeat until no more new DFA states are added For each state Q in the DFA, for each symbol x, determine the set R of NFAs that are reached from any NFA state in Q via symbol x. For each R from the last step, update R = δ(r, ε), which is the set of all NFA states reachable from some state in R via zero or more ε-transitions. 19

The initial state and accepting states of the DFA Initial state of the DFA: Q0 = δ(s, ε) Accepting states of the DFA: Any states that contains an accepting state of the NFA. 20

Example 21

Find the equivalent DFA for the following 4-state NFA old state symbol new state q0 0 q1 q0 1 q0 q0 ε q3 q1 0 q2 q2 ε q1 q2 1 q3 The initial state is q0; the accepting state is q3. 22

How many states in the DFA? 5 {q0, q3}, {q1}, {q1, q2}, {q3}, Which state is the initial state? Q0: {q0, q3} Which states are accepting states? any state that contains q3 {q0, q3} and {q3}. 23

The resulting DFA from subset construction old state symbol new state {q0, q3} 0 {q1} {q0, q3} 1 {q0, q3} Initial state: {q0, q3} Accepting states: {q0, q3}, {q3} 1 {q1} 0 {q1, q2} {q1} 1 {q1, q2} 0 {q1, q2} {q1, q2} 1 {q3} 0, 1 {q0,q3} 1 0 {q1} 0 {q3} 0 {q3} 1 0 0, 1 {q3} 1 {q1,q2} 0 1 24

25