
Nondeterministic Finite Automata and Regular Expressions in Computer Science
Explore the concepts of nondeterministic finite automata, regular expressions, closure properties, and their applications in computer science. Dive into theorems, definitions, and practical examples to grasp these fundamental topics effectively.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
18.404/6.840 Lecture 2 Last time: (Sipser 1.1) - Finite automata, regular languages - Regular operations , , - Regular expressions - Closure under Today: (Sipser 1.2 1.3) - Nondeterminism - Closure under and - Regular expressions finite automata Goal: Show finite automata equivalent to regular expressions - This week s check-ins will not be counted - TA office hours will be posted tomorrow - Chat is restricted to TAs only.
Problem Sets - 35% of overall grade - Problems are hard! Leave time to think about them. - Writeups need to be clear and understandable, handwritten ok. Level of detail in proofs comparable to lecture: focus on main ideas. Don t need to include minor details. - Submit via gradescope (see Canvas) by 2:30pm Cambridge time. Late submission accepted (on gradescope) until 11:59pm following day: 1 point (out of 10 points) per late problem penalty. After that solutions are posted so not accepted without S3 excuse. - Optional problems: Don t count towards grade except for A+. Value to you (besides the challenge): Recommendations, employment (future grading, TA, UROP) - Problem Set 1 is due in one week.
Closure Properties for Regular Languages Theorem: Theorem: If ?1, ?2are regular languages, so is ?1?2 (closure under ) Recall proof attempt: Recall proof attempt: Let ?1= (?1, , ?1, ?1, ?1)recognize?1 ?2= (?2, , ?2, ?2, ?2)recognize?2 Construct ? = (?, , ?, ?0, ?) recognizing?1?2 ?2 ?1 ? should accept input ? if ? = ?? where ?1 accepts ? and ?2 accepts ?. ? ? ? ? Doesn t work: Where to split ?? Hold off. Need new concept.
Nondeterministic Finite Automata a ?1 a b a, ?4 ?1 ?2 ?3 b New features of nondeterminism: - multiple paths possible (0, 1 or many at each step) - -transition is a free move without reading input - Accept input if some path leads to accept Check-in 2.1 Example inputs: - ab accept - aa reject - aba accept - abb reject What does ?1 do on input aab ? (a) Accept Nondeterminism doesn t correspond Nondeterminism doesn t correspond to a physical machine we can build. to a physical machine we can build. However, it is However, it is useful useful mathematically. (b) Reject (c) Both Accept and Reject mathematically. Check-in 2.1
NFA Formal Definition a ?1 a b a, ?4 ?1 ?2 ?3 b Defn: A nondeterministic finite automaton (NFA) ? is a 5-tuple (?, ,?,?0,?) Ways to think about nondeterminism: Ways to think about nondeterminism: Computational: Computational: Fork new parallel thread and accept if any thread leads to an accept state. - all same as before except ? - ?:? ? ? = ? ? ?} { } Mathematical: Mathematical: Tree with branches. Accept if any branch leads to an accept state. power set Magical: Magical: Guess at each nondeterministic step which way to go. Machine always makes the right guess that leads to accepting, if possible. - In the ?1 example: ? ?1,a = {?1,?2} ? ?1,b =
Converting NFAs to DFAs Theorem: Theorem: If an NFA recognizes ? then ? is regular Proof: Proof: Let NFA ? = (?, ,?, ?0,?)recognize? Construct DFA ? = (? , ,? , ?0 ,? )recognizing? (Ignore the -transitions, can easily modify to handle them) IDEA: IDEA: DFA ? keeps track of the subset of possible states in NFA ?. Check-in 2.2 Construction of Construction of ? : : ? ? If ? has ? states, how many states does ? have by this construction? (a) 2? (b) ?2 (c) 2? ?3 ? = ? ? ? ?,? = ? ? ?(?,?) for some ? ?} {?3,?7} ? ? = {q0} ?0 ? = ? ? ? intersects ?} ?7 NFA DFA Check-in 2.2
Return to Closure Properties Recall Theorem: Recall Theorem: If ?1,?2are regular languages, so is ?1 ?2 (The class of regular languages is closed under union) New Proof (sketch): New Proof (sketch): Given DFAs ?1 and ?2 recognizing ?1 and ?2 Construct NFA ? recognizing ?1 ?2 ? ?1 Nondeterminism Nondeterminism parallelism vs guessing ?2
Closure under (concatenation) Theorem: Theorem: If ?1,?2are regular languages, so is ?1?2 Proof sketch: Proof sketch: Given DFAs ?1 and ?1 recognizing ?1 and ?2 Construct NFA ? recognizing ?1?2 ? ?2 ?1 ? should accept input ? if ? = ?? where ?1 accepts ? and ?2 accepts ?. ? = ? ? Nondeterministic ? has the option to jump to ?2 when ?1 accepts.
Closure under (star) Theorem: Theorem: If ? is a regular language, so is ? Proof sketch: Proof sketch: Given DFA ? recognizing ? Construct NFA ? recognizing ? ? Check-in 2.3 ? ? should accept input ? if ? = ?1?2 ?? where ? 0 and ? accepts each ?? does ? have by this construction? (a) ? (b) ? + 1 (c) 2? If ? has ? states, how many states ? = ?3 ?4 ?1 ?2 Make sure ? accepts Check-in 2.3
Regular Expressions NFA Theorem: Theorem: If ? is a regular expr and ? = ? ? then ? is regular Proof: Proof: Convert ? to equivalent NFA ?: If ? is atomic: ? = ? for ? ? = ? = Equivalent ? is: ? Example: Example: Convert a ab to equivalent NFA a: b: : ab: : a ab: : a b a b If ? is composite: ? = ?1 ?2 ? = ?1 ?2 ? = ?1 } a a b Use closure constructions a ab : : a a b
Quick review of today 1. 1. Nondeterministic finite automata (NFA) Nondeterministic finite automata (NFA) 2. 2. Proved: NFA and DFA are equivalent in power Proved: NFA and DFA are equivalent in power 3. 3. Proved: Class of regular languages is closed under Proved: Class of regular languages is closed under , 4. 4. Conversion of regular expressions to NFA Conversion of regular expressions to NFA Check-in 2.4 Recitations start tomorrow online (same link as for lectures). They are optional, unless you need more help. You may attend any recitation(s). Which do you think you ll attend? (you may check several) (a) 10:00 (b) 11:00 (c) 12:00 (d) 1:00 (e) 2:00 (f) I prefer a different time (please post on piazza, but no promises) Check-in 2.4