Regular Languages and Finite State Automata Minimization Ç. Çöltekin, SfS / University of Tübingen WS 19–20 5 / 56 Introduction DFA NFA Regular languages Regular expressions b Another note on DFA error or sink state well-defjned, we can add a sink (or error) state explicit error state – In that case, when we reach a dead end, recognition fails a a 1 DFA with At any given time, for any input, a DFA has a single well-defjned action to take. Ç. Çöltekin, Data structures and algorithms WS 19–20 4 / 56 Introduction NFA b Regular languages Minimization Regular expressions DFA: formal defjnition an example 0 1 2 0 2 Regular expressions 1 1 * 2 3 3 3 * marks the accepting state(s) 0 2 1 b a b a 3 Ç. Çöltekin, SfS / University of Tübingen WS 19–20 2 state 3 Introduction b a b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 6 / 56 DFA 1 NFA Regular languages Minimization Regular expressions DFA: the transition table transition table symbol 2 DFA: formal defjnition SfS / University of Tübingen Minimization Regular expressions Ç. Çöltekin, SfS / University of Tübingen WS 19–20 1 / 56 Introduction DFA NFA Regular languages Minimization Finite-state automata (FSA) – Shallow parsing/chunking in a given time – Deterministic fjnite automata (DFA) – Non-deterministic fjnite automata (NFA) Note: the NFA is a superset of DFA. Regular languages SfS / University of Tübingen WS 19–20 2 / 56 Introduction – … – Morphological analysis NFA Regular languages for Computational Linguistics III Çağrı Çöltekin ccoltekin@sfs.uni-tuebingen.de University of Tübingen Seminar für Sprachwissenschaft Winter Semester 2019–2020 Introduction DFA NFA Minimization – Tokenization, stemming Regular expressions Why study fjnite-state automata? fjnite-state automata are effjcient models of computation – Electronic circuit design – Workfmow management – Games – Pattern matching – … But more importantly ;-) DFA Ç. Çöltekin, Regular languages transition 1 2 Minimization b a b a initial state state states accepting state Ç. Çöltekin, SfS / University of Tübingen WS 19–20 3 / 56 Introduction DFA NFA 0 7 / 56 as the initial state Regular expressions DFA as a graph nodes the edges, labeled with symbols from an alphabet • Unlike some of the abstract machines we discussed, • There are many applications • A fjnite-state machine is in one of a fjnite-number of states • States are represented as • The machine changes its state based on its input • Transitions are shown by • Every regular language is generated/recognized by an FSA • Every FSA generates/recognizes a regular language • Two fmavors: • One of the states is marked • Some states are accepting Formally, a fjnite state automaton, M , is a tuple ( Σ , Q , q 0 , F , ∆ ) Σ is the alphabet, a fjnite set of symbols Σ = { a , b } Q a fjnite set of states Q = { q 0 , q 1 , q 2 } q 0 is the start state, q 0 ∈ Q q 0 = q 0 F is the set of fjnal states, F ⊆ Q F = { q 2 } ∆ is a function that takes a state and a symbol in the ∆ = { ( q 0 , a ) → q 2 , alphabet, and returns another state ( ∆ : Q × Σ → Q ) ( q 0 , b ) → q 1 , ( q 1 , a ) → q 2 , ( q 1 , b ) → q 1 } • Is this FSA deterministic? a b • To make all transitions → 0 ∅ ∅ a , b • For brevity, we skip the a , b a , b a , b → marks the start state
Introduction Minimization a Input: b b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 8 / 56 Introduction DFA NFA Regular languages Regular expressions a DFA recognition 2. Process an input symbol, move accordingly 3. Accept if in a fjnal state at the end of the input What is the complexity of the algorithm? How about inputs: – bbbb – aa 0 1 b b b Minimization a DFA b b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 8 / 56 Introduction DFA NFA Regular languages Regular expressions 2 DFA recognition 2. Process an input symbol, move accordingly 3. Accept if in a fjnal state at the end of the input What is the complexity of the algorithm? How about inputs: – bbbb – aa 0 1 2 a a A few questions b b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 8 / 56 Introduction DFA NFA Regular languages Minimization Regular expressions recognized by this FSA? a DFA for the same language? strings with even number 0 1 2 b a b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 Input: b b Minimization a Input: b b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 8 / 56 Introduction DFA NFA Regular languages Regular expressions a DFA recognition 2. Process an input symbol, move accordingly 3. Accept if in a fjnal state at the end of the input complexity of the algorithm? – bbbb – aa 0 1 2 b b Input: b the end of the input WS 19–20 7 / 56 Introduction DFA NFA Regular languages Minimization Regular expressions DFA recognition 2. Process an input symbol, move accordingly 3. Accept if in a fjnal state at What is the Ç. Çöltekin, complexity of the algorithm? How about inputs: – bbbb – aa 0 1 2 2 a b a Input: SfS / University of Tübingen 3 b 1 NFA Regular languages Minimization Regular expressions DFA: the transition table transition table symbol 2 1 state 1 2 * 2 a 3 3 3 3 3 * marks the accepting state(s) 0 1 2 b a b b b a Minimization a Ç. Çöltekin, b b a Ç. Çöltekin, SfS / University of Tübingen WS 19–20 8 / 56 Introduction DFA NFA Regular languages Regular expressions a DFA recognition 2. Process an input symbol, move accordingly 3. Accept if in a fjnal state at the end of the input What is the complexity of the algorithm? How about inputs: – bbbb – aa 0 1 b Input: 9 / 56 the end of the input SfS / University of Tübingen WS 19–20 8 / 56 Introduction DFA NFA Regular languages Minimization Regular expressions DFA recognition b move accordingly 3. Accept if in a fjnal state at 2. Process an input symbol, What is the How about inputs: 1 0 – aa 2 – bbbb algorithm? complexity of the 1. Start at q 0 a b → 0 a , b a , b → marks the start state 1. Start at q 0 1. Start at q 0 1. Start at q 0 1. Start at q 0 1. Start at q 0 • What is the language • Can you draw a simpler • What is the • Draw a DFA recognizing of ‘ a ’s over Σ = { a , b } • How about inputs:
Recommend
More recommend