CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho.

Slides:



Advertisements
Similar presentations
CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Advertisements

Lecture 6 Nondeterministic Finite Automata (NFA)
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Tutorial CSC3130 : Formal Languages and Automata Theory Tu Shikui ( ) SHB 905, Office hour: Thursday 2:30pm-3:30pm
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.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Non-Deterministic Automata Regular Expressions.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
CSCI 2670 Introduction to Theory of Computing August 24, 2005.
CSCI 3130: Formal languages and automata theory Tutorial 2 Chin.
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
CSCI 2670 Introduction to Theory of Computing September 13.
CSCI 3130: Formal languages and automata theory Tutorial 3 Chin.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Lecture Notes 
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
 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.
CSCI 2670 Introduction to Theory of Computing September 7, 2004.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 Lexical Analysis Uses formalism of Regular Languages Uses formalism of Regular Languages Regular Expressions Regular Expressions Deterministic Finite.
Theory of Computation Automata Theory Dr. Ayman Srour.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
1 Finite Automata. 2 Introductory Example An automaton that accepts all legal Pascal identifiers: Letter Digit Letter or Digit "yes" "no" 2.
Lecture #5 Advanced Computation Theory Finite Automata.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Theory of Computation Automata Theory Dr. Ayman Srour.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Nondeterminism The Chinese University of Hong Kong Fall 2011
CIS Automata and Formal Languages – Pei Wang
Finite automate.
Lexical analysis Finite Automata
Non Deterministic Automata
Two issues in lexical analysis
Cpt S 317: Spring 2009 Reading: Chapters 1-4
Non-Deterministic Finite Automata
COSC 3340: Introduction to Theory of Computation
Non-Deterministic Finite Automata
CSE322 Definition and description of finite Automata
Non Deterministic Automata
Finite Automata.
4b Lexical analysis Finite Automata
NFAs, DFAs, and regular expressions
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
4b Lexical analysis Finite Automata
Pushdown automata The Chinese University of Hong Kong Fall 2011
Cpt S 317: Spring 2009 Reading: Chapters 1-4
Chapter # 5 by Cohen (Cont…)
Lexical Analysis Uses formalism of Regular Languages
CSCI 2670 Introduction to Theory of Computing
Nondeterminism The Chinese University of Hong Kong Fall 2010
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho

About me Name: Chin Office: SHB 117 Office hour: Tuesday 11:00 – 12:00 Homework 1 is due on next Thursday

Finite Automata 1. Q - States 2.  - Alphabets 3.  - Transitions 4. q 0 - Initial state 5. F - Final state(s) / Accepting state(s)

Deterministic Finite Automata There must be a transition corresponding to each alphabet at each state

Nondeterministic Finite Automata Can be at multiple states at the same time Can go to multiple states on one alphabet May have no transitions on an alphabet (die)

Regular Expression The symbols  and  are regular expressions Every a in  is a regular expression If R and S are regular expressions, so are R+S, RS and R* Remember for R*, * could be 0

Regular Languages Languages that can be represented by a DFA / NFA / RE DFA = NFA = RE When asked if a language L is regular, represent L using a DFA / NFA / RE

Checklist 1. Always pay attention to  2. For DFA, out degree of each state must be equal |  | e.g.  = { 0, 1, 2 }, L = {w: w begins with 01 } 3. For NFA, pay attention to  -transitions 4. Remember to specify the initial state 5. Make sure you have considered the input  e.g. L = {w: w contains even number of 01 }

Example in Lecture q0q0 q1q q2q2 0, 1  = {0, 1} 1.q 2 is a “die” state 2.After a 1 has appeared, any 0 appears afterwards will die 3.0*1*

Exercise  = { 0, 1 } L = {w: w is non-empty and the sum of the digits in w is divisible by 5}

Idea Need to keep track of the sum of digits Arrive at the state q k when sum of digits = k q0q0 q1q q2q2 0 1 q3q q4q4 0 q5q5 0 1 …

Idea Need to keep track of the sum of digits Arrive at the state q k when sum of digits = k k divisible by 5 iff k mod 5 = 0 Keep track of the remainder instead q0q0 q1q q2q2 0 1 q3q q4q4 0 1

Answer Handle the input  q0q0 q1q q2q2 0 1 q3q q4q4 0 1 qsqs 0 1

Converting an NFA to a DFA Eliminate  for each state i for each alphabet x for each state j if i can reach j using one x and  (s) add an edge from i to j with label x q0q0 q1q1 0 q2q2  q0q0 q1q1  q2q2 1 q0q0 q1q1 0 q2q2 0 q0q0 q1q1 q2q2 1 1 q0q0 q1q1  q2q2 1 q0q0 q1q1 q2q2 1 1 q3q3  q3q3 11

Converting an NFA to a DFA Eliminate  Remember to consider the case when the initial state can reach accepting states on  (s) q0q0 q1q1  q2q2 1 q0q0 q1q1 q2q2 1 1

Converting an NFA to a DFA Every possible subsets of Q is a state in the DFA Going to multiple states at the same time in the NFA = going to a subset of Q, which is now a state in the DFA q0q0 q1q1 1 q2q2 1 {q 0 }{q 1, q 2 } 1

Converting an NFA to a DFA Empty set ∅ = die ∅  

Exercise q0q0 q1q1 0  0 q2q2 1 0, 1 1

Eliminating  -transitions q 0 can reach q 0 on 0 (q 0 -> q 1 -> q 0 ) q 0 can reach q 1 on 0 (q 0 -> q 1 ) q 1 can reach q 0 on 0 (q 1 -> q 0 ) q 1 can reach q 1 on 0 (q 1 -> q 1 ) The rest of the transitions remain unchanged 01 q0q0 q 0, q 1 q2q2 q1q1 q2q2 q1q1 q 1, q 2 q0q0 q1q1 0  0 q2q2 1 0, 1 1

Eliminating  -transitions q0q0 q1q1 0 0 q2q2 1 0, q0q0 q 0, q 1 q2q2 q1q1 q2q2 q1q1 q 1, q 2 q0q0 q1q1 0  0 q2q2 1 0, 1 1 q 0 is the initial state q 0 can reach an accepting state on  (i.e. q 1 ) therefore q 0 is also an accepting state

Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } q0q0 q1q1 0 0 q2q2 1 0,

Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Starting from initial state {q 0 } {q 0 } {q 0, q 1 } 0 {q 2 } 1

Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Check if every state has |  | outgoing transitions No “Fix” {q 2 } and {q 0, q 1 } {q 0, q 1 } goes to {q 0, q 1 } ∪ {q 0, q 1 } = {q 0, q 1 } on 0 {q 0, q 1 } goes to {q 2 } ∪ ∅ = {q 2 } on 1 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } 1 1

Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Check if every state has |  | outgoing transitions No “Fix” {q 1 } and {q 1, q 2 } {q 1, q 2 } goes to {q 0, q 1 } ∪ {q 1 } = {q 0, q 1 } on 0 {q 1, q 2 } goes to ∅ ∪ {q 1, q 2 } = {q 1, q 2 } on 1 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } ∅ 1

Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Check if every state has |  | outgoing transitions No “Fix” ∅ ∅ = die 0, 1 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } ∅ 1 1

Converting NFA to DFA 01 {q 0 }{q 0, q 1 }{q 2 } {q 1 }{q 0, q 1 } ∅ {q 2 }{q 1 }{q 1, q 2 } Check if every state has |  | outgoing transitions Yes Accepting states = states that contain q 0 or q 1 q0q0 q1q1 0 0 q2q2 1 0, {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } ∅ 1 1

Converting NFA to DFA Done q0q0 q1q1 0  0 q2q2 1 0, 1 1 {q 0 } {q 0, q 1 } 0 {q 2 } 1 0 {q 1 } 0 {q 1, q 2 } ∅ 1 1