Introduction to Finite Automata Adapted from the slides of Stanford CS154.

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

Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Introduction to Computability Theory
Introduction to Computability Theory
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.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata (cont.) Prof. Amos Israeli.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 1 Regular Languages Contents Finite Automata (FA or DFA) definitions, examples,
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
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.
Nondeterministic Finite Automata
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
CS 503 Spring semester 2015 WPI Most of the slides below are due to Jeffrey Ullman (one of our textbok’s authors). They are slides from a course he gave.
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
What Are They? Who Needs ‘em? An Example: Scoring in Tennis Finite Automata 11.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
CS311: Computational Theory
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
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.
Introduction to Finite Automata
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Lesson No.6 Naveen Z Quazilbash. Overview Attendance and lesson plan sharing Assignments Quiz (10 mins.). Some basic ideas about this course Regular Expressions.
CHAPTER 1 Regular Languages
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CS 203: Introduction to Formal Languages and Automata
Introduction to Finite Automata
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
Lecture Notes 
Deterministic Finite Automata
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 Example: Graph of a DFA Start 1 0 ACB 1 0 0,1 Previous string OK, does not end in 1. Previous String OK, ends in a single 1. Consecutive 1’s have been.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
Nondeterminism Subset Construction ε -Transitions.
  An alphabet is any finite set of symbols.  Examples: ASCII, Unicode, {0,1} ( binary alphabet ), {a,b,c}. Alphabets.
Non Deterministic Automata
Finite Automata a b A simplest computational model
What Are They? Who Needs ‘em? An Example: Scoring in Tennis
Chapter 2 FINITE AUTOMATA.
Finite Automata Motivation An Example.
Non-Deterministic Finite Automata
Introduction to Finite Automata
Finite Automata.
Deterministic Finite Automaton (DFA)
Chapter 1 Regular Language
NFA’s With ε-Transitions
AUTOMATA THEORY.
Presentation transcript:

Introduction to Finite Automata Adapted from the slides of Stanford CS154

2 Informal Explanation Finite automata  finite collections of states with transition rules that take you from one state to another. Original application  sequential switching circuits, where the “state” was the settings of internal bits. Today, several kinds of software can be modeled by FA.

3 Representing FA Simplest representation is often a graph.  Nodes = states.  Arcs indicate state transitions.  Labels on arcs tell what causes the transition.

4 Example: Recognizing Strings Ending in “ing” nothing Saw i i Not i Saw ing g i Not i or g Saw in n i Not i or n Start

5 Automata to Code In C/C++, make a piece of code for each state. This code: 1. Reads the next input. 2. Decides on the next state. 3. Jumps to the beginning of the code for that state.

6 Example: Automata to Code 2: /* i seen */ c = getNextInput(); if (c == ’n’) goto 3; else if (c == ’i’) goto 2; else goto 1; 3: /* ”in” seen */...

7 Deterministic Finite Automata A formalism for defining languages, consisting of: 1. A finite set of states (Q, typically). 2. An input alphabet ( Σ, typically). 3. A transition function ( δ, typically). 4. A start state (q 0, in Q, typically). 5. A set of final states (F ⊆ Q, typically). u “Final” and “accepting” are synonyms.

8 The Transition Function Takes two arguments:  a state and an input symbol. δ (q, a) = the state that the DFA goes to when it is in state q and input a is received.

9 Graph Representation of DFA’s Nodes = states. Arcs represent transition function.  Arc from state p to state q labeled by all those input symbols that have transitions from p to q. Arrow labeled “Start” to the start state. Final states indicated by double circles.

10 Example: Graph of a DFA Start 1 0 ACB 1 0 0,1 Previous string OK, does not end in 1. Previous String OK, ends in a single 1. Consecutive 1’s have been seen. Accepts all strings without two consecutive 1’s.

11 Alternative Representation: Transition Table 01 AABBACCCCAABBACCCC Rows = states Columns = input symbols Final states starred * * Arrow for start state

12 Extended Transition Function We describe the effect of a string of inputs on a DFA  by extending δ to a state and a string. Induction on length of string. Basis: δ (q, ε ) = q Induction: δ (q,wa) = δ ( δ (q,w),a)  w is a string; a is an input symbol.

13 Extended δ : Intuition Convention:  … w, x, y, x are strings.  a, b, c,… are single symbols. Extended δ is computed for state q and inputs a 1 a 2 …a n by following a path in the transition graph, starting at q and selecting the arcs with labels a 1, a 2,…,a n in turn.

14 Example: Extended Delta 01 AABBACCCCAABBACCCC δ (B,011) = δ ( δ (B,01),1) = δ ( δ ( δ (B,0),1),1) = δ ( δ (A,1),1) = δ (B,1) = C

15 Language of a DFA Automata of all kinds define languages. If A is an automaton, L(A) is its language. For a DFA A, L(A) is the set of strings labeling paths from the start state to a final state. Formally: L(A) = the set of strings w such that δ (q 0, w) is in F.

16 Example: String in a Language Start 1 0 ACB 1 0 0,1 String 101 is in the language of the DFA below. Start at A.

17 Example: String in a Language Start 1 0 ACB 1 0 0,1 Follow arc labeled 1. String 101 is in the language of the DFA below.

18 Example: String in a Language Start 1 0 ACB 1 0 0,1 Then arc labeled 0 from current state B. String 101 is in the language of the DFA below.

19 Example: String in a Language Start 1 0 ACB 1 0 0,1 Finally arc labeled 1 from current state A. Result is an accepting state, so 101 is in the language. String 101 is in the language of the DFA below.

20 Example – Concluded The language of our example DFA is: {w | w is in {0,1}* and w does not have two consecutive 1’s} Read a set former as “The set of strings w… Such that… These conditions about w are true.

21 Regular Languages A language L is regular if it is the language accepted by some DFA.  Note: the DFA must accept only the strings in L, no others. Some languages are not regular.  Intuitively, regular languages “cannot count” to arbitrarily high integers.

22 Example: A Nonregular Language L 1 = {0 n 1 n | n ≥ 1} Note: a i is conventional for i a’s.  Thus, 0 4 = 0000, e.g. Read: “The set of strings consisting of n 0’s followed by n 1’s, such that n is at least 1. Thus, L 1 = {01, 0011, ,…}

23 Another Example L 2 = {w | w in {(, )}* and w is balanced }  Note: alphabet consists of the parenthesis symbols ’(’ and ’)’.  Balanced parens are those that can appear in an arithmetic expression. E.g.: (), ()(), (()), (()()),…

24 But Many Languages are Regular Regular Languages can be described in many ways, e.g., regular expressions. They appear in many contexts and have many useful properties. Example: the strings that represent floating point numbers in your favorite language is a regular language.

25 Nondeterminism A nondeterministic finite automaton has the ability to be in several states at once. Transitions from a state on an input symbol can be to any set of states.

26 Nondeterminism – (2) Start in one start state. Accept if any sequence of choices leads to a final state. Intuitively: the NFA always “guesses right.”

27 Formal NFA A finite set of states, typically Q. An input alphabet, typically Σ. A transition function, typically δ. A start state in Q, typically q 0. A set of final states F ⊆ Q.

28 Transition Function of an NFA δ (q, a) is a set of states. Extend to strings as follows: Basis: δ (q, ε ) = {q} Induction: δ (q, wa) = the union over all states p in δ (q, w) of δ (p, a)

29 Language of an NFA A string w is accepted by an NFA if δ (q 0, w) contains at least one final state. The language of the NFA is the set of strings it accepts.

30 Equivalence of DFA’s, NFA’s A DFA can be turned into an NFA that accepts the same language. If δ D (q, a) = p, let the NFA have δ N (q, a) = {p}. Then the NFA is always in a set containing exactly one state – the state the DFA is in after reading the same input.

31 Equivalence – (2) Surprisingly, for any NFA there is a DFA that accepts the same language. Proof is the subset construction. The number of states of the DFA can be exponential in the number of states of the NFA. Thus, NFA’s accept exactly the regular languages.

32 Subset Construction Given an NFA with states Q, inputs Σ, transition function δ N, state state q 0, and final states F, construct equivalent DFA with:  States 2 Q (Set of subsets of Q).  Inputs Σ.  Start state {q 0 }.  Final states = all those with a member of F.

33 Subset Construction – (2) The transition function δ D is defined by: δ D ({q 1,…,q k }, a) is the union over all i = 1,…,k of δ N (q i, a).

34 Proof of Equivalence: Subset Construction Show by induction on |w| that δ N (q 0, w) = δ D ({q 0 }, w) Basis: w = ε : δ N (q 0, ε ) = δ D ({q 0 }, ε ) = {q 0 }.

35 Induction Assume IH (Induction Hypothesis) holds for strings shorter than w. Let w = xa; IH holds for x. Let δ N (q 0, x) = δ D ({q 0 }, x) = S. Let T = the union over all states p in S of δ N (p, a). Then δ N (q 0, w) = δ D ({q 0 }, w) = T.  For NFA: the extension of δ N.  For DFA: definition of δ D plus extension of δ D. That is, δ D (S, a) = T; then extend δ D to w = xa.

36 NFA’s With ε -Transitions We can allow state-to-state transitions on ε input. These transitions are done spontaneously, without looking at the input string. A convenience at times, but still only regular languages are accepted.

37 Example: ε -NFA C EF A BD ε ε ε

Subset construction in the Textbook

Subset construction in the Textbook (cont.)