2 - Nondeterminism

ucla | CS 181 | 2024-04-03 15:06


Table of Contents

Basic Notions and Examples

  • NFAs may have any number of transitions on a given symbol (i.e. multiple paths from the same symbol of the alphabet)
  • NFAs may transition wo consuming a symbol and isntead transitioning on ε to another state
  • NFAs accept a string if there is at least 1 path that accepts
  • useful for pattern matching
  • e.g. L(M) = strings containing 11 or 101:
  • e.g. L(M) = strings of length >= 2 and starts and ends in the same symbol:

    Pattern Matching Examples

  • L(M) = string of regex 0*1*0+ (any number of 0s followed by any number of 1s followed by at least one 0):

    Formal Definition

    M=(Q,Σ,q0,F,δ) only difference is the transition returns a set of states and can take an epsilon input: δ:Q×(Σ{ε})P(Q) where P(Q) is the Power set of Q, i.e. the set of all possible combinations of sets in Q The model accepts a string if there exists at least 1 path from start to an accepting state and the string ends on a final state.

Equivalence of DFA and NFA: Conversion NFA -> DFA

Theorem: Every NFA N can be converted to a DFA D that recognizes the same language L

  1. Allow DFA states to represent a et of NFA states
  2. Make transitions over the alphabet for each DFA state, recursively (i.e., do this for all new/unique DFA states we generate)
  3. If the NFA state transitions nowhere, then DFA should transition to a trap state (dead state, denoted )
  4. Label final states of DFA as any states that contain final states of NFA
  5. Remove unreachable states

Given an NFA N=(Q,Σ,δ,q0,F), the equivalent DFA is defined as D=(P(Q),Σ,Δ,S0,F) $S_0={q\in Q\space:\space q\text{ is reachable from }q_0\text{ via a path }\varepsilon^}\Delta(S,\sigma)={q\in Q\space:\space q\text{ is reachable from a state in } S\text{ via a path }\sigma\varepsilon^}\mathscr F={S\subseteq Q\space:\space S\text{ contains a state in }F}$

Equivalence: N accepts a string w=w1wn a state in F is reachable via a path $\varepsilon^w_1\varepsilon^w_2…w_n\varepsilon^*\iffastatein\mathscr FisreachablefromS_0viathepathw_1…w_n\iffDacceptsw$

Proving Complexity

Thm: An (smallest) NFA w/ kZ+ states can always be converted to a DFA w/ 2k states Thus, the smallest DFA has some kn2k states

  • We prove this by considering a language s.t. NFA w/ k+1 states and NO DFA w/ <2k states (pf by contradiction, so consider that the DFA accepts w/ <2k states)
  • e.g., L is the language for which there is a 0 in the kth position from the end over the binary alphabet
  • The NFA w/ k+1 states:
  • then for the DFA, there are 2k unique inputs possible, but if the DFA has strictly <2k states, then the final state for the inputs cannot be unique for all inputs by the P.P.
  • i.e., klength strings u,v for which uv but final state of u= final state of v
  • suppose the unique identifier in the strings is that ui=0,vi=1 and all other characters in the string are the same
  • Now because they share the same end state (i.e. they converge at the end), appending i1 0s to the end of either string will still have the same end state u0i1 ends on the same state as v0i1 (they both have 0 in the kthe position because they are in the language)
  • Now consider that both u,v are length k so after position i (the character for which they differ), there are ki characters following the ith position symbol
  • Now if we consider the 0-extended strings, they have (ki)+(i1)=k1 values after the ith position, thus kth position = ith position => vL b/c it has a 1 at vi=vk
  • This contradicts the fact that both u,v the DFA ends them on the same final state (Accepting or rejecting we don’t know but this regardless contradicts the definition of the DFA on L)