lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

lecture-2.md (2122B)


      1 +++
      2 title = "Lecture 2"
      3 template = "page-math.html"
      4 +++
      5 
      6 # Lecture 2
      7 
      8 ## Nondeterministic Finite Automata (NFA)
      9 
     10 Difference from DFA:
     11 
     12 -   A state can have zero or more outgoing arrows with the same label.
     13 -   Allows for empty steps: arrows with label λ that don\'t consume a
     14     symbol
     15 
     16 Defined like DFAs, except for transition function. Consists of:
     17 
     18 -   Q finite set of states
     19 -   Σ finite input alphabet
     20 -   δ : Q × (Σ  ∪ *λ*)  → 2<sup>Q</sup> transition function, 2<sup>Q</sup> is set of all
     21     subsets of Q
     22 -   q<sub>0</sub> ∈ Q starting state
     23 -   F ⊂ Q of final states
     24 
     25 Nondeterministic means that it can accept a word in more than one way.
     26 
     27 For an L, you cannot form $\overline{L}$ by flipping final and nonfinal
     28 states.
     29 
     30 A language L is accepted by NFA iff L is regular.
     31 
     32 ### Transforming NFA into DFA
     33 
     34 Start with the λ-closure of the initial states -- i.e. the initial state
     35 plus any states you can reach with a λ transition. Then, see what states
     36 you can go to from there, and every time compute the λ-closure.
     37 
     38 ## Grammars
     39 
     40 Grammar defines a language. With grammar rules you can construct a
     41 sentence.
     42 
     43 Consists of:
     44 
     45 -   V finite set of non-terminals (variables)
     46 -   T finite set of terminals
     47 -   S ∈ V start symbol
     48 -   P finite set of production rules x → y where
     49     -   $x \in (V \cup T)^+$ containing at least one symbol from V
     50     -   $y \in (V \cup T)^*$
     51     -   for CFGs, x ∈ V
     52 
     53 If x → y is production rule, then we have derivation step uxv ⇒ uyv for
     54 every u,v ∈ (V ∪ T)<sup>\*</sup>.
     55 
     56 ### Example
     57 
     58 Find grammar G such that L(G) = {a,b}<sup>\*</sup> {c} {b,c}<sup>\*</sup>
     59 
     60 ```
     61 S → AcB
     62 A → aA   B → bB
     63 A → bA   B → cB
     64 A → λ    B → λ
     65 ```
     66 
     67 ### Backus Naur Form (BNF) - Context-free grammar
     68 
     69 Non-terminals are indicated by \< and \>, and you can abbreviate
     70 multiple rules with an or.
     71 
     72 So like:
     73 
     74 ```
     75 S → a
     76   | b
     77   | λ
     78 ```
     79 
     80 ### Right linear grammars
     81 
     82 Right linear if all production rules are of form A → uB or A → u, where
     83 A,B are variables and u is a terminal.
     84 
     85 It's strictly right linear if $|u|  \leq 1$ (so $u \in (T  \cup \lambda)$)