NFAs, DFAs, and regular expressions

Slides:



Advertisements
Similar presentations
CSE 202 – Formal Languages and Automata Theory 1 REGULAR LANGUAGE.
Advertisements

Transparency No. 2-1 Formal Language and Automata Theory Homework 3.
Regular expressions Regular languages Sipser 1.3 (pages 63-76)
Regular expressions Regular languages Sipser 1.3 (pages 63-76)
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
CS 310 – Fall 2006 Pacific University CS310 Regular Expressions Sections:1.3 page 63 September 18, 2006 September 20, 2006.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
1 Non-Deterministic Automata Regular Expressions.
CS 310 – Fall 2006 Pacific University CS310 Homework 2 & JFLAP September 22, 2006.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA to regular.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
CHAPTER 1 Regular Languages
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
Theory of Computing CSCI 356/541 Lab Session. Outline Lab 1: Finite Automata  Construct and Run Construct and Run  Manipulating Transitions Manipulating.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
Finite Automata Chapter 1. Automatic Door Example Top View.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho.
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
1 Introduction to the Theory of Computation Regular Expressions.
CSE 202 – Formal Languages and Automata Theory 1 REGULAR EXPRESSION.
CSCI 2670 Introduction to Theory of Computing September 7, 2004.
Theory of Computation Automata Theory Dr. Ayman Srour.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Decidable.
Theory of Languages and Automata By: Mojtaba Khezrian.
Nondeterminism The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
Formal Language & Automata Theory
LR(k) grammars The Chinese University of Hong Kong Fall 2009
CSE 105 theory of computation
Regular Expressions Sections:1.3 page 63 September 17, 2008
Jaya Krishna, M.Tech, Assistant Professor
Non-Determinism 12CS45 Finite Automata.
Pushdown automata and CFG ↔ PDA conversions
LR(1) grammars The Chinese University of Hong Kong Fall 2010
COT 4210 Lecture Notes - 3 By Njegos and Monika.
More on DFA minimization and DFA equivalence
Non-Deterministic Finite Automata
Non Deterministic Automata
Context-Free Grammars
Transition Diagrams Lecture 3 Fri, Jan 21, 2005.
Finite Automata.
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
Decidable and undecidable languages
CS21 Decidability and Tractability
Chapter 1 Regular Language - 02
CS21 Decidability and Tractability
LR(1) grammars The Chinese University of Hong Kong Fall 2011
NFA to DFA conversion and regular expressions
CSE 105 theory of computation
Non-regular languages
Pushdown automata The Chinese University of Hong Kong Fall 2011
LR(k) grammars The Chinese University of Hong Kong Fall 2008
Text search and closure properties
CSCI 2670 Introduction to Theory of Computing
DFA minimization The Chinese University of Hong Kong Fall 2011
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
Intro to Theory of Computation
Nondeterminism The Chinese University of Hong Kong Fall 2010
CSCI 2670 Introduction to Theory of Computing
COSC 3340: Introduction to Theory of Computation
COSC 3340: Introduction to Theory of Computation
CSE 105 theory of computation
Presentation transcript:

NFAs, DFAs, and regular expressions The Chinese University of Hong Kong Fall 2010 CSCI 3130: Automata theory and formal languages NFAs, DFAs, and regular expressions Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

Three ways of doing it L = {x Î S*: x ends in 01} S = {0, 1} (0+1)*01 1 0, 1 q0 q1 q2 qe 1 q0 q1 q00 q10 q01 q11 (0+1)*01 regular expression NFA DFA

They are all the same NFA regular expression DFA regular languages

Road map   regular expression NFA NFA without e DFA

Examples: regular expression → NFA q0 q1 R1 = 0 R2 = 01 1 q0 q1 q2

Examples: regular expression → NFA q1 q2 q0 q6  R3 = 0 + 01 q3 q4 q5 1  q0’ q1’ R4 = (0 + 01)* NFA3

Regular expressions → NFA In general, how do we convert a regular expression to an NFA? A regular expression over S is an expression formed using the following rules: The symbol Æ is a regular expression The symbol e is a regular expression For every a  S, the symbol a is a regular expression If R and S are regular expressions, so are R+S, RS and R*.

General method Æ e regular expr NFA q0 q0 q0 q1 a a  S RS q0 q1  NFAR NFAS

General method continued regular expr NFA NFAR q0 q1  R + S NFAS q0 q1  R* NFAR

Road map    regular expression NFA NFA without e DFA

Road map    regular expression NFA NFA without e DFA

Road map regular expression NFA NFA without e DFA 2-state GNFA GNFA

Generalized NFAs A generalized NFA is an NFA whose transitions are labeled by regular expressions, like moreover It has exactly one accept state, different from its start state No arrows come into the start state No arrows go out of the accept state 0*1 e+10* 0*11 q0 q1 q2 01

Converting a DFA to a GNFA regular expression NFA NFA without e DFA 2-state GNFA GNFA q1 q3 q5 q0 qf e

   Conversion example 1 q0 e q3 1 q1 q2  It has exactly one accept state, different from its start state No arrows come into the start state No arrows go out of the accept state  

GNFA state reduction regular expression NFA NFA without e DFA 2-state GNFA GNFA We will eliminate every state but the start and accept states

State elimination e+10* 0*11 0*1 q0 q1 q2 01 q0 q2 01

State elimination – general method To eliminate state qk, for every pair of states (qi, qj) remember to do this even when qi = qj! R2 R1 R3 Replace qi qk qj R4 R1R2*R3 + R4 by qi qj

      Road map NFA without e NFA regular expression DFA GNFA 2-state GNFA GNFA q0 q1 R A 2-state GNFA is the same as a regular expression R!

Conversion example Eliminate q1: Eliminate q2: Check: 0*1(00*1+1)* = 1 1 e 1 e q0 q1 q2 q3 00*1+1 0*1 e Eliminate q1: q0 q2 q3 0*1(00*1+1)* Eliminate q2: q0 q3 q1 q2 1 ? Check: 0*1(00*1+1)* =

Check your answer! 0*1(00*1+1)* 0*1(0*1)* 011001000101 q1 q2 1 All strings that end in 1 (0 + 1)*1 0*1(00*1+1)* Always ends in 1 = Does every string that ends in 1 have this form? 0*1(0*1)* 011001000101 Yes!

Design Analyze Convert What you need to know regular expression NFA DFA regular languages Design Analyze Convert