- University of Applied Sciences - Computational Models - CSCI 331 - Friedhelm Seutter Institut für Angewandte Informatik Part I Automata and Languages 0. Introduction, Alphabets, Strings, and Languages 1. Regular Languages and Finite Automata 2. Context-Free Languages and Pushdown Automata Institut für Angewandte Informatik 2 1
1. Regular Languages Finite Automata Nondeterminism Regular Expressions Nonregular Languages Institut für Angewandte Informatik 3 Finite Automata Example: Addition of two binary numbers Institut für Angewandte Informatik 4 2
Finite Automata Example: Computation of the binary adder Sum, output: s : {0,1} 3 {0,1} Carry, internal state: c : {0,1} 3 {0,1} Institut für Angewandte Informatik 5 Finite Automata Example: State diagram (or transition diagram) Institut für Angewandte Informatik 6 3
Finite Automata Components: Institut für Angewandte Informatik 7 Finite Automata Components of FA without output tape: Institut für Angewandte Informatik 8 4
Finite Automata Example: Input: w {a,b}* Output: o {no,yes} Institut für Angewandte Informatik 9 Finite Automata Institut für Angewandte Informatik 10 5
Finite Automata Example: M = ({0,1,2}, {a,b}, δ, 0, {0}) δ: a b 0 1 0 1 2 1 2 0 2 Institut für Angewandte Informatik 11 Finite Automata Institut für Angewandte Informatik 12 6
Finite Automata Computation: Initially a finite automaton is in its start state and the reading head is positioned on the first symbol of the input. Depending on the present state and the present input symbol the automaton changes the state and moves the reading head to the next input symbol. When the input is read completely and the finite automaton terminates processing in a final state, then it accepts, otherwise it rejects the input. Institut für Angewandte Informatik 13 Finite Automata Example: Input: w = baabab Output: yes, accept There is a sequence of states from the start state to a final state: 0, 0, 1, 2, 2, 0, 0 Institut für Angewandte Informatik 14 7
Finite Automata Example: Input: w = baababa Output: no, reject There is no sequence of states from the start state to a final state: 0, 0, 1, 2, 2, 0, 0, 1 L(M) = { w w {a,b}*, w a mod 3 = 0} Institut für Angewandte Informatik 15 Finite Automata Institut für Angewandte Informatik 16 8
Finite Automata Institut für Angewandte Informatik 17 Nondeterminism So far, every step of a computation of a finite automaton follows in a unique way from the preceding step. The computation is deterministic. Generalization to a nondeterministic computation. There may exist several choices for the next state at any point. We speak of deterministic finite automata (DFA) and of nondeterministic finite automata (NFA). Institut für Angewandte Informatik 18 9
Nondeterminism, NFA Example: Institut für Angewandte Informatik 19 Nondeterminism Extensions: A state may have more than one transition for some alphabet symbol. A state may have no transition for some alphabet symbol. A state may have a transition for the empty string ε, which is not an alphabet symbol. Institut für Angewandte Informatik 20 10
Nondeterminism, NFA Institut für Angewandte Informatik 21 Nondeterminism, NFA Example: N = ({A,B,C,D}, {a,b}, δ, A, {A}) δ: a b ε A {C} {A} {B} B {A,B} C {D} {C} D {A} {D} Institut für Angewandte Informatik 22 11
Nondeterminism, NFA Computation: If there are several choices for a state and an input symbol, the automaton splits into multiple copies of itself and follows all the possibilities in parallel. If there is no transition for a state and an input symbol, the automaton terminates this branch. ε - transition: No input symbol is read, the head is not moved to the next input symbol. The automaton just changes to the next state. Institut für Angewandte Informatik 23 Nondeterminism Computation of input string baaba: Institut für Angewandte Informatik 24 12
Nondeterminism Institut für Angewandte Informatik 25 Nondeterminism Input string w = baaba: For example, w can be written as εbaaba leading to a final state. Institut für Angewandte Informatik 26 13
Equivalence of NFA and DFA Institut für Angewandte Informatik 27 Subset Construction Given NFA N = (Q, Σ, δ, q 0, F). Construction of an equivalent DFA M = (Q, Σ, δ, q 0, F ): Institut für Angewandte Informatik 28 14
Subset Construction Given NFA N = (Q, Σ, δ, q 0, F). Construction of an equivalent DFA M = (Q, Σ, δ, q 0, F ): Institut für Angewandte Informatik 29 Example of Subset Construction Institut für Angewandte Informatik 30 15
Example of Subset Construction Reachable states from start state Institut für Angewandte Informatik 31 Computation of NFA N and equivalent DFA M for input baaba: Institut für Angewandte Informatik 32 16
Closure under Regular Operations Institut für Angewandte Informatik 33 Closure under Union N 1 N N 2 ε ε NFAs N 1, N 2, N with L(N) = L(N 1 ) L(N 2 ) Institut für Angewandte Informatik 34 17
Closure under Concatenation N 1 N N 2 ε ε NFAs N 1, N 2, N with L(N) = L(N 1 ) L(N 2 ) Institut für Angewandte Informatik 35 Closure under Star Operation N 1 N ε ε ε NFAs N 1, N with L(N) = (L(N 1 ))* Institut für Angewandte Informatik 36 18