Finite Automata Part Two

Similar documents
Finite Automata Part Two

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

Finite Automata Part One

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,

CS 154, Lecture 3: DFA NFA, Regular Expressions

Lecture 3: Nondeterministic Finite Automata

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Finite Automata Part One

Finite Automata Part One

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Fooling Sets and. Lecture 5

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Closure under the Regular Operations

CSC236 Week 11. Larry Zhang

Turing Machines Part III

CSE 105 THEORY OF COMPUTATION

Complexity Theory Part I

Decision, Computation and Language

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Announcements. Problem Set Four due Thursday at 7:00PM (right before the midterm).

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

Takeaway Notes: Finite State Automata

Nondeterministic Finite Automata

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

Nondeterminism. September 7, Nondeterminism

Nondeterministic finite automata

Intro to Theory of Computation

Turing Machines Part One

CSE 105 THEORY OF COMPUTATION

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

Concatenation. The concatenation of two languages L 1 and L 2

Finite Automata Part One

CS243, Logic and Computation Nondeterministic finite automata

Extended transition function of a DFA

Finite Automata (contd)

CSE 105 THEORY OF COMPUTATION

A Note on Turing Machine Design

CSE 105 Theory of Computation Professor Jeanne Ferrante

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Chapter Five: Nondeterministic Finite Automata

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

CSE 105 THEORY OF COMPUTATION

Non-deterministic Finite Automata (NFAs)

Nonregular Languages

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Theory of Computation (I) Yijia Chen Fudan University

Nondeterminism and Epsilon Transitions

CSE 105 THEORY OF COMPUTATION

CSC236 Week 10. Larry Zhang

CS 455/555: Finite automata

Nondeterministic Finite Automata

Nondeterministic Finite Automata and Regular Expressions

UNIT-III REGULAR LANGUAGES

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

Finite Automata. Mahesh Viswanathan

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

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

CSE 105 THEORY OF COMPUTATION

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

Theory of Computation

Deterministic Finite Automaton (DFA)

Theory of computation: initial remarks (Chapter 11)

CSE 105 THEORY OF COMPUTATION

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

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

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

CSC173 Workshop: 13 Sept. Notes

Recap from Last Time

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

Turing Machines Part Two

CPS 220 Theory of Computation REGULAR LANGUAGES

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

10. The GNFA method is used to show that

Finite Automata. Finite Automata

CS21 Decidability and Tractability

Automata and Languages

Turing Machines Part Three

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

Constructions on Finite Automata

MA/CSSE 474 Theory of Computation

Finite Automata and Regular languages

Turing Machines Part II

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

Context-Free Languages

Inf2A: Converting from NFAs to DFAs and Closure Properties

Tasks of lexer. CISC 5920: Compiler Construction Chapter 2 Lexical Analysis. Tokens and lexemes. Buffering

Mathematical Logic Part One

Course 4 Finite Automata/Finite State Machines

CS103 Handout 47 Spring 2018 Practice CS103 Final Exam V

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

CS 154 Introduction to Automata and Complexity Theory

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

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Compilers. Lexical analysis. Yannis Smaragdakis, U. Athens (original slides by Sam

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

CISC 4090 Theory of Computation

Transcription:

Finite Automata Part Two

Recap from Last Time

Old MacDonald Had a Symbol, Σ-eye-ε-ey, Oh! You may have noticed that we have several letter- E-ish symbols in CS103, which can get confusing! Here s a quick guide to remembering which is which: Typically, we use the symbol Σ to refer to an alphabet. The empty string is length 0 and is denoted ε. In set theory, use to say is an element of. In set theory, use to say is a subset of.

DFAs A DFA is a Deterministic Finite Automaton DFAs are the simplest type of automaton that we will see in this course.

Recognizing Languages with DFAs L = { w {a, b}* w contains aa as a substring } start q 0 b a a q 1 q 2 Σ b

DFAs A DFA is defned relative to some alphabet Σ. For each state in the DFA, there must be exactly one transition defned for each symbol in Σ. This is the deterministic part of DFA. There is a unique start state. There are zero or more accepting states.

New Stuf!

Which Which table table best best represents represents the the transitions transitions DFA transition for for the the DFA DFA shown shown below? function below? 1 0 start q 0 0 1 0 q 1 q 2 (A) 0 1 (B) 1 0 1 (C) 0 1 Σ Σ q 0 q 1 q 1 q 0 q 2 q 0 q 1 q 0 q 1 q 2 q 0 q 1 q 1 q 0 q 2 / / q 2 q 0 q 2 q 0 q 2 q 0 / / / Answer Answer at at PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then A, A, B, B, C, C, or or D (none (none of of the the above). above).

Tabular DFAs start 1 q 0 0 1 0 q 1 q 2 0 1 Σ 0 1 *q 0 q 1 q 0 These These stars stars indicate indicate accepting accepting states. states. q 1 q 2 * q2 q 0

Tabular DFAs start 1 q 0 0 1 0 q 1 q 2 0 1 Σ 0 1 *q 0 q 1 q 0 Since Since this this is is the the frst frst row, row, it's it's the the start start state. state. q 1 q 2 * q2 q 0

My Turn to Code Things Up! int ktransitiontable[knumstates][knumsymbols] = { {0, 0, 1, 3, 7, 1, }, }; bool kaccepttable[knumstates] = { false, true, true, }; bool SimulateDFA(string input) { int state = 0; for (char ch: input) { state = ktransitiontable[state][ch]; } return kaccepttable[state]; }

The Regular Languages

A language L is called a regular language if there exists a DFA D such that L( D) = L. If L is a language and ( L D) = L, we say that D recognizes the language L.

The Complement of a Language Given a language L Σ*, the complement of that language (denoted L) is the language of all strings in Σ* that aren't in L. Formally: L = Σ* - L

The Complement of a Language Given a language L Σ*, the complement of that language (denoted L) is the language of all strings in Σ* that aren't in L. Formally: L = Σ* - L L L Σ*

Complements of Regular Languages As we saw a few minutes ago, a regular language is a language accepted by some DFA. Question: If L is a regular language, is L necessarily a regular language? If the answer is yes, then if there is a way to construct a DFA for L, there must be some way to construct a DFA for L. If the answer is no, then some language L can be accepted by some DFA, but L cannot be accepted by any DFA.

Yep! input Computational Device for L Nope! Yep! input Computational Device for L Nope!

Complementing Regular Languages L = { w {a, b}* w contains aa as a substring } start q 0 b a b a q 1 q 2 L = { w {a, b}* w does not contain aa as a substring } start q 0 b a b a q 1 q 2 Σ Σ

More Elaborate DFAs L = { w {a, *, /}* w represents a C-style comment } Σ a, * q 5 Σ /, a start q 0 / q 1 * q 2 * a / q 4 a, / *

More Elaborate DFAs L = { w {a, *, /}* w doesn't represent a C-style comment } Σ a, * q 5 Σ /, a start q 0 q 0 / q 1 * q 2 * a / q 4 a, / *

Closure Properties Theorem: If L is a regular language, then L is also a regular language. As a result, we say that the regular languages are closed under complementation. L L Regular languages All languages

Time-Out For Announcements!

Additional Practice Looking to improve your performance in CS103? We ve released two handouts: Handout 31: How to Improve in CS103 Handout 32: Extra Practice Problems 2 Set aside a few minutes each day to get some additional practice. That will add up extremely quickly!

STANFORD S NATIONAL HACKATHON THIS WEEKEND FEB 16-18 HUANG ENGINEERING CENTER BEGINNERS WELCOME!

Ever felt you weren't good enough to be in STEM? Afraid of being "found out" because you don't think you belong? Learn how to combat Imposter Phenomenon at a very special workshop led by Dr. Nicole Cabrera Salazar! Lunch will be served. ~Wed. 2/14, 11:30 am - 1:30 pm, PAB 232~

Back to CS103!

NFAs

NFAs An NFA is a Nondeterministic Finite Automaton Structurally similar to a DFA, but represents a fundamental shift in how we'll think about computation.

(Non)determinism A model of computation is deterministic if at every point in the computation, there is exactly one choice that can make. The machine accepts if that series of choices leads to an accepting state. A model of computation is nondeterministic if the computing machine may have multiple decisions that it can make at one point. The machine accepts if any series of choices leads to an accepting state. (This sort of nondeterminism is technically called existential nondeterminism, the most philosophical-sounding term we ll introduce all quarter.)

A Simple NFA start q 1 0 q 1 1 q 2 0, 1 0 0, 1 q 0 has 0 has two two transitions defined defined on on!ꥣ!ꥣ 0, 1

A More Complex NFA start q 0 1 q 1 1 q 2 0, 1 If If a a NFA NFA needs needs to to make make a a transition transition when when no no transition transition exists, exists, the the automaton automaton dies dies and and that that particular particular path path does does not not accept. accept.

start 1 1 q 0 q 1 q 2 0, 1 As As with with DFAs, DFAs, the the language language of of an an NFA NFA N is is the the set set of of strings strings that that N accepts: accepts: L(N) L(N) = { w Σ* Σ* N accepts accepts w }. }. What What is is the the language language of of the the NFA NFA shown shown above? above? A. A. { 01011 01011 } B. B. { w {0, {0, 1}* 1}* w contains contains at at least least two two 1s 1s } C. C. { w {0, {0, 1}* 1}* w ends ends with with 11 11 } D. D. { w {0, {0, 1}* 1}* w ends ends with with 11 } E. E. None None of of these, these, or or two two or or more more of of these. these. Answer Answer at at PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then A, A,,, or or E. E.

NFA Acceptance An NFA N accepts a string w if there is some series of choices that lead to an accepting state. Consequently, an NFA N rejects a string w if no possible series of choices lead it into an accepting state. It's easier to show that an NFA does accept something than to show that it doesn't.

ε-transitions NFAs have a special type of transition called the ε-transition. An NFA may follow any number of ε-transitions at any time without consuming any input. start a q a 0 q 1 a q 2 ε q 0 3 ε b, ε q 4 b q 5 b

ε-transitions NFAs have a special type of transition called the ε-transition. An NFA may follow any number of ε-transitions at any time without consuming any input. NFAs are not required to follow ε-transitions. It's simply another option at the machine's disposal.

start 0 0 0 0 0 ε 1 ε 1 ε ε ε ε 1 1 1 Suppose Suppose we we run run the the above above NFA NFA on on the the string string 10110. 10110. How How many many of of the the following following statements statements are are true? true? There There is is at at least least one one computation computation that that fnishes fnishes in in an an accepting accepting state. state. There There is is at at least least one one computation computation that that fnishes fnishes in in a a rejecting rejecting state. state. There There is is at at least least one one computation computation that that dies. dies. This This NFA NFA accepts accepts 10110. 10110. This This NFA NFA rejects rejects 10110. 10110. Answer Answer at at PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then a a number. number.

Intuiting Nondeterminism Nondeterministic machines are a serious departure from physical computers. How can we build up an intuition for them? There are two particularly useful frameworks for interpreting nondeterminism: Perfect guessing Massive parallelism

Perfect Guessing We can view nondeterministic machines as having Magic Superpowers that enable them to guess choices that lead to an accepting state. If there is at least one choice that leads to an accepting state, the machine will guess it. If there are no choices, the machine guesses any one of the wrong guesses. No known physical analog for this style of computation this is totally new!

Massive Parallelism Σ start q₀ a q₁ b q₂ a q₃ a b a b a We're We're in in at at least least one one accepting accepting state, state, so so there's there's some some path path that that gets gets us us to to an an accepting accepting state. state. Therefore, Therefore, we we accept! accept!

Massive Parallelism An NFA can be thought of as a DFA that can be in many states at once. At each point in time, when the NFA needs to follow a transition, it tries all the options at the same time. (Here's a rigorous explanation about how this works; read this on your own time). Start of in the set of all states formed by taking the start state and including each state that can be reached by zero or more ε- transitions. When you read a symbol a in a set of states S: Form the set S of states that can be reached by following a single a transition from some state in S. Your new set of states is the set of states in S, plus the states reachable from S by following zero or more ε-transitions.

So What? Each intuition of nondeterminism is useful in a diferent setting: Perfect guessing is a great way to think about how to design a machine. Massive parallelism is a great way to test machines and has nice theoretical implications. Nondeterministic machines may not be feasible, but they give a great basis for interesting questions: Can any problem that can be solved by a nondeterministic machine be solved by a deterministic machine? Can any problem that can be solved by a nondeterministic machine be solved eficiently by a deterministic machine? The answers vary from automaton to automaton.

Designing NFAs

Designing NFAs When designing NFAs, embrace the nondeterminism! Good model: Guess-and-check: Is there some information that you'd really like to have? Have the machine nondeterministically guess that information. Then, have the machine deterministically check that the choice was correct. The guess phase corresponds to trying lots of diferent options. The check phase corresponds to fltering out bad guesses or wrong options.

Guess-and-Check L = { w {0, 1}* w ends in 010 or 101 } 0 0 1 0 start 0 1 1 0 0 1 0 1 1 1

Guess-and-Check L = { w {0, 1}* w ends in 010 or 101 } 1 0 start 0 1 Σ Nondeterministically Nondeterministically guess guess when when to to leave leave the the start start state. state. Deterministically Deterministically check check whether whether that that was was the the right right time time to to do do so. so. 0 1

Guess-and-Check L = { w {a, b, c}* at least one of a, b, or c is not in w } start a a, b b a c c b a a, c b b Σ c c a b, c c b a

Guess-and-Check L = { w {a, b, c}* at least one of a, b, or c is not in w } a, b start ε ε ε a, c b, c Nondeterministically Nondeterministically guess which character guess which character is missing. is missing. Deterministically check Deterministically check whether that whether that character is indeed character is indeed missing. missing.

Just how powerful are NFAs?