Comprehensive Automata and Computation Theory Guide

Deterministic Finite Automata (DFA) Design and Transition Systems

  • Foundational Principles of DFA State Design:

    • Every state in a DFA represents an equivalence class of string histories based on future behavior.
    • Two string prefixes P1P_1 and P2P_2 can be merged into the same state if and only if for every future continuation string ww, both P1wP_1 w and P2wP_2 w are either both accepted or both rejected.
    • If reading an input symbol causes the state condition to change, a transition is made to a different state; otherwise, a self-loop is executed on the current state.
  • DFA: Even Number of 00s Over Binary Alphabet Σ={0,1}\Sigma = \{0, 1\}:

    • Language specification: L={w∈{0,1}∗∣number of 0s in w is even}L = \{w \in \{0, 1\}^* \mid \text{number of } 0\text{s in } w \text{ is even}\}.
    • States:
      • q0q_0: Start state, representing the condition where an even number of 00s have been seen (Accepting state).
      • q1q_1: Representing the condition where an odd number of 00s have been seen.
    • Transitions:
      • δ(q0,0)=q1\delta(q_0, 0) = q_1
      • δ(q0,1)=q0\delta(q_0, 1) = q_0
      • δ(q1,0)=q0\delta(q_1, 0) = q_0
      • δ(q1,1)=q1\delta(q_1, 1) = q_1
  • DFA: Substring 0101:

    • Condition tracking:
      • P1P_1: Starts with 00 but 11 is not yet seen (State q1q_1).
      • P2P_2: Does not start with 00 (State q0q_0, start state).
      • P3P_3: Substring 0101 has been matched (State q2q_2, accepting state).
    • State equivalence checking:
      • Prefix P1=0P_1 = 0
      • Prefix P2=ϵP_2 = \epsilon
      • For future string 11: P11=01P_1 1 = 01 (Accepted); P21=1P_2 1 = 1 (Rejected). Hence, P1≠P2P_1 \neq P_2.
      • For future string 0101: P201=01P_2 01 = 01 (Accepted).
      • Prefix 1010 with future string 11: 101101 (Accepted). Prefix 1010 behaves identically to prefix 00, mapping to state q1q_1.
    • Total states: 33
    • Transitions:
      • δ(q0,0)=q1\delta(q_0, 0) = q_1, δ(q0,1)=q0\delta(q_0, 1) = q_0
      • δ(q1,0)=q1\delta(q_1, 0) = q_1, δ(q1,1)=q2\delta(q_1, 1) = q_2
      • δ(q2,0)=q2\delta(q_2, 0) = q_2, δ(q2,1)=q2\delta(q_2, 1) = q_2
  • DFA: Substring 101101:

    • States and progress conditions:
      • q0q_0: Start state; no part of the pattern 101101 is matched.
      • q1q_1: Last symbol read is 11; pattern 11 matched, 00 not yet seen.
      • q2q_2: Pattern 1010 matched, final 11 not yet seen.
      • q3q_3: Pattern 101101 matched (Accepting state).
    • Behavioral analysis for merges:
      • P1=1P_1 = 1
      • P2=10P_2 = 10
      • P3=0P_3 = 0
      • P4=101P_4 = 101
      • P3P_3 behaves identically to q0q_0: on input 11, 0101 requires future 0101 to accept; on input 00, 0000 requires future 101101 to accept.
    • Transitions:
      • δ(q0,0)=q0\delta(q_0, 0) = q_0, δ(q0,1)=q1\delta(q_0, 1) = q_1
      • δ(q1,0)=q2\delta(q_1, 0) = q_2, δ(q1,1)=q1\delta(q_1, 1) = q_1
      • δ(q2,0)=q0\delta(q_2, 0) = q_0, δ(q2,1)=q3\delta(q_2, 1) = q_3
      • δ(q3,0)=q3\delta(q_3, 0) = q_3, δ(q3,1)=q3\delta(q_3, 1) = q_3
  • DFA: Starting with aa Over Alphabet Σ={a,b}\Sigma = \{a, b\}:

    • Conditions:
      • P1P_1: Starts with aa (q1q_1, accepting state).
      • P2P_2: Does not start with aa (starts with bb) (q2q_2, trap/dead state).
      • q0q_0: Start state (before reading any input).
    • Total states: 33
    • Transitions:
      • δ(q0,a)=q1\delta(q_0, a) = q_1, δ(q0,b)=q2\delta(q_0, b) = q_2
      • δ(q1,a)=q1\delta(q_1, a) = q_1, δ(q1,b)=q1\delta(q_1, b) = q_1
      • δ(q2,a)=q2\delta(q_2, a) = q_2, δ(q2,b)=q2\delta(q_2, b) = q_2
  • DFA: Starting with cc and Ending with ss Over Σ={c,a,s}\Sigma = \{c, a, s\}:

    • Condition tracking:
      • q0q_0: Initial state, no symbols read.
      • q1q_1: Starts with cc, but does not currently end with ss.
      • q2q_2: Does not start with cc (Dead/Trap state).
      • q3q_3: Starts with cc and currently ends with ss (Accepting state).
    • Transitions:
      • δ(q0,c)=q1\delta(q_0, c) = q_1, δ(q0,a)=q2\delta(q_0, a) = q_2, δ(q0,s)=q2\delta(q_0, s) = q_2
      • δ(q1,c)=q1\delta(q_1, c) = q_1, δ(q1,a)=q1\delta(q_1, a) = q_1, δ(q1,s)=q3\delta(q_1, s) = q_3
      • δ(q2,c)=q2\delta(q_2, c) = q_2, δ(q2,a)=q2\delta(q_2, a) = q_2, δ(q2,s)=q2\delta(q_2, s) = q_2
      • δ(q3,c)=q1\delta(q_3, c) = q_1, δ(q3,a)=q1\delta(q_3, a) = q_1, δ(q3,s)=q3\delta(q_3, s) = q_3
    • Total states: 44
  • DFA: Ending with 11 Over Σ={0,1}\Sigma = \{0, 1\}:

    • States:
      • q0q_0: Does not end with 11 (Start state; includes empty string ϵ\epsilon and strings ending in 00).
      • q1q_1: Ends with 11 (Accepting state).
    • Transitions:
      • δ(q0,0)=q0\delta(q_0, 0) = q_0, δ(q0,1)=q1\delta(q_0, 1) = q_1
      • δ(q1,0)=q0\delta(q_1, 0) = q_0, δ(q1,1)=q1\delta(q_1, 1) = q_1
    • Total states: 22
  • DFA: Number of 11s Divisible by 33:

    • Condition: Count of 11s modulo 33.
      • q0q_0: count(mod3)=0\text{count} \pmod 3 = 0 (0,3,6,…0, 3, 6, \dots ones seen; Start and Accepting state).
      • q1q_1: count(mod3)=1\text{count} \pmod 3 = 1 (1,4,7,…1, 4, 7, \dots ones seen; Non-accepting).
      • q2q_2: count(mod3)=2\text{count} \pmod 3 = 2 (2,5,8,…2, 5, 8, \dots ones seen; Non-accepting).
    • Transitions:
      • δ(q0,0)=q0\delta(q_0, 0) = q_0, δ(q0,1)=q1\delta(q_0, 1) = q_1
      • δ(q1,0)=q1\delta(q_1, 0) = q_1, δ(q1,1)=q2\delta(q_1, 1) = q_2
      • δ(q2,0)=q2\delta(q_2, 0) = q_2, δ(q2,1)=q0\delta(q_2, 1) = q_0
    • Total states: 33
  • DFA: Beginning with 0101 and of Even Length Over Σ={0,1}\Sigma = \{0, 1\}:

    • Conditions:
      • q0q_0: Start state, length 00 (even).
      • q1q_1: Seen 00, length 11 (odd).
      • q2q_2: Dead state; strings that do not begin with 0101.
      • q3q_3: Seen 0101, length 22 (even, prefix 0101 verified; Accepting state).
      • q4q_4: Began with 0101, currently odd length (Non-accepting).
    • Transitions:
      • δ(q0,0)=q1\delta(q_0, 0) = q_1, δ(q0,1)=q2\delta(q_0, 1) = q_2
      • δ(q1,0)=q2\delta(q_1, 0) = q_2, δ(q1,1)=q3\delta(q_1, 1) = q_3
      • δ(q2,0)=q2\delta(q_2, 0) = q_2, δ(q2,1)=q2\delta(q_2, 1) = q_2
      • δ(q3,0)=q4\delta(q_3, 0) = q_4, δ(q3,1)=q4\delta(q_3, 1) = q_4
      • δ(q4,0)=q3\delta(q_4, 0) = q_3, δ(q4,1)=q3\delta(q_4, 1) = q_3
    • Total states: 55
  • DFA: Strings Not Containing 110110 Over Σ={0,1}\Sigma = \{0, 1\}:

    • States:
      • q0q_0: Start state; have not seen 110110, no trailing 11 (Accepting state).
      • q1q_1: Have not seen 110110, trailing 11 (Accepting state).
      • q2q_2: Have not seen 110110, trailing 1111 (Accepting state).
      • q3q_3: Substring 110110 seen (Dead/Trap state, non-accepting).
    • Transitions:
      • δ(q0,0)=q0\delta(q_0, 0) = q_0, δ(q0,1)=q1\delta(q_0, 1) = q_1
      • δ(q1,0)=q0\delta(q_1, 0) = q_0, δ(q1,1)=q2\delta(q_1, 1) = q_2
      • δ(q2,0)=q3\delta(q_2, 0) = q_3, δ(q2,1)=q2\delta(q_2, 1) = q_2
      • δ(q3,0)=q3\delta(q_3, 0) = q_3, δ(q3,1)=q3\delta(q_3, 1) = q_3
  • DFA: Exactly Three Consecutive 00s:

    • States:
      • q0q_0: No consecutive 00s seen (Start state).
      • q1q_1: Exactly one consecutive 00 seen.
      • q2q_2: Exactly two consecutive 00s seen.
      • q3q_3: Exactly three consecutive 00s seen (Accepting state).
    • Transitions:
      • δ(q0,1)=q0\delta(q_0, 1) = q_0, δ(q0,0)=q1\delta(q_0, 0) = q_1
      • δ(q1,1)=q0\delta(q_1, 1) = q_0, δ(q1,0)=q2\delta(q_1, 0) = q_2
      • δ(q2,1)=q0\delta(q_2, 1) = q_0, δ(q2,0)=q3\delta(q_2, 0) = q_3
      • δ(q3,0)=q0\delta(q_3, 0) = q_0, δ(q3,1)=q0\delta(q_3, 1) = q_0
    • Total states: 44
  • DFA: Beginning with 0101 and Ending with 1111 Over Σ={0,1}\Sigma = \{0, 1\}:

    • Conditions and state progression:
      • q0q_0: Start state; does not begin with 00.
      • q1q_1: Began with 00, next symbol must be 11.
      • q2q_2: Trap state; strings that fail to begin with 0101.
      • q3q_3: Began with 0101, current suffix is neither 11 nor 1111.
      • q4q_4: Began with 0101, current suffix is 11 (not 1111).
      • q5q_5: Began with 0101, current suffix is 1111 (Accepting state).
    • Transitions:
      • δ(q0,0)=q1\delta(q_0, 0) = q_1, δ(q0,1)=q2\delta(q_0, 1) = q_2
      • δ(q1,0)=q2\delta(q_1, 0) = q_2, δ(q1,1)=q3\delta(q_1, 1) = q_3
      • δ(q2,0)=q2\delta(q_2, 0) = q_2, δ(q2,1)=q2\delta(q_2, 1) = q_2
      • δ(q3,0)=q3\delta(q_3, 0) = q_3, δ(q3,1)=q4\delta(q_3, 1) = q_4
      • δ(q4,0)=q3\delta(q_4, 0) = q_3, δ(q4,1)=q5\delta(q_4, 1) = q_5
      • δ(q5,0)=q3\delta(q_5, 0) = q_3, δ(q5,1)=q5\delta(q_5, 1) = q_5
    • Total states: 66
  • DFA: Starting with aaaa Over Σ={a,b}\Sigma = \{a, b\}:

    • States:
      • q0q_0: Start state.
      • q1q_1: Seen single aa at the start.
      • q2q_2: Seen aaaa at the start (Accepting state).
      • q3q_3: Started with bb or abab (Dead state).
    • Transitions:
      • δ(q0,a)=q1\delta(q_0, a) = q_1, δ(q0,b)=q3\delta(q_0, b) = q_3
      • δ(q1,a)=q2\delta(q_1, a) = q_2, δ(q1,b)=q3\delta(q_1, b) = q_3
      • δ(q2,a)=q2\delta(q_2, a) = q_2, δ(q2,b)=q2\delta(q_2, b) = q_2
      • δ(q3,a)=q3\delta(q_3, a) = q_3, δ(q3,b)=q3\delta(q_3, b) = q_3
    • Total states: 44
  • DFA: Ending with aaaa or bbbb Over Σ={a,b}\Sigma = \{a, b\}:

    • States:
      • q0q_0: Start state, no suffix matched.
      • q1q_1: Last symbol read is aa.
      • q2q_2: Suffix is aaaa (Accepting state).
      • q3q_3: Last symbol read is bb.
      • q4q_4: Suffix is bbbb (Accepting state).
    • Transitions:
      • δ(q0,a)=q1\delta(q_0, a) = q_1, δ(q0,b)=q3\delta(q_0, b) = q_3
      • δ(q1,a)=q2\delta(q_1, a) = q_2, δ(q1,b)=q3\delta(q_1, b) = q_3
      • δ(q2,a)=q2\delta(q_2, a) = q_2, δ(q2,b)=q3\delta(q_2, b) = q_3
      • δ(q3,a)=q1\delta(q_3, a) = q_1, δ(q3,b)=q4\delta(q_3, b) = q_4
      • δ(q4,a)=q1\delta(q_4, a) = q_1, δ(q4,b)=q4\delta(q_4, b) = q_4
    • Total states: 55

Non-Deterministic Finite Automata (NFA) Design Principles

  • NFA State Interpretation:

    • In an NFA, states represent the degree of progress toward satisfying an acceptance condition rather than mutually exclusive global scenarios.
    • State q0q_0 typically denotes the state before reading the first symbol or the persistent process scanning for the initial symbol of an accepting pattern.
    • Non-determinism allows guessing whether an incoming symbol represents the start of a target sequence or part of an arbitrary prefix/suffix.
  • NFA: Strings Having Odd Number of 00s:

    • States:
      • q0q_0: Even number of 00s seen.
      • q1q_1: Odd number of 00s seen (Accepting state).
    • Transitions:
      • δ(q0,0)={q1}\delta(q_0, 0) = \{q_1\}, δ(q0,1)={q0}\delta(q_0, 1) = \{q_0\}
      • δ(q1,0)={q0}\delta(q_1, 0) = \{q_0\}, δ(q1,1)={q1}\delta(q_1, 1) = \{q_1\}
  • NFA: Second Symbol from the Last is 11:

    • Conceptual operation:
      • q0q_0: Scanning the input string; non-deterministically guesses when the symbol 11 is the second-to-last symbol.
      • q1q_1: Guessed that current 11 is the second-to-last symbol.
      • q2q_2: Exactly one symbol has been read after the guessed 11 (Accepting state).
    • Transitions:
      • δ(q0,0)={q0}\delta(q_0, 0) = \{q_0\}
      • δ(q0,1)={q0,q1}\delta(q_0, 1) = \{q_0, q_1\}
      • δ(q1,0)={q2}\delta(q_1, 0) = \{q_2\}
      • δ(q1,1)={q2}\delta(q_1, 1) = \{q_2\}
      • δ(q2,0)=∅\delta(q_2, 0) = \emptyset, δ(q2,1)=∅\delta(q_2, 1) = \emptyset
    • Rule constraint: Adding a self-loop on q1q_1 would incorrectly enforce that the first read 11 is fixed rather than guessed, breaking the second-last specification.
  • NFA: Strings Containing Substring 110110:

    • States:
      • q0q_0: Scanning string, searching for substring 110110.
      • q1q_1: Matched initial 11.
      • q2q_2: Matched sequence 1111.
      • q3q_3: Matched sequence 110110 (Accepting state).
    • Transitions:
      • δ(q0,0)={q0}\delta(q_0, 0) = \{q_0\}, δ(q0,1)={q0,q1}\delta(q_0, 1) = \{q_0, q_1\}
      • δ(q1,1)={q2}\delta(q_1, 1) = \{q_2\}
      • δ(q2,0)={q3}\delta(q_2, 0) = \{q_3\}
      • δ(q3,0)={q3}\delta(q_3, 0) = \{q_3\}, δ(q3,1)={q3}\delta(q_3, 1) = \{q_3\}
  • NFA: Starting with 0000:

    • States:
      • q0q_0: Start state, awaiting first symbol 00.
      • q1q_1: Matched first 00.
      • q2q_2: Matched 0000 (Accepting state).
    • Transitions:
      • δ(q0,0)={q1}\delta(q_0, 0) = \{q_1\}
      • δ(q1,0)={q2}\delta(q_1, 0) = \{q_2\}
      • δ(q2,0)={q2}\delta(q_2, 0) = \{q_2\}, δ(q2,1)={q2}\delta(q_2, 1) = \{q_2\}
  • NFA: Ending with 11:

    • States:
      • q0q_0: Scanning string.
      • q1q_1: Guessed that current symbol 11 is the final symbol (Accepting state).
    • Transitions:
      • δ(q0,0)={q0}\delta(q_0, 0) = \{q_0\}, δ(q0,1)={q0,q1}\delta(q_0, 1) = \{q_0, q_1\}
  • NFA: Having 101101 or 110110 as Substring:

    • States:
      • q0q_0: Scanning input.
      • q1q_1: Matched 11.
      • q2q_2: Matched 1010.
      • q3q_3: Matched 101101 (Accepting state).
      • q4q_4: Matched 1111.
      • q5q_5: Matched 110110 (Accepting state).
    • Transitions:
      • δ(q0,0)={q0}\delta(q_0, 0) = \{q_0\}, δ(q0,1)={q0,q1}\delta(q_0, 1) = \{q_0, q_1\}
      • δ(q1,0)={q2}\delta(q_1, 0) = \{q_2\}, δ(q1,1)={q4}\delta(q_1, 1) = \{q_4\}
      • δ(q2,1)={q3}\delta(q_2, 1) = \{q_3\}
      • δ(q4,0)={q5}\delta(q_4, 0) = \{q_5\}
      • δ(q3,0)={q3}\delta(q_3, 0) = \{q_3\}, δ(q3,1)={q3}\delta(q_3, 1) = \{q_3\}
      • δ(q5,0)={q5}\delta(q_5, 0) = \{q_5\}, δ(q5,1)={q5}\delta(q_5, 1) = \{q_5\}
  • NFA: Third Character is 11:

    • States:
      • q0q_0: Start state, awaiting 1st character.
      • q1q_1: 1st character scanned.
      • q2q_2: 2nd character scanned.
      • q3q_3: 3rd character scanned and confirmed as 11 (Accepting state).
    • Transitions:
      • δ(q0,0)={q1}\delta(q_0, 0) = \{q_1\}, δ(q0,1)={q1}\delta(q_0, 1) = \{q_1\}
      • δ(q1,0)={q2}\delta(q_1, 0) = \{q_2\}, δ(q1,1)={q2}\delta(q_1, 1) = \{q_2\}
      • δ(q2,1)={q3}\delta(q_2, 1) = \{q_3\}
      • δ(q3,0)={q3}\delta(q_3, 0) = \{q_3\}, δ(q3,1)={q3}\delta(q_3, 1) = \{q_3\}
  • NFA: Starting with cc and Ending with ss Over Σ={c,a,s}\Sigma = \{c, a, s\}:

    • States:
      • q0q_0: Start state.
      • q1q_1: Verified string started with cc.
      • q2q_2: Last symbol read is ss (Accepting state).
    • Transitions:
      • δ(q0,c)={q1}\delta(q_0, c) = \{q_1\}
      • δ(q1,c)={q1}\delta(q_1, c) = \{q_1\}, δ(q1,a)={q1}\delta(q_1, a) = \{q_1\}, δ(q1,s)={q1,q2}\delta(q_1, s) = \{q_1, q_2\}
    • Total states: 33
  • NFA: Ending with 0101:

    • States:
      • q0q_0: Scanning string.
      • q1q_1: Guessed 00 is penultimate symbol.
      • q2q_2: Read 11 following guessed 00 (Accepting state).
    • Transitions:
      • δ(q0,0)={q0,q1}\delta(q_0, 0) = \{q_0, q_1\}, δ(q0,1)={q0}\delta(q_0, 1) = \{q_0\}
      • δ(q1,1)={q2}\delta(q_1, 1) = \{q_2\}
  • NFA: Starting with "cat" and Ending with "bat" Over Σ={a,b,c,…,z}\Sigma = \{a, b, c, \dots, z\}:

    • States:
      • q0q_0: Initial state.
      • q1q_1: Read cc.
      • q2q_2: Read caca.
      • q3q_3: Read catcat.
      • q4q_4: Guessed bb is start of final "bat".
      • q5q_5: Read baba.
      • q6q_6: Matched batbat (Accepting state).
    • Transitions:
      • δ(q0,c)={q1}\delta(q_0, c) = \{q_1\}
      • δ(q1,a)={q2}\delta(q_1, a) = \{q_2\}
      • δ(q2,t)={q3}\delta(q_2, t) = \{q_3\}
      • δ(q3,Σ)={q3}\delta(q_3, \Sigma) = \{q_3\}, δ(q3,b)={q3,q4}\delta(q_3, b) = \{q_3, q_4\}
      • δ(q4,a)={q5}\delta(q_4, a) = \{q_5\}
      • δ(q5,t)={q6}\delta(q_5, t) = \{q_6\}
    • Total states: 77

Extended Transition Functions and State Traces

  • DFA State Trace for String w=10110101w = 10110101 (Testing Non-containment of 110110):

    • δ(q0,10110101)\delta(q_0, 10110101)
    • =δ(δ(q0,1),0110101)=δ(q1,0110101)= \delta(\delta(q_0, 1), 0110101) = \delta(q_1, 0110101)
    • =δ(δ(q1,0),110101)=δ(q0,110101)= \delta(\delta(q_1, 0), 110101) = \delta(q_0, 110101)
    • =δ(δ(q0,1),10101)=δ(q1,10101)= \delta(\delta(q_0, 1), 10101) = \delta(q_1, 10101)
    • =δ(δ(q1,1),0101)=δ(q2,0101)= \delta(\delta(q_1, 1), 0101) = \delta(q_2, 0101)
    • =δ(δ(q2,0),101)=δ(q3,101)= \delta(\delta(q_2, 0), 101) = \delta(q_3, 101)
    • =q3= q_3
    • Since q3q_3 is a non-accepting dead state, the string is rejected.
  • NFA Traces for Third Character is 11:

    • Input 00011100001110:
      • δ(q0,0)={q1}\delta(q_0, 0) = \{q_1\}
      • δ(q1,0)={q2}\delta(q_1, 0) = \{q_2\}
      • δ(q2,0)=∅\delta(q_2, 0) = \emptyset
      • Branch terminates in failure; string rejected.
    • Input 0010100101:
      • δ(q0,0)={q0,q1}\delta(q_0, 0) = \{q_0, q_1\}
      • δ(q1,0)→q2\delta(q_1, 0) \rightarrow q_2
      • δ(q2,1)→q3\delta(q_2, 1) \rightarrow q_3
      • δ(q3,0)→q3\delta(q_3, 0) \rightarrow q_3
      • δ(q3,1)→q3\delta(q_3, 1) \rightarrow q_3
      • State q3q_3 is reached; string accepted.
  • Formal Definition of NFA Extended Transition Function δ^\hat{\delta}:

    • Base case: δ^(q,ϵ)={q}\hat{\delta}(q, \epsilon) = \{q\}
    • Recursive step: For string w=xaw = xa where x∈Σ∗x \in \Sigma^* and a∈Σa \in \Sigma:
      • If δ^(q,x)={p1,p2,…,pk}\hat{\delta}(q, x) = \{p_1, p_2, \dots, p_k\}, then:
      • δ^(q,w)=⋃i=1kδ(pi,a)\hat{\delta}(q, w) = \bigcup_{i=1}^k \delta(p_i, a)
  • Trace of String 1011010110 on NFA (Second Symbol from Last is 11):

    • Initial condition: δ^(q0,ϵ)={q0}\hat{\delta}(q_0, \epsilon) = \{q_0\}
    • Symbol 11: δ^(q0,1)=δ(q0,1)={q0,q1}\hat{\delta}(q_0, 1) = \delta(q_0, 1) = \{q_0, q_1\}
    • Symbol 00: δ^(q0,10)=δ(q0,0)∪δ(q1,0)={q0}∪{q2}={q0,q2}\hat{\delta}(q_0, 10) = \delta(q_0, 0) \cup \delta(q_1, 0) = \{q_0\} \cup \{q_2\} = \{q_0, q_2\}
    • Symbol 11: δ^(q0,101)=δ(q0,1)∪δ(q2,1)={q0,q1}∪∅={q0,q1}\hat{\delta}(q_0, 101) = \delta(q_0, 1) \cup \delta(q_2, 1) = \{q_0, q_1\} \cup \emptyset = \{q_0, q_1\}
    • Symbol 11: δ^(q0,1011)=δ(q0,1)∪δ(q1,1)={q0,q1}∪{q2}={q0,q1,q2}\hat{\delta}(q_0, 1011) = \delta(q_0, 1) \cup \delta(q_1, 1) = \{q_0, q_1\} \cup \{q_2\} = \{q_0, q_1, q_2\}
    • Symbol 00: δ^(q0,10110)=δ(q0,0)∪δ(q1,0)∪δ(q2,0)={q0}∪{q2}∪∅={q0,q2}\hat{\delta}(q_0, 10110) = \delta(q_0, 0) \cup \delta(q_1, 0) \cup \delta(q_2, 0) = \{q_0\} \cup \{q_2\} \cup \emptyset = \{q_0, q_2\}
    • Result: Since the final set of reachable states {q0,q2}\{q_0, q_2\} contains the accepting state q2q_2, the string 1011010110 is accepted.

Automata Conversions: Powerset Construction and Epsilon-Closures

  • NFA to DFA Conversion via Powerset Construction:

    • Given NFA specification: states Q={p,q,r}Q = \{p, q, r\}, alphabet Σ={0,1}\Sigma = \{0, 1\}, start state pp, accepting state rr.
    • Transition table of original NFA:
      • δ(p,0)={p,q}\delta(p, 0) = \{p, q\}, δ(p,1)={p}\delta(p, 1) = \{p\}
      • δ(q,0)=∅\delta(q, 0) = \emptyset, δ(q,1)={r}\delta(q, 1) = \{r\}
      • δ(r,0)={p,r}\delta(r, 0) = \{p, r\}, δ(r,1)={r}\delta(r, 1) = \{r\}
    • Complete powerset: 2Q=23=82^Q = 2^3 = 8 subsets: ∅,{p},{q},{r},{p,q},{p,r},{q,r},{p,q,r}\emptyset, \{p\}, \{q\}, \{r\}, \{p, q\}, \{p, r\}, \{q, r\}, \{p, q, r\}.
    • Powerset evaluation:
      • δ({p},0)={p,q}\delta(\{p\}, 0) = \{p, q\}, δ({p},1)={p}\delta(\{p\}, 1) = \{p\}
      • δ({q},0)=∅\delta(\{q\}, 0) = \emptyset, δ({q},1)={r}\delta(\{q\}, 1) = \{r\}
      • δ({r},0)={p,r}\delta(\{r\}, 0) = \{p, r\}, δ({r},1)={r}\delta(\{r\}, 1) = \{r\}
      • δ({p,q},0)={p,q}∪∅={p,q}\delta(\{p, q\}, 0) = \{p, q\} \cup \emptyset = \{p, q\}
      • δ({p,q},1)={p}∪{r}={p,r}\delta(\{p, q\}, 1) = \{p\} \cup \{r\} = \{p, r\}
      • δ({p,r},0)={p,q}∪{p,r}={p,q,r}\delta(\{p, r\}, 0) = \{p, q\} \cup \{p, r\} = \{p, q, r\}
      • δ({p,r},1)={p}∪{r}={p,r}\delta(\{p, r\}, 1) = \{p\} \cup \{r\} = \{p, r\}
      • δ({q,r},0)=∅∪{p,r}={p,r}\delta(\{q, r\}, 0) = \emptyset \cup \{p, r\} = \{p, r\}
      • δ({q,r},1)={r}∪{r}={r}\delta(\{q, r\}, 1) = \{r\} \cup \{r\} = \{r\}
      • δ({p,q,r},0)={p,q}∪∅∪{p,r}={p,q,r}\delta(\{p, q, r\}, 0) = \{p, q\} \cup \emptyset \cup \{p, r\} = \{p, q, r\}
      • δ({p,q,r},1)={p}∪{r}∪{r}={p,r}\delta(\{p, q, r\}, 1) = \{p\} \cup \{r\} \cup \{r\} = \{p, r\}
    • Reachable DFA states from start state {p}\{p\}:
      • Initial state: {p}\{p\}
      • From {p}\{p\}: on 0→{p,q}0 \rightarrow \{p, q\}; on 1→{p}1 \rightarrow \{p\}
      • From {p,q}\{p, q\}: on 0→{p,q}0 \rightarrow \{p, q\}; on 1→{p,r}1 \rightarrow \{p, r\}
      • From {p,r}\{p, r\}: on 0→{p,q,r}0 \rightarrow \{p, q, r\}; on 1→{p,r}1 \rightarrow \{p, r\}
      • From {p,q,r}\{p, q, r\}: on 0→{p,q,r}0 \rightarrow \{p, q, r\}; on 1→{p,r}1 \rightarrow \{p, r\}
    • Final reachable states: {{p},{p,q},{p,r},{p,q,r}}\{\{p\}, \{p, q\}, \{p, r\}, \{p, q, r\}\}.
    • Final accepting states (any state containing rr): {{p,r},{p,q,r}}\{\{p, r\}, \{p, q, r\}\}.
  • ϵ\epsilon-Closure Computation (ECLOSE\text{ECLOSE}):

    • ECLOSE(q)\text{ECLOSE}(q) is the set of all states reachable from state qq via zero or more ϵ\epsilon-transitions.
    • Example 1:
      • ECLOSE(p)={p,q,r}\text{ECLOSE}(p) = \{p, q, r\}
      • ECLOSE(q)={q}\text{ECLOSE}(q) = \{q\}
      • ECLOSE(r)={p,q,r}\text{ECLOSE}(r) = \{p, q, r\}
      • Since start state pp has r∈ECLOSE(p)r \in \text{ECLOSE}(p), empty string ϵ\epsilon (length 00) is accepted.
      • Transition computations:
        • δ(p,a)={q}\delta(p, a) = \{q\}, δ(q,a)={p}\delta(q, a) = \{p\}, δ(r,a)={r}\delta(r, a) = \{r\}
        • Union={p,q,r}  ⟹  ECLOSE({p,q,r})={p,q,r}\text{Union} = \{p, q, r\} \implies \text{ECLOSE}(\{p, q, r\}) = \{p, q, r\}
        • δ(p,b)={p,r}\delta(p, b) = \{p, r\}, δ(q,b)=∅\delta(q, b) = \emptyset, δ(r,b)={p}\delta(r, b) = \{p\}
        • Union={p,r}  ⟹  ECLOSE({p,r})={p,q,r}\text{Union} = \{p, r\} \implies \text{ECLOSE}(\{p, r\}) = \{p, q, r\}
      • Resulting DFA contains exactly one reachable state: {p,q,r}\{p, q, r\}, which acts as an accepting self-loop state on all inputs a,ba, b.
  • ϵ\epsilon-NFA to DFA Conversion (3-Input System Σ={a,b,c}\Sigma = \{a, b, c\}):

    • Given ϵ\epsilon-closures:
      • ECLOSE(p)={p,q,r}\text{ECLOSE}(p) = \{p, q, r\}
      • ECLOSE(q)={q}\text{ECLOSE}(q) = \{q\}
      • ECLOSE(r)={r}\text{ECLOSE}(r) = \{r\}
    • Start state of DFA: A=ECLOSE(p)={p,q,r}A = \text{ECLOSE}(p) = \{p, q, r\}. Since it contains rr, AA is an accepting state.
    • Evaluating transitions from A={p,q,r}A = \{p, q, r\}:
      • Input aa:
        • δ(p,a)=∅\delta(p, a) = \emptyset, δ(q,a)={p}\delta(q, a) = \{p\}, δ(r,a)=∅\delta(r, a) = \emptyset
        • Union={p}\text{Union} = \{p\}
        • ECLOSE({p})={p,q,r}=A\text{ECLOSE}(\{p\}) = \{p, q, r\} = A
      • Input bb:
        • δ(p,b)={q}\delta(p, b) = \{q\}, δ(q,b)={r}\delta(q, b) = \{r\}, δ(r,b)=∅\delta(r, b) = \emptyset
        • Union={q,r}\text{Union} = \{q, r\}
        • ECLOSE({q,r})=ECLOSE(q)∪ECLOSE(r)={q}∪{r}={q,r}=B\text{ECLOSE}(\{q, r\}) = \text{ECLOSE}(q) \cup \text{ECLOSE}(r) = \{q\} \cup \{r\} = \{q, r\} = B
      • Input cc:
        • δ(p,c)={r}\delta(p, c) = \{r\}, δ(q,c)={p,q}\delta(q, c) = \{p, q\}, δ(r,c)=∅\delta(r, c) = \emptyset
        • Union={p,q,r}\text{Union} = \{p, q, r\}
        • ECLOSE({p,q,r})={p,q,r}=A\text{ECLOSE}(\{p, q, r\}) = \{p, q, r\} = A
    • Evaluating transitions from B={q,r}B = \{q, r\}:
      • Input aa:
        • δ(q,a)={p}\delta(q, a) = \{p\}, δ(r,a)=∅  ⟹  Union={p}\delta(r, a) = \emptyset \implies \text{Union} = \{p\}
        • ECLOSE({p})={p,q,r}=A\text{ECLOSE}(\{p\}) = \{p, q, r\} = A
      • Input bb:
        • δ(q,b)={r}\delta(q, b) = \{r\}, δ(r,b)=∅  ⟹  Union={r}\delta(r, b) = \emptyset \implies \text{Union} = \{r\}
        • ECLOSE({r})={r}=C\text{ECLOSE}(\{r\}) = \{r\} = C
      • Input cc:
        • δ(q,c)={p,q}\delta(q, c) = \{p, q\}, δ(r,c)=∅  ⟹  Union={p,q}\delta(r, c) = \emptyset \implies \text{Union} = \{p, q\}
        • ECLOSE({p,q})={p,q,r}=A\text{ECLOSE}(\{p, q\}) = \{p, q, r\} = A
    • Evaluating transitions from C={r}C = \{r\}:
      • δ(r,a)=∅  ⟹  ECLOSE(∅)=∅=D\delta(r, a) = \emptyset \implies \text{ECLOSE}(\emptyset) = \emptyset = D
      • δ(r,b)=∅  ⟹  ECLOSE(∅)=∅=D\delta(r, b) = \emptyset \implies \text{ECLOSE}(\emptyset) = \emptyset = D
      • δ(r,c)=∅  ⟹  ECLOSE(∅)=∅=D\delta(r, c) = \emptyset \implies \text{ECLOSE}(\emptyset) = \emptyset = D
    • State D=∅D = \emptyset is the dead/trap state.
  • ϵ\epsilon-NFA to Standard NFA Conversion:

    • Transition rule: δ′(q,a)=ECLOSE(δ(ECLOSE(q),a))\delta'(q, a) = \text{ECLOSE}(\delta(\text{ECLOSE}(q), a)).
    • Accepting states: Any state whose ϵ\epsilon-closure contains an original accepting state.
    • For state pp: ECLOSE(p)={p,q,r}\text{ECLOSE}(p) = \{p, q, r\}. Since rr is accepting, pp becomes an accepting state in the NFA.
    • Transitions for state pp:
      • δ′(p,a)=ECLOSE(δ({p,q,r},a))=ECLOSE({p})={p,q,r}\delta'(p, a) = \text{ECLOSE}(\delta(\{p, q, r\}, a)) = \text{ECLOSE}(\{p\}) = \{p, q, r\}
      • δ′(p,b)=ECLOSE(δ({p,q,r},b))=ECLOSE({q,r})={q,r}\delta'(p, b) = \text{ECLOSE}(\delta(\{p, q, r\}, b)) = \text{ECLOSE}(\{q, r\}) = \{q, r\}
      • δ′(p,c)=ECLOSE(δ({p,q,r},c))=ECLOSE({p,q,r})={p,q,r}\delta'(p, c) = \text{ECLOSE}(\delta(\{p, q, r\}, c)) = \text{ECLOSE}(\{p, q, r\}) = \{p, q, r\}
    • Transitions for state qq: ECLOSE(q)={q}\text{ECLOSE}(q) = \{q\}
      • δ′(q,a)=ECLOSE(δ(q,a))=ECLOSE({p})={p,q,r}\delta'(q, a) = \text{ECLOSE}(\delta(q, a)) = \text{ECLOSE}(\{p\}) = \{p, q, r\}
      • δ′(q,b)=ECLOSE(δ(q,b))=ECLOSE({r})={r}\delta'(q, b) = \text{ECLOSE}(\delta(q, b)) = \text{ECLOSE}(\{r\}) = \{r\}
      • δ′(q,c)=ECLOSE(δ(q,c))=ECLOSE({p,q})={p,q,r}\delta'(q, c) = \text{ECLOSE}(\delta(q, c)) = \text{ECLOSE}(\{p, q\}) = \{p, q, r\}
    • Transitions for state rr: ECLOSE(r)={r}\text{ECLOSE}(r) = \{r\}
      • δ′(r,a)=∅\delta'(r, a) = \emptyset
      • δ′(r,b)=∅\delta'(r, b) = \emptyset
      • δ′(r,c)=∅\delta'(r, c) = \emptyset

Finite State Machines with Outputs: Moore and Mealy Machines

  • Theoretical Definitions:
    • Moore Machine: Output depends strictly on the current state. Represented as a 6-tuple (Q,Σ,Δ,δ,λ,q0)(Q, \Sigma, \Delta, \delta, \lambda, q_0), where λ:Q→Δ\lambda: Q \rightarrow \Delta.
    • Mealy Machine: Output depends on both the current state and the current input symbol. Represented as a 6-tuple (Q,Σ,Δ,δ,λ′,q0)(Q, \Sigma, \Delta, \delta, \lambda', q_0), where \lambda': Q \times \Sigma \rightarrow \Delta$.\n\n* **Moore to Mealy Conversion Algorithm:**\n * Conversion formula: \lambda'(q, a) = \lambda(\delta(q, a)).\n * The output associated with an incoming transition on input atostateto stateq' = \delta(q, a)issettotheMooreoutputofstateis set to the Moore output of stateq',,\lambda(q').\n * Given Moore transition table:\n * State q_0:Nextstateon: Next state ona=0isisq_3;Nextstateon; Next state ona=1isisq_1;Output; Output= 0.\n * State q_1:Nextstateon: Next state ona=0isisq_1;Nextstateon; Next state ona=1isisq_2;Output; Output= 1.\n * State q_2:Nextstateon: Next state ona=0isisq_2;Nextstateon; Next state ona=1isisq_3;Output; Output= 0.\n * State q_3:Nextstateon: Next state ona=0isisq_3;Nextstateon; Next state ona=1isisq_0;Output; Output= 0.\n * Computing Mealy outputs:\n * At q_0:on: on0 \rightarrow q_3,output, output\lambda(q_3) = 0;on; on1 \rightarrow q_1,output, output\lambda(q_1) = 1.\n * At q_1:on: on0 \rightarrow q_1,output, output\lambda(q_1) = 1;on; on1 \rightarrow q_2,output, output\lambda(q_2) = 0.\n * At q_2:on: on0 \rightarrow q_2,output, output\lambda(q_2) = 0;on; on1 \rightarrow q_3,output, output\lambda(q_3) = 0.\n * At q_3:on: on0 \rightarrow q_3,output, output\lambda(q_3) = 0;on; on1 \rightarrow q_0,output, output\lambda(q_0) = 0.\n\n* **Mealy to Moore Conversion Algorithm:**\n * A Moore state must have a fixed output. If a Mealy state receives incoming transitions with different output symbols, the state must be split into multiple copies, one for each distinct incoming output.\n * A dummy start state S must be introduced because a Moore machine produces an output before reading the first input symbol.\n * Given Mealy transition table:\n * State q_1:on: ona=0 \rightarrow q_3(out:(out:0);on); ona=1 \rightarrow q_2(out:(out:0).\n * State q_2:on: ona=0 \rightarrow q_1(out:(out:1);on); ona=1 \rightarrow q_4(out:(out:0).\n * State q_3:on: ona=0 \rightarrow q_2(out:(out:1);on); ona=1 \rightarrow q_1(out:(out:1).\n * State q_4:on: ona=0 \rightarrow q_4(out:(out:1);on); ona=1 \rightarrow q_3(out:(out:0).\n * Analysis of incoming outputs per state:\n * State q_1:Incomingoutputsareall: Incoming outputs are all1(from(fromq_2onon0/1,from, fromq_3onon1/1).Output). Output= 1.Retainassinglestate. Retain as single stateA = (q_1, 1).\n * State q_2:Incomingoutputsare: Incoming outputs are0(from(fromq_1onon1/0)and) and1(from(fromq_3onon0/1).Splitinto). Split intoB = (q_2, 0)andandC = (q_2, 1).\n * State q_3:Incomingoutputsareall: Incoming outputs are all0(from(fromq_1onon0/0,from, fromq_4onon1/0).Output). Output= 0.Retainassinglestate. Retain as single stateD = (q_3, 0).\n * State q_4:Incomingoutputsare: Incoming outputs are0(from(fromq_2onon1/0)and) and1(from(fromq_4onon0/1).Splitinto). Split intoE = (q_4, 0)andandF = (q_4, 1).\n * Initial state assignment: Original start was q_1.Introducedummystate. Introduce dummy stateSwithoutputwith output0(orarbitrary),copyingtransitionsof(or arbitrary), copying transitions ofq_1:\n * From Sonon0 \rightarrow (q_3, \text{out } 0) = D\n * From Sonon1 \rightarrow (q_2, \text{out } 0) = B\n * Transitions for split Moore states:\n * From A (q_1):on: on0 \rightarrow D;on; on1 \rightarrow B\n * From B (q_2, 0):on: on0 \rightarrow A;on; on1 \rightarrow E\n * From C (q_2, 1):on: on0 \rightarrow A;on; on1 \rightarrow E\n * From D (q_3):on: on0 \rightarrow C;on; on1 \rightarrow A\n * From E (q_4, 0):on: on0 \rightarrow F;on; on1 \rightarrow D\n * From F (q_4, 1):on: on0 \rightarrow F;on; on1 \rightarrow D\n\n\n# State Minimization of Finite Automata\n\n* **Minimization via Partition Refinement (8-State System):**\n * Transition table with states q_0throughthroughq_7:\n * q_0:on: on0 \rightarrow q_1,on, on1 \rightarrow q_5\n * q_1:on: on0 \rightarrow q_6,on, on1 \rightarrow q_2\n * q_2(Final):on(Final): on0 \rightarrow q_0,on, on1 \rightarrow q_2\n * q_3:on: on0 \rightarrow q_2,on, on1 \rightarrow q_6\n * q_4:on: on0 \rightarrow q_7,on, on1 \rightarrow q_5\n * q_5:on: on0 \rightarrow q_2,on, on1 \rightarrow q_6\n * q_6:on: on0 \rightarrow q_6,on, on1 \rightarrow q_4\n * q_7:on: on0 \rightarrow q_6,on, on1 \rightarrow q_2\n * Step 1: Partition into final and non-final states:\n * \Pi_0 = {{q_2}, {q_0, q_1, q_3, q_4, q_5, q_6, q_7}}\n * Group A = {q_2}(Final),Group(Final), GroupB = {q_0, q_1, q_3, q_4, q_5, q_6, q_7} (Non-final).\n * Step 2: Signatures on (0, 1)underunder\Pi_0:\n * q_0 \rightarrow (q_1, q_5) \in (B, B)\n * q_1 \rightarrow (q_6, q_2) \in (B, A)\n * q_3 \rightarrow (q_2, q_6) \in (A, B)\n * q_4 \rightarrow (q_7, q_5) \in (B, B)\n * q_5 \rightarrow (q_2, q_6) \in (A, B)\n * q_6 \rightarrow (q_6, q_4) \in (B, B)\n * q_7 \rightarrow (q_6, q_2) \in (B, A)\n * Constructing \Pi_1:\n * \Pi_1 = {{q_2}, {q_0, q_4, q_6}, {q_1, q_7}, {q_3, q_5}}\n * Label: A = {q_2},,B = {q_0, q_4, q_6},,C = {q_1, q_7},,D = {q_3, q_5}.\n * Step 3: Refine group Bunderunder\Pi_1:\n * q_0 \rightarrow q_1 \in C, q_5 \in D \implies (C, D)\n * q_4 \rightarrow q_7 \in C, q_5 \in D \implies (C, D)\n * q_6 \rightarrow q_6 \in B, q_4 \in B \implies (B, B)\n * Group Bsplitsintosplits into{q_0, q_4}andand{q_6}.\n * Checking other groups under \Pi_1:\n * For C = {q_1, q_7}::q_1 \rightarrow (q_6, q_2) \in (B, A);;q_7 \rightarrow (q_6, q_2) \in (B, A). No split.\n * For D = {q_3, q_5}::q_3 \rightarrow (q_2, q_6) \in (A, B);;q_5 \rightarrow (q_2, q_6) \in (A, B). No split.\n * Constructing \Pi_2:\n * \Pi_2 = {{q_2}, {q_0, q_4}, {q_6}, {q_1, q_7}, {q_3, q_5}}\n * Step 4: Check stability (\Pi_3):\n * \Pi_3 = \Pi_2. The process terminates.\n * Final minimized DFA has 5 states:\n * Start state: {q_0, q_4}\n * Final state: {q_2}\n * Other states: {q_6},,{q_1, q_7},,{q_3, q_5}\n\n* **Minimization via Partition Refinement (6-State System):**\n * Given states: q_0, q_1, q_2, q_3, q_4, q_5withacceptingstateswith accepting statesF = {q_3, q_5}.\n * q_0:on: on0 \rightarrow q_1,on, on1 \rightarrow q_3\n * q_1:on: on0 \rightarrow q_0,on, on1 \rightarrow q_3\n * q_2:on: on0 \rightarrow q_1,on, on1 \rightarrow q_4\n * q_3:on: on0 \rightarrow q_5,on, on1 \rightarrow q_5\n * q_4:on: on0 \rightarrow q_3,on, on1 \rightarrow q_3\n * q_5:on: on0 \rightarrow q_5,on, on1 \rightarrow q_5\n * Partition step 1:\n * \Pi_0 = {{q_3, q_5}, {q_0, q_1, q_2, q_4}}\n * Group A = {q_3, q_5},Group, GroupB = {q_0, q_1, q_2, q_4}.\n * Partition step 2:\n * q_3 \rightarrow (q_5, q_5) \in (A, A)\n * q_5 \rightarrow (q_5, q_5) \in (A, A)\n * q_0 \rightarrow (q_1, q_3) \in (B, A)\n * q_1 \rightarrow (q_0, q_3) \in (B, A)\n * q_2 \rightarrow (q_1, q_4) \in (B, B)\n * q_4 \rightarrow (q_3, q_3) \in (A, A)\n * \Pi_1 = {{q_3, q_5}, {q_0, q_1}, {q_2}, {q_4}}\n * Partition step 3:\n * Comparing q_0andandq_1:bothtransitiontogroup: both transition to group{q_0, q_1}onon0andtoand to{q_3, q_5}onon1.\n * Comparing q_3andandq_5:bothtransitionto: both transition to{q_3, q_5}onon0andand1.\n * \Pi_2 = {{q_3, q_5}, {q_0, q_1}, {q_2}, {q_4}}\n * \Pi_2 = \Pi_1. Process terminates.\n * Final minimized DFA has 4 states:\n * {q_0, q_1} (Start state)\n * {q_2}\n * {q_4}\n * {q_3, q_5} (Final accepting state)\n\n\n# Regular Expressions: Design Principles and Patterns\n\n* **At Least One aandatLeastOneand at Least OnebOverOver\Sigma = {a, b, c}:**\n * Two mutually exclusive chronological cases:\n * Case 1: aappearsbeforeappears beforeb::(a + b + c)^* a (a + b + c)^* b (a + b + c)^\n * Case 2: bappearsbeforeappears beforea::(a + b + c)^ b (a + b + c)^* a (a + b + c)^\n * Combined expression:\n * (a + b + c)^ a (a + b + c)^* b (a + b + c)^* + (a + b + c)^* b (a + b + c)^* a (a + b + c)^\n\n* **Tenth Symbol from Right End is 1OverOver\Sigma = {0, 1}:**\n * The prefix can be arbitrary, followed by 1,followedbyexactly, followed by exactly9 binary positions:\n * (0 + 1)^ 1 (0 + 1)^9\n * Expanded form: (0 + 1)^* 1 (0 + 1)(0 + 1)(0 + 1)(0 + 1)(0 + 1)(0 + 1)(0 + 1)(0 + 1)(0 + 1)\n\n* **Number of 0sisDivisiblebys is Divisible by5OverOver\Sigma = {0, 1}:**\n * Allowed counts of 0s:s:0, 5, 10, 15, \dots\n * Any number of 1smayappearbefore,between,orafterthes may appear before, between, or after the0s.\n * Elementary block containing five 0s:s:0 1^* 0 1^* 0 1^* 0 1^* 0\n * Regular expression: 1^(0 1^ 0 1^* 0 1^* 0 1^* 0 1^)^\n\n* **Strings Not Containing Substring 101OverOver\Sigma = {0, 1}:**\n * Safe building blocks that cannot create the sequence 101underconcatenation:under concatenation:0,,11,,100.\n * Valid terminal endings that do not complete 101::\epsilon,,1,,10.\n * Regular expression: (0 + 11 + 100)^* (\epsilon + 1 + 10)\n\n* **Equal Number of 0sands and1sSuchThatNoPrefixDifferenceExceedss Such That No Prefix Difference Exceeds1:**\n * Condition: In every prefix, |\text{count}(0) - \text{count}(1)| \le 1.\n * An immediate 0cannotbefollowedbyanothercannot be followed by another0,anda, and a1cannotbefollowedbyanothercannot be followed by another1.\n * The string must be composed of balanced consecutive pairs: 01oror10.\n * Regular expression: (01 + 10)^\n\n* **Odd Number of 0sOvers Over\Sigma = {0, 1}:**\n * After seeing the first 0,anyadditional, any additional0s must occur in pairs.\n * Pair block: (0 1^ 0 1^)^\n * Regular expression: 1^* 0 (0 1^* 0 1^)^ 1^\n\n* **Strings Not Containing Substring 11OverOver\Sigma = {0, 1}:**\n * Every 1mustbefollowedimmediatelybyamust be followed immediately by a0, or be the final symbol of the string.\n * Safe recurring block: (0 + 10)\n * Terminal ending: (\epsilon + 1)\n * Regular expression: (0 + 10)^ (\epsilon + 1)\n\n* **Structural Deconstruction of Regular Expressions:**\n * Expression: (1 + \epsilon)(00^1)^ 0^\n * (1 + \epsilon):Startswithasingle: Starts with a single1 or nothing (empty string).\n * (00^1)^:Repeatedblocksconsistingofoneormore: Repeated blocks consisting of one or more0sfollowedbyasingles followed by a single1.\n * 0^:Finisheswithzeroormore: Finishes with zero or more0s.\n * Expression: (0 + 10)^* 1^\n * Repeats blocks of either 0oror10anynumberoftimes,thenconcludeswithanynumberofany number of times, then concludes with any number of1s.\n\n\n# Conversion of Finite Automata to Regular Expressions\n\n* **Inductive Formulation (R_{ij}^{(k)} Method):**\n * R_{ij}^{(k)}representsthesetofallstringsthattaketheautomatonfromstaterepresents the set of all strings that take the automaton from stateitostateto statejwithoutpassingthroughanyintermediatestatehigherthanwithout passing through any intermediate state higher thank.\n * Recursive formula:\n * R_{ij}^{(k)} = R_{ij}^{(k-1)} + R_{ik}^{(k-1)} (R_{kk}^{(k-1)})^ R_{kj}^{(k-1)}\n * Base case (k = 0):\n * If i = j::R_{ii}^{(0)} = \epsilon + \sum a(where(whereaisalabelonaself−loopfromis a label on a self-loop fromitotoi).\n * If i eq j::R_{ij}^{(0)} = \sum a(where(whereaisalabelonadirecttransitionfromis a label on a direct transition fromitotoj),or), or\emptyset if no edge exists.\n\n* **Inductive Computation for 2-State DFA:**\n * States: 1(Start)and(Start) and2 (Accepting).\n * Transitions: \delta(1, 0) = 2,,\delta(1, 1) = 1,,\delta(2, 0) = 2,,\delta(2, 1) = 2.\n * At k = 0:\n * R_{11}^{(0)} = \epsilon + 1\n * R_{12}^{(0)} = 0\n * R_{21}^{(0)} = \emptyset\n * R_{22}^{(0)} = \epsilon + 0 + 1\n * At k = 1:\n * R_{11}^{(1)} = R_{11}^{(0)} + R_{11}^{(0)} (R_{11}^{(0)})^* R_{11}^{(0)} = (\epsilon + 1) + (\epsilon + 1)(\epsilon + 1)^* (\epsilon + 1) = 1^\n * R_{12}^{(1)} = R_{12}^{(0)} + R_{11}^{(0)} (R_{11}^{(0)})^ R_{12}^{(0)} = 0 + (\epsilon + 1)(\epsilon + 1)^* 0 = 0 + 1^* 0 = 1^* 0\n * R_{21}^{(1)} = R_{21}^{(0)} + R_{21}^{(0)} (R_{11}^{(0)})^* R_{11}^{(0)} = \emptyset + \emptyset = \emptyset\n * R_{22}^{(1)} = R_{22}^{(0)} + R_{21}^{(0)} (R_{11}^{(0)})^* R_{12}^{(0)} = (\epsilon + 0 + 1) + \emptyset = \epsilon + 0 + 1\n * At k = 2(FinalREtoreachstate(Final RE to reach state2fromstartstatefrom start state1):\n * R_{12}^{(2)} = R_{12}^{(1)} + R_{12}^{(1)} (R_{22}^{(1)})^* R_{22}^{(1)}\n * = 1^* 0 + 1^* 0 (\epsilon + 0 + 1)^* (\epsilon + 0 + 1)\n * Since (\epsilon + 0 + 1)^* = (0 + 1)^,appending, appending(\epsilon + 0 + 1) simplifies to:\n * = 1^ 0 + 1^* 0 (0 + 1)^* = 1^* 0 (0 + 1)^\n\n* **State Elimination Method:**\n * Formula for eliminating intermediate state q_kbetweenpredecessorbetween predecessorq_iandsuccessorand successorq_j:\n * R_{ij}' = R_{ij} + Q_i S^ P_j\n * R_{ij}:Directexistingregularexpressionfrom: Direct existing regular expression fromq_itotoq_j.\n * Q_i:Labelenteringtheeliminatedstatefrom: Label entering the eliminated state fromq_i.\n * S:Labeloftheself−loopontheeliminatedstate(: Label of the self-loop on the eliminated state (S^* = \epsilon if no self-loop).\n * P_j:Labelleavingtheeliminatedstateto: Label leaving the eliminated state toq_j.\n * Application on 3-State DFA (States q_1, q_2, q_3,eliminate, eliminateq_2):\n * Path q_1 \rightarrow q_2 \rightarrow q_1::S = 0,,S^* = \epsilon,,Q_i = 0,,P_j = 0,,R_{11} = 0 \implies R = 00.\n * Path q_1 \rightarrow q_2 \rightarrow q_3::S^* = \epsilon,,Q_i = 0,,P_j = 1,,R_{13} = 1 \implies S = 1 + 01.\n * Path q_3 \rightarrow q_2 \rightarrow q_1::S^* = \epsilon,,Q_i = 0,,P_j = 0,,R_{31} = 1 \implies T = 1 + 00.\n * Path q_3 \rightarrow q_2 \rightarrow q_3::S^* = \epsilon,,Q_i = 0,,P_j = 1,,R_{33} = \emptyset \implies U = 01.\n * Final regular expression between start q_1andacceptand acceptq_3:\n * (R + S U^* T)^* S U^* = (00 + (1 + 01)(01)^* (1 + 00))^* (1 + 01)(01)^\n\n* **Arden's Theorem:**\n * **Theorem Statement:** If PandandQaretworegularexpressionsoverare two regular expressions over\Sigma,andif, and if\epsilon otin P,thentheequation, then the equationR = Q + RPhasauniquesolutiongivenbyhas a unique solution given byR = QP^.\n* Example 1 (2-State Automaton):\n * Equations: R_1 = \epsilon + R_1 1,,R_2 = R_1 0 + R_2 0 + R_2 1.\n * Solving for R_1::R_1 = \epsilon (1)^* = 1^.\n * Substituting R_1intointoR_2::R_2 = 1^ 0 + R_2 (0 + 1).\n * Applying Arden's Theorem on R_2::Q = 1^* 0,,P = (0 + 1) \implies R_2 = 1^* 0 (0 + 1)^\n* Example 2 (3-State System):\n * R_1 = \epsilon + R_2 0 + R_3 1\n * R_2 = R_1 0 + R_2 1\n * R_3 = R_1 1 + R_2 1\n * Applying Arden's theorem to R_2::R_2 = R_1 0 (1)^\n * Substitute R_2intointoR_3::R_3 = R_1 1 + R_1 0 1^* 1 = R_1 (1 + 0 1^* 1)\n * Substitute into R_1::R_1 = \epsilon + R_1 [0 1^* 0 + (1 + 0 1^* 1) 1]\n * R_1 = [0 1^* 0 + 1 + 0 1^* 1]^\n\n\n# Conversion of Regular Expressions to Finite Automata\n\n* **Thompson's Construction (Structural Induction):**\n * Basic primitives:\n * For symbol a:Twostateswithadirectededgelabeled: Two states with a directed edge labeleda.\n * For \epsilon:Twostateswithan: Two states with an\epsilon-transition.\n * Union (R_1 + R_2):\n * Introduce new start state with \epsilon−transitionstostartsof-transitions to starts ofR_1andandR_2.\n * Join final states of R_1andandR_2toanewacceptstateviato a new accept state via\epsilon-transitions.\n * Concatenation (R_1 R_2):\n * Connect the accepting state of R_1tothestartstateofto the start state ofR_2viaanvia an\epsilon-transition.\n * Kleene Star (R_1^):\n * Introduce new start and final states.\n * Add \epsilon−transitionfromstarttoaccept(torecognize-transition from start to accept (to recognize\epsilon).\n * Add \epsilon−transitionfromfinalstatebacktothestartof-transition from final state back to the start ofR_1 for repetition.\n\n* **Construction for (0 + 1)^* 1 (0 + 1):**\n * Sub-automaton for (0 + 1):States: Statesq_0, q_1((0branch)andbranch) andq_2, q_3((1branch),bracketedbystartbranch), bracketed by startq_4andjoinand joinq_5withwith\epsilon-transitions.\n * Sub-automaton for (0 + 1)^:Bracketwithinitialstate: Bracket with initial stateq_6andjoinstateand join stateq_7withforwardandbackwardwith forward and backward\epsilon-loops.\n * Concatenation with 1:Connect: Connectq_7viavia\epsilontostateto stateq_8,thensymbol, then symbol1totoq_9.\n * Concatenation with (0 + 1):Connect: Connectq_9viavia\epsilontothesecondto the second(0 + 1)unitconsistingofstatesunit consisting of statesq_{10}throughthroughq_{15}.\n\n* **Construction for 0 1^:**\n * Primitive for 0::q_0 \xrightarrow{0} q_1.\n * Sub-automaton for 1^:Primitive: Primitiveq_2 \xrightarrow{1} q_3,wrappedby, wrapped byq_4andandq_5withwith\epsilon−transitions:-transitions:q_4 \xrightarrow{\epsilon} q_2,,q_3 \xrightarrow{\epsilon} q_5,,q_3 \xrightarrow{\epsilon} q_2,and, andq_4 \xrightarrow{\epsilon} q_5.\n * Concatenation: Connect q_1totoq_4viaanvia an\epsilon-transition.\n\n\n# Equivalence of Automata and Table-Filling Algorithm\n\n* **Table-Filling (Myhill-Nerode Pair Equivalence) Algorithm:**\n * Objective: Identify whether initial states of two DFAs are equivalent (i.e., accept the exact same language).\n * For a combined state space of size n,generateall, generate alln(n-1)/2unorderedstatepairsunordered state pairs(p, q).\n * Step 1: Mark with an Xallpairsall pairs(p, q)whereonestateisaccepting(where one state is accepting (F)andtheotherisnon−accepting() and the other is non-accepting (Q - F).\n * Step 2: Iteratively check each unmarked pair (p, q).Ifthereexistsanysymbol. If there exists any symbola \in \Sigmasuchthatsuch that(\delta(p, a), \delta(q, a))isalreadymarkedis already markedX,thenmark, then mark(p, q)withanwith anX.\n * Step 3: Repeat until a complete pass produces no new marks.\n * Conclusion: If the pair containing the initial states (q_{01}, q_{02}) remains unmarked, the two automatons are equivalent.\n\n* **5-State Equivalence Verification:**\n * Combined states: A, B, C, D, E.Totalpairs=. Total pairs =5(4)/2 = 10.\n * Final states: B, E.Non−final:. Non-final:A, C, D.\n * Step 1 marks: AB, AE, BC, BD, CE, DEaremarkedare markedX.\n * Step 2 checking remaining pairs: AC, AD, BE, CD:\n * For AC:on: on0 \rightarrow AD;on; on1 \rightarrow BE.Neither. NeitherADnornorBEismarked.is marked.AC remains unmarked.\n * For AD:on: on0 \rightarrow AD;on; on1 \rightarrow BE. Remains unmarked.\n * For BE:on: on0 \rightarrow AC;on; on1 \rightarrow BE. Remains unmarked.\n * For CD: both map to unmarked pairs.\n * Initial states AandandCremainunmarked;therefore,remain unmarked; therefore,A \equiv C and both automata accept the identical language.\n\n\n# Pumping Lemma for Regular Languages and Closure Properties\n\n* **Pumping Lemma Theorem:**\n * Let Lbearegularlanguage.Thereexistsanintegerconstantbe a regular language. There exists an integer constantn(thepumpinglength)suchthatforanystring(the pumping length) such that for any stringw \in Lwithwith|w| \ge n,,wcanbepartitionedascan be partitioned asw = xyz satisfying:\n 1. |xy| \le n\n 2. |y| \ge 1((y eq \epsilon)\n 3. For all k \ge 0,,x y^k z \in L\n\n* **Non-Regularity Proofs:**\n * **Language L_{eq} = {w \in {0, 1}^ \mid w \text{ contains equal number of } 0\text{s and } 1\text{s}}:**\n * Choose w = 0^n 1^n.Clearly. Clearlyw \in L_{eq}andand|w| = 2n \ge n.\n * Since |xy| \le n,,ymustconsistexclusivelyofmust consist exclusively of0s(lets (let|y| = m \ge 1).\n * Pump down with k = 0::x y^0 z = xz = 0^{n-m} 1^n.\n * The number of 0siss isn - m eq n.Thus,. Thus,xz otin L_{eq}, reaching a contradiction.\n* **Language L = {0^n 1 0^n \mid n \ge 1}:**\n * Choose w = 0^n 1 0^n,,|w| = 2n + 1 \ge n.\n * Since |xy| \le n,,y = 0^mwithwith1 \le m \le n.\n * For k = 0::w' = xz = 0^{n-m} 1 0^n.\n * The prefix has n-mzeroswhilethesuffixhaszeros while the suffix hasnzeros.zeros.w' otin L. Contradiction.\n * **Language L = {0^n 1^m 2^n \mid n, m \ge 1}:**\n * Choose w = 0^n 1^m 2^n.\n * Since |xy| \le n,,ycontainsonlycontains only0s.\n * Pumping with k = 0yieldsyields0^{n-m} 1^m 2^n,wherethecountof, where the count of0sdoesnotmatchthecountofs does not match the count of2s. Contradiction.\n * **Language L = {0^n 1^m \mid n \le m}:**\n * Choose w = 0^n 1^n..y = 0^m((m \ge 1).\n * Pump up with k = 2::x y^2 z = 0^{n+m} 1^n.\n * Here, number of 0siss isn+m > n,violatingthecondition, violating the conditionn \le m. Contradiction.\n * **Language L = {0^{n^2} \mid n \ge 1}:**\n * Choose w = 0^{n^2}..|xy| \le n \implies |y| = m \le n.\n * Consider k = 2::|x y^2 z| = n^2 + m.\n * Since 1 \le m \le n,,n^2 < n^2 + m < n^2 + 2n + 1 = (n+1)^2.\n * The length strictly falls between consecutive perfect squares n^2andand(n+1)^2. Contradiction.\n\n* **Homomorphism and Inverse Homomorphism:**\n * A homomorphism h: \Sigma \rightarrow \Gamma^ substitutes symbols with strings.\n * Given h(0) = a,,h(1) = ab,,h(2) = b:\n * h(0120) = h(0)h(1)h(2)h(0) = a \cdot ab \cdot b \cdot a = aabb a\n * h(01^2) = h(0)(h(1))^h(2) = a(ab)^b\n * Inverse homomorphism h^{-1}(L) = {w \in \Sigma^* \mid h(w) \in L}:\n * Given L = {ababa},finding, findingwsuchthatsuch thath(w) = ababa:\n * Partitioning options: ab \cdot ab \cdot a = 110;;ab \cdot a \cdot b \cdot a = 1020;;a \cdot b \cdot a \cdot b \cdot a = 02020.\n * h^{-1}(L) = {110, 1020, 02020}.\n\n\n# Context-Free Grammars, Derivations, and Ambiguity\n\n* **Formal Definition:**\n * A Context-Free Grammar (CFG) is a 4-tuple G = (V_N, \Sigma, P, S),where, whereV_Nisafinitesetofvariables(non−terminals),is a finite set of variables (non-terminals),\Sigmaisafinitesetofterminals,is a finite set of terminals,Pisasetofproductionrulesoftheformis a set of production rules of the formA \rightarrow \alpha((A \in V_N, \alpha \in (V_N \cup \Sigma)^*),and), andS \in V_N is the start symbol.\n\n* **Language Generation Examples:**\n * Grammar S \rightarrow aS \mid ageneratesgeneratesL(G) = {a^n \mid n \ge 1} = a^+.\n * Grammar S \rightarrow 0S1 \mid \epsilongeneratesgeneratesL(G) = {0^n 1^n \mid n \ge 0}.\n * Grammar S \rightarrow SSwithnoterminalproductionsyieldswith no terminal productions yieldsL(G) = \emptyset.\n * Grammar S \rightarrow aCa,,C \rightarrow aCa \mid bgeneratesgeneratesL(G) = {a^n b a^n \mid n \ge 1}.\n * Palindromes over {a, b}::S \rightarrow \epsilon \mid a \mid b \mid aSa \mid bSb.\n * Grammar for L = {a^n b^n c^i \mid n \ge 1, i \ge 0}:\n * S \rightarrow AC\n * A \rightarrow ab \mid aAb\n * C \rightarrow cC \mid \epsilon\n\n* **Arithmetic Expression Grammar with Identifiers:**\n * Terminals: \Sigma = {+, *, (, ), a, b, 0, 1}.\n * Productions:\n * E \rightarrow E + E \mid E * E \mid (E) \mid I\n * I \rightarrow a \mid b \mid Ia \mid Ib \mid I0 \mid I1\n * Leftmost derivation (`lmd`) of a * (a + b00):\n * E \Rightarrow_{lmd} E * E \Rightarrow_{lmd} I * E \Rightarrow_{lmd} a * E\n * \Rightarrow_{lmd} a * (E + E) \Rightarrow_{lmd} a * (I + E) \Rightarrow_{lmd} a * (a + E)\n * \Rightarrow_{lmd} a * (a + I) \Rightarrow_{lmd} a * (a + I0) \Rightarrow_{lmd} a * (a + I00) \Rightarrow_{lmd} a * (a + b00)\n\n* **Ambiguity in Grammars:**\n * A CFG is ambiguous if there exists at least one string w \in L(G) that possesses two or more distinct leftmost derivations (or distinct parse trees).\n * Case 1: Grammar S \rightarrow S + S \mid S * S \mid a \mid bforstringfor stringw = a + a * b:\n * Tree 1: Root +withleftchildwith left childaandrightchildand right childS * S((a * b))\implies a + (a * b).\n * Tree 2: Root *withleftchildwith left childS + S((a + a)andrightchild) and right childb\implies (a + a) * b.\n * The grammar produces two distinct parse trees; hence it is ambiguous.\n * Case 2: Grammar S \rightarrow SbS \mid aforstringfor stringw = ababa:\n * Derivation 1: S \Rightarrow SbS \Rightarrow abS \Rightarrow abSbS \Rightarrow ababS \Rightarrow ababa\n * Derivation 2: S \Rightarrow SbS \Rightarrow SbSbS \Rightarrow abSbS \Rightarrow ababS \Rightarrow ababa\n * Produces structurally distinct syntax trees; hence it is ambiguous.\n\n\n# Chomsky Hierarchy of Formal Languages\n\n* **Classification Criteria:**\n * **Type 0 (Unrestricted / Recursively Enumerable):** Arbitrary phrase-structure rules \alpha \rightarrow \beta,with, with\alpha, \beta \in (V_N \cup \Sigma)^,,|\alpha| \ge 1.\n * **Type 1 (Context-Sensitive Grammar - CSG):** Rules of the form \alpha \rightarrow \betawithconditionwith condition|\alpha| \le |\beta|,plus, plusS \rightarrow \epsilonallowedifallowed ifS does not appear on the RHS.\n * **Type 2 (Context-Free Grammar - CFG):** Rules of the form A \rightarrow \alpha,where, whereA \in V_Nandand\alpha \in (V_N \cup \Sigma)^.\n * **Type 3 (Regular Grammar - RG):** Rules restricted to Right-Linear (A \rightarrow aBororA \rightarrow a)orLeft−Linear() or Left-Linear (A \rightarrow BaororA \rightarrow a).\n\n* **Production Analysis Examples:**\n * Grammar 1: S \rightarrow Aa,,A \rightarrow c \mid Ba,,B \rightarrow abc:\n * S \rightarrow Aa: Variable to Terminal + Variable (Right-linear, Type 3).\n * A \rightarrow c: Variable to Terminal (Type 3).\n * A \rightarrow Ba: Left-linear (Type 3).\n * B \rightarrow abc:RHShasthreeterminals(: RHS has three terminals (V \rightarrow TTT), which is not regular (violates Type 3).\n * Conforms to V \rightarrow (V_N \cup \Sigma)^ (Type 2).\n * Highest applicable number: **Type 2**.\n * Grammar 2: S \rightarrow ASB \mid d,,A \rightarrow aA:\n * S \rightarrow ASBhasmultiplevariablesonRHS(has multiple variables on RHS (V \rightarrow VVN). Violates Type 3.\n * Conforms to Context-Free rule format.\n * Highest applicable number: **Type 2**.\n * Grammar 3: S \rightarrow as \mid ab:\n * S \rightarrow asisType3(is Type 3 (V \rightarrow TV).\n * S \rightarrow abhastwoterminalsonRHS(has two terminals on RHS (V \rightarrow TT), violating Type 3.\n * Highest applicable number: **Type 2**.\n\n\n# Simplification of Context-Free Grammars\n\n* **Phase 1: Elimination of Non-Generating and Unreachable Symbols:**\n * **Finding Generating Variables:**\n * W_1: Variables that directly derive a string of terminals.\n * W_{i+1} = W_i \cup {A \mid A \rightarrow \alpha \text{ for some } \alpha \in (W_i \cup \Sigma)^}.\n * Iterate until W_{k+1} = W_k.Anyvariablenotin. Any variable not inW_k is eliminated along with its productions.\n * **Finding Reachable Symbols:**\n * Y_1 = {S}.\n * Y_{i+1} = Y_i \cup {X \mid A \rightarrow \alpha X \beta \in P \text{ for some } A \in Y_i}.\n * Iterate until stable. Discard any variable or terminal not appearing in Y_k.\n * Example: S \rightarrow AB \mid CA,,B \rightarrow BC \mid AB,,A \rightarrow a,,C \rightarrow aB \mid b:\n * Generating check: W_1 = {A, C},,W_2 = {A, C, S},,W_3 = {A, C, S}.Variable. VariableB is non-generating and removed.\n * Reachable check from S::Y_1 = {S},,Y_2 = {S, A, C},,Y_3 = {S, A, C, a, b}.\n * Reduced grammar: S \rightarrow CA,,A \rightarrow a,,C \rightarrow b.\n\n* **Phase 2: Elimination of \epsilon-Productions (Nullable Variables):**\n * A variable Aisnullableifis nullable ifA \Rightarrow^* \epsilon.\n * Identify nullable variables: If A \rightarrow \epsilon,,A \in W_1.If. IfB \rightarrow A_1 A_2 \dots A_mwhereallwhere allA_iarenullable,are nullable,B \in W_{k+1}.\n * Substitute nullable variables across all RHS occurrences in all combinations, omitting the generated \epsilon.\n * Example: S \rightarrow aS \mid AB,,A \rightarrow \epsilon,,B \rightarrow \epsilon,,D \rightarrow b:\n * Nullable variables: W_1 = {A, B},,W_2 = {A, B, S}.\n * Modified productions P':\n * From S \rightarrow aS::S \rightarrow aS \mid a\n * From S \rightarrow AB::S \rightarrow AB \mid A \mid B\n * D \rightarrow b\n\n* **Phase 3: Elimination of Unit Productions (A \rightarrow B):**\n * Compute unit pairs or non-unit dependencies W(A)foreveryvariablefor every variableA:\n * W_0(A) = {A}\n * W_{i+1}(A) = W_i(A) \cup {C \mid B \rightarrow C \in P \text{ for some } B \in W_i(A)}\n * For each B \in W(A),addallnon−unitproductions, add all non-unit productionsB \rightarrow \alphatotoA.\n * Example: S \rightarrow AB,,A \rightarrow a,,B \rightarrow C \mid b,,C \rightarrow D,,D \rightarrow E,,E \rightarrow a:\n * W(S) = {S} \implies S \rightarrow AB\n * W(A) = {A} \implies A \rightarrow a\n * W(B) = {B, C, D, E} \implies B \rightarrow b \mid a\n * W(C) = {C, D, E} \implies C \rightarrow a\n * W(D) = {D, E} \implies D \rightarrow a\n * W(E) = {E} \implies E \rightarrow a\n\n\n# Normal Forms for Context-Free Grammars: CNF and GNF\n\n* **Chomsky Normal Form (CNF):**\n * Every production is of the form: A \rightarrow BCororA \rightarrow a,where, whereA, B, C \in V_Nandanda \in \Sigma.\n * Conversion procedure:\n 1. Eliminate \epsilon-productions and unit productions.\n 2. Replace terminals in productions of length \ge 2withnewlycreatedvariables(e.g.,with newly created variables (e.g.,C_a \rightarrow a).\n 3. Cascade long variable chains (A \rightarrow B_1 B_2 \dots B_mwithwithm \ge 3) using binary variables.\n * Example 1: S \rightarrow aAD,,A \rightarrow aB \mid b,,B \rightarrow b,,D \rightarrow d:\n * Introduce C \rightarrow a.\n * S \rightarrow CAD,,A \rightarrow CB \mid b,,B \rightarrow b,,D \rightarrow d.\n * Cascade S \rightarrow CAD:set: setE \rightarrow AD,yielding, yieldingS \rightarrow CE.\n * Final CNF productions:\n * S \rightarrow CE\n * E \rightarrow AD\n * A \rightarrow CB \mid b\n * B \rightarrow b\n * D \rightarrow d\n * C \rightarrow a\n * Example 2: S \rightarrow aAbB,,A \rightarrow aA \mid a,,B \rightarrow bB \mid b:\n * Introduce C \rightarrow a,,D \rightarrow b.\n * Productions become: S \rightarrow CADB,,A \rightarrow CA \mid a,,B \rightarrow DB \mid b.\n * Cascade S \rightarrow CADB:let: letX \rightarrow ADB,,Y \rightarrow DB,giving, givingS \rightarrow CX,,X \rightarrow AY,,Y \rightarrow DB.\n\n* **Greibach Normal Form (GNF):**\n * Every production is of the form: A \rightarrow a\alpha,where, wherea \in \Sigmaandand\alpha \in V_N^.\n * **Lemma 1 (Substitution):** If A \rightarrow B\gammaandandB \rightarrow \beta_1 \mid \beta_2 \mid \dots \mid \beta_k,replace, replaceA \rightarrow B\gammawithwithA \rightarrow \beta_1\gamma \mid \beta_2\gamma \mid \dots \mid \beta_k\gamma.\n * **Lemma 2 (Left Recursion Elimination):** If A \rightarrow A\alpha_1 \mid A\alpha_2 \mid \dots \mid \beta_1 \mid \beta_2wherewhere\beta_idonotbeginwithdo not begin withA:\n * Introduce new variable Z.\n * A \rightarrow \beta_i \mid \beta_i Z\n * Z \rightarrow \alpha_i \mid \alpha_i Z\n * Example 1 Conversion (S \rightarrow AA \mid a,,A \rightarrow SS \mid b):\n * Order variables: A_1 = S,,A_2 = A.\n * A_1 \rightarrow A_2 A_2 \mid a(Index(Index2 > 1; valid).\n * A_2 \rightarrow A_1 A_1 \mid b(Index(Index1 < 2;violatescondition).ApplyLemma1bysubstituting; violates condition). Apply Lemma 1 by substitutingA_1:\n * A_2 \rightarrow A_2 A_2 A_1 \mid a A_1 \mid b\n * Left recursion detected on A_2((\alpha_1 = A_2 A_1,,\beta_1 = aA_1,,\beta_2 = b). Apply Lemma 2:\n * A_2 \rightarrow aA_1 \mid b \mid aA_1 Z \mid bZ\n * Z \rightarrow A_2 A_1 \mid A_2 A_1 Z\n * Substitute A_2intointoZusingLemma1tomakeusing Lemma 1 to makeZ conform to GNF.\n * Substitute A_2intointoA_1 \rightarrow A_2 A_2 \mid a to finalize GNF.\n\n\n# Pumping Lemma for Context-Free Languages and Closure Properties\n\n* **Pumping Lemma for CFLs:**\n * For any context-free language L,thereexistsaconstant, there exists a constantnsuchthatforanysuch that for anyz \in Lwithwith|z| \ge n,,zcanbewrittenascan be written asz = uvwxy satisfying:\n 1. |vwx| \le n\n 2. |vx| \ge 1\n 3. u v^i w x^i y \in Lforallfor alli \ge 0\n\n* **Non-CFL Proofs:**\n * **Language L = {0^n 1^n 2^n \mid n \ge 1}:**\n * Choose z = 0^n 1^n 2^n,,|z| = 3n \ge n.\n * The substring vwxhaslengthhas length\le n,meaningitcannotcontainoccurrencesofallthreesymbols, meaning it cannot contain occurrences of all three symbols0, 1, 2 simultaneously.\n * Case 1: vwxcontainsonlycontains only0sands and1s(nos (no2s).Pumpingdown(s). Pumping down (i = 0)removessymbolsfrom) removes symbols from0and/orand/or1,leaving, leavingnoccurrencesofoccurrences of2.Thepumpedstringhasfewerthan. The pumped string has fewer thannzerosorones,sozeros or ones, souwy otin L.\n* Case 2: vwxcontainsonlycontains only1sands and2s(nos (no0s).Pumpingdown(s). Pumping down (i = 0)leaves) leavesnzerosbutfewerthanzeros but fewer thannonesortwos.ones or twos.uwy otin L.\n * Contradiction in all cases; L is not context-free.\n * **Language L = {ww \mid w \in {0, 1}^}:**\n * Choose z = 0^n 1^n 0^n 1^n..|z| = 4n \ge n.\n * Because |vwx| \le n,thesubstring, the substringvx cannot span more than two contiguous blocks.\n * Pumping down (i = 0)altersonehalfofthestringwithoutequallyalteringtheotherhalf,destroyingtherequiredstructure) alters one half of the string without equally altering the other half, destroying the required structurew w.\n * Contradiction; L is not context-free.\n * **Language L = {0^p \mid p \text{ is prime}}:**\n * Choose z = 0^pwherewherep \ge n is a prime.\n * |vwx| \le p,,|vx| = m \ge 1.\n * Pumping up with i = p + 1::|u v^{p+1} w x^{p+1} y| = |uwy| + (p+1)|vx| = (p - m) + (p + 1)m = p - m + pm + m = p(m + 1).\n * The resulting length p(m + 1) is composite, violating primality.\n * Contradiction; L is not context-free.\n * **Language L = {a^n b^n c^i \mid i \le n}:**\n * Choose z = a^p b^p c^p.\n * Substring vwxcanspanatmosttwotypesofsymbols(can span at most two types of symbols (abororbc).\n * Pumping down with i = 0removesremovesasors orbswhileleavings while leavingcsunchanged,causingthecountofs unchanged, causing the count ofasors orbstodropbelowthecountofs to drop below the count ofcs(s (i > n). Contradiction.\n\n* **Closure Properties of Context-Free Languages:**\n * **Closed under Union:** Given G_1 = (V_1, \Sigma, P_1, S_1)andandG_2 = (V_2, \Sigma, P_2, S_2),define, defineS \rightarrow S_1 \mid S_2.\n * **Closed under Concatenation:** Define S \rightarrow S_1 S_2.\n * **Closed under Kleene Closure:** For L(G_1),define, defineS \rightarrow S_1 S \mid \epsilon.\n * **NOT closed under Intersection:**\n * Let L_1 = {0^n 1^n 2^m \mid n, m \ge 1}(CFL)and(CFL) andL_2 = {0^m 1^n 2^n \mid m, n \ge 1} (CFL).\n * L_1 \cap L_2 = {0^n 1^n 2^n \mid n \ge 1}, which is proven to be non-CFL.\n * **NOT closed under Complement:**\n * By De Morgan's Laws: L_1 \cap L_2 = \overline{\overline{L_1} \cup \overline{L_2}}.\n * If CFLs were closed under complement, then since they are closed under union, they would be closed under intersection, which is false.\n\n\n# Pushdown Automata: Design, Acceptance, and State Traces\n\n* **Formal Definition:**\n * A Pushdown Automaton (PDA) is a 7-tuple M = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F),where, whereQisafinitesetofstates,is a finite set of states,\Sigmaistheinputalphabet,is the input alphabet,\Gammaisthestackalphabet,is the stack alphabet,\delta: Q \times (\Sigma \cup {\epsilon}) \times \Gamma \rightarrow \mathcal{P}(Q \times \Gamma^)isthetransitionfunction,is the transition function,q_0 \in Qisthestartstate,is the start state,Z_0 \in \Gammaistheinitialstackstartsymbol,andis the initial stack start symbol, andF \subseteq Q is the set of accepting states.\n\n* **PDA for L = {a^n b^n \mid n \ge 1}:**\n * States: Q = {q_0, q_1, q_f},,\Sigma = {a, b},,\Gamma = {a, Z_0}.\n * Transitions:\n * \delta(q_0, a, Z_0) = {(q_0, aZ_0)}\n * \delta(q_0, a, a) = {(q_0, aa)}\n * \delta(q_0, b, a) = {(q_1, \epsilon)}\n * \delta(q_1, b, a) = {(q_1, \epsilon)}\n * \delta(q_1, \epsilon, Z_0) = {(q_f, Z_0)}(or(or(q_f, \epsilon) for empty stack acceptance)\n\n* **Non-Deterministic PDA for Even Palindromes L = {w w^R \mid w \in {0, 1}^}:**\n * States: Q = {q_0, q_1, q_2},,\Sigma = {0, 1},,\Gamma = {0, 1, Z_0}.\n * Pushing phase (State q_0):\n * \delta(q_0, 0, Z_0) = {(q_0, 0Z_0)},,\delta(q_0, 1, Z_0) = {(q_0, 1Z_0)}\n * \delta(q_0, 0, 0) = {(q_0, 00)},,\delta(q_0, 0, 1) = {(q_0, 01)}\n * \delta(q_0, 1, 0) = {(q_0, 10)},,\delta(q_0, 1, 1) = {(q_0, 11)}\n * Non-deterministic midpoint guess via \epsilon-transitions:\n * \delta(q_0, \epsilon, Z_0) = {(q_1, Z_0)}\n * \delta(q_0, \epsilon, 0) = {(q_1, 0)}\n * \delta(q_0, \epsilon, 1) = {(q_1, 1)}\n * Matching and popping phase (State q_1):\n * \delta(q_1, 0, 0) = {(q_1, \epsilon)}\n * \delta(q_1, 1, 1) = {(q_1, \epsilon)}\n * Acceptance transition:\n * \delta(q_1, \epsilon, Z_0) = {(q_2, Z_0)}\n\n* **Deterministic PDA for Marked Midpoint L = {w c w^R \mid w \in {0, 1}^}:**\n * Push all symbols while reading wininq_0.\n * Transition on delimiter ctostateto stateq_1withoutalteringstack:without altering stack:\delta(q_0, c, X) = {(q_1, X)}forforX \in {0, 1, Z_0}.\n * Pop matching symbols in q_1::\delta(q_1, 0, 0) = {(q_1, \epsilon)},,\delta(q_1, 1, 1) = {(q_1, \epsilon)}.\n * Enter accepting state q_2onemptyinputandstacktopon empty input and stack topZ_0::\delta(q_1, \epsilon, Z_0) = {(q_2, Z_0)}.\n\n* **Instantaneous Descriptions (ID) Traces for PDA P = ({q, p}, {0, 1}, {Z_0, X}, \delta, q, Z_0, {p}):**\n * Trace for string w = 01:\n * (q, 01, Z_0) \vdash (q, 1, XZ_0) \vdash (q, \epsilon, XZ_0) \vdash (p, \epsilon, Z_0)\n * Accepting state p reached; Accepted.\n * Trace for string w = 0011:\n * (q, 0011, Z_0) \vdash (q, 011, XZ_0) \vdash (q, 11, XXZ_0) \vdash (q, 1, XXZ_0)\n * \vdash (q, \epsilon, XXZ_0) \vdash (q, \epsilon, XZ_0) \vdash (p, \epsilon, Z_0)\n * Accepted.\n * Trace for string w = 010:\n * (q, 010, Z_0) \vdash (q, 10, XZ_0) \vdash (q, 0, XZ_0) \vdash (q, \epsilon, XXZ_0)\n * \vdash (p, \epsilon, XZ_0) \vdash (p, \epsilon, Z_0)\n * Accepted.\n\n* **PDA Acceptance Modes:**\n * **Acceptance by Final State:** L(M) = {w \in \Sigma^ \mid (q_0, w, Z_0) \vdash^* (q_f, \epsilon, \alpha) \text{ for some } q_f \in F, \alpha \in \Gamma^}.\n * **Acceptance by Empty Stack:** N(M) = {w \in \Sigma^ \mid (q_0, w, Z_0) \vdash^* (q, \epsilon, \epsilon) \text{ for some } q \in Q}.\n * Both models are computationally equivalent: L(M) = N(M').\n\n\n# Equivalence Between Context-Free Grammars and Pushdown Automata\n\n* **CFG to PDA Conversion Algorithm:**\n * Given G = (V_N, \Sigma, P, S), define a single-state PDA accepting by empty stack:\n * M = ({q}, \Sigma, V_N \cup \Sigma, \delta, q, S, \emptyset)\n * For every production rule A \rightarrow \alpha \in P,addan, add an\epsilon-transition:\n * \delta(q, \epsilon, A) = {(q, \alpha)}\n * For every terminal a \in \Sigma, add a matching pop transition:\n * \delta(q, a, a) = {(q, \epsilon)}\n * Application to grammar S \rightarrow 0S1 \mid A,,A \rightarrow 1A0 \mid S \mid \epsilon:\n * \delta(q, \epsilon, S) = {(q, 0S1), (q, A)}\n * \delta(q, \epsilon, A) = {(q, 1A0), (q, S), (q, \epsilon)}\n * \delta(q, 0, 0) = {(q, \epsilon)}\n * \delta(q, 1, 1) = {(q, \epsilon)}\n\n* **PDA to CFG Conversion Algorithm:**\n * Grammar variables are created for all triplets of the form [q X p],where, whereq, p \in QandandX \in \Gamma,denotingthatthePDAgoesfromstate, denoting that the PDA goes from stateqtostateto statepwhilepoppingstacksymbolwhile popping stack symbolX.\n * Start rules:\n * S \rightarrow [q_0 Z_0 p]forallfor allp \in Q.\n * Production generation from transitions:\n * If \delta(q, a, X)containscontains(r, \epsilon):Addproduction: Add production[q X r] \rightarrow a.\n * If \delta(q, a, X)containscontains(r, Y_1 Y_2 \dots Y_k):Foreverysequenceofstates: For every sequence of statess_1, s_2, \dots, s_k \in Q, add production:\n * [q X s_k] \rightarrow a [r Y_1 s_1][s_1 Y_2 s_2] \dots [s_{k-1} Y_k s_k]\n\n\n# Deterministic Pushdown Automata and Language Limitations\n\n* **DPDA Conditions:**\n * A PDA M = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F) is deterministic if and only if:\n 1. For any q \in Q,,a \in \Sigma \cup {\epsilon},and, andX \in \Gamma,theset, the set\delta(q, a, X) contains at most one element.\n 2. If \delta(q, \epsilon, X) eq \emptyset,then, then\delta(q, a, X) = \emptysetforallfor alla \in \Sigma.\n\n* **DPDA Design Examples:**\n * **Language L = {0^n 1^m \mid n \le m}:**\n * q_0:Read: Read0sandpushtostack:s and push to stack:\delta(q_0, 0, Z_0) = (q_0, 0Z_0),,\delta(q_0, 0, 0) = (q_0, 00).\n * q_1:Read: Read1sandpopmatchings and pop matching0s:s:\delta(q_0, 1, 0) = (q_1, \epsilon),,\delta(q_1, 1, 0) = (q_1, \epsilon).\n * q_2:Acceptingstatereachedonemptystacktop: Accepting state reached on empty stack topZ_0::\delta(q_1, \epsilon, Z_0) = (q_2, Z_0).\n * Excess 1sabsorbedins absorbed inq_2::\delta(q_2, 1, Z_0) = (q_2, Z_0).\n * **Language L = {0^n 1^m \mid n > m}:**\n * Push all 0sins inq_0.\n * Pop 0foreachfor each1instatein stateq_1.\n * Accepting state requires that the input has been fully consumed while stack still contains unmatched 0s(s (\delta(q_1, \epsilon, 0) = (q_f, \epsilon)).\n\n* **Non-DPDA Languages:**\n * Languages such as L = {0^n 1^m 0^n}witharbitrarywith arbitraryn, m or languages requiring guessing of the boundary cannot be accepted by a DPDA because unresolved nondeterminism occurs when determining whether to match or bypass the stack contents.\n\n\n# Turing Machines: Instantaneous Descriptions, Design, and Techniques\n\n* **Formal Definition:**\n * A Turing Machine (TM) is a 7-tuple M = (Q, \Sigma, \Gamma, \delta, q_0, B, F),where, whereQisafinitesetofstates,is a finite set of states,\Sigmaistheinputalphabet,is the input alphabet,\Gammaisthetapealphabet(is the tape alphabet (\Sigma \subset \Gamma),),B \in \Gamma - \Sigmaistheblanksymbol,is the blank symbol,\delta: Q \times \Gamma \rightarrow Q \times \Gamma \times {L, R}isthepartialtransitionfunction,is the partial transition function,q_0 \in Qistheinitialstartstate,andis the initial start state, andF \subseteq Q is the set of final/halting states.\n\n* **Instantaneous Description (ID) Execution Traces:**\n * An ID is denoted as \alpha q \beta,indicatingthecurrentstateis, indicating the current state isq,thetapecontentis, the tape content is\alpha\beta,andtheread/writeheadispositionedonthefirstsymbolof, and the read/write head is positioned on the first symbol of\beta.\n * Trace for TM on input 00withblanksymbolwith blank symbolb:\n * q_1 00b \vdash 0 q_1 0b \vdash 00 q_1 b \vdash 0 q_2 01 \vdash q_2 001 \vdash q_2 b001 \vdash b q_3 001\n * \vdash bb q_4 01 \vdash bb0 q_4 1 \vdash bb01 q_4 b \vdash bb010 q_5\n * No further moves exist from state q_5.Machinehaltsinfinalstate. Machine halts in final stateq_5;input; input00 accepted.\n * Trace for input 0011:\n * q_1 0011b \vdash X q_2 011b \vdash X0 q_2 11b \vdash X q_3 0Y1b \vdash q_3 X0Y1b\n * \vdash X q_1 0Y1b \vdash XX q_2 Y1b \vdash XXY q_2 1b \vdash XX q_3 YYb\n * \vdash X q_3 XYYb \vdash XX q_1 YYb \vdash XXY q_4 Yb \vdash XXYY q_4 b \vdash XXYYb q_6 b\n * Machine halts in accepting state q_6;input; input0011 accepted.\n * Rejection traces:\n * String 011 terminates in a configuration with no valid transitions before reaching a final state; rejected.\n * String 001 encounters invalid symbol alignments; rejected.\n\n* **TM Design: Even Number of 1sOvers Over\Sigma = {1}:**\n * States: Q = {q_0, q_1},Tapesymbols:, Tape symbols:\Gamma = {1, b},Startstate:, Start state:q_0,Halting/Acceptingstate:, Halting/Accepting state:F = {q_0}.\n * Transitions:\n * \delta(q_0, 1) = (q_1, b, R)\n * \delta(q_1, 1) = (q_0, b, R)\n * Trace on 11::b q_0 11b \vdash bb q_1 1b \vdash bbb q_0 b.Haltsin. Halts inq_0; Accepted.\n * Trace on 111::b q_0 111b \vdash bb q_1 11b \vdash bbb q_0 1b \vdash bbbb q_1 b.Haltsin. Halts inq_1 otin F; Rejected.\n\n* **TM Design: Concatenation of Two Unary Strings (w_1 w_2):**\n * Objective: Connect two blocks of 1sseparatedbyablanks separated by a blankb,thenerasetherightmost, then erase the rightmost1 to maintain total count, returning head to the start.\n * States and roles:\n * q_0:Scanfirstword,findseparatorblank: Scan first word, find separator blankb.\n * q_1:Convertseparatorto: Convert separator to1,scansecondwordtofindtrailingblank, scan second word to find trailing blankb.\n * q_2:Moveleftanderaserightmost: Move left and erase rightmost1byreplacingitwithby replacing it withb.\n * q_3: Return tape head leftward to the initial blank.\n * q_4: Final halting state.\n * Transitions:\n * \delta(q_0, 1) = (q_0, 1, R)\n * \delta(q_0, b) = (q_1, 1, R)\n * \delta(q_1, 1) = (q_1, 1, R)\n * \delta(q_1, b) = (q_2, b, L)\n * \delta(q_2, 1) = (q_3, b, L)\n * \delta(q_3, 1) = (q_3, 1, L)\n * \delta(q_3, b) = (q_4, b, R)\n\n* **TM Design: Language L = {0^n 1^n \mid n \ge 1}:**\n * States: q_0, q_1, q_2, q_3, q_4,Tapealphabet:, Tape alphabet:\Gamma = {0, 1, X, Y, b}.\n * Transitions:\n * \delta(q_0, 0) = (q_1, X, R):Markleftmostavailable: Mark leftmost available0asasX.\n * \delta(q_1, 0) = (q_1, 0, R),,\delta(q_1, Y) = (q_1, Y, R):Moverightacrossremaining: Move right across remaining0sands andYs.\n * \delta(q_1, 1) = (q_2, Y, L):Markmatchingleftmost: Mark matching leftmost1asasY.\n * \delta(q_2, Y) = (q_2, Y, L),,\delta(q_2, 0) = (q_2, 0, L):Moveleftacross: Move left acrossYsands and0s.\n * \delta(q_2, X) = (q_0, X, R):Returntorightoflastmarked: Return to right of last markedX.\n * \delta(q_0, Y) = (q_3, Y, R):Whenall: When all0sareconverted,verifythatnoremainings are converted, verify that no remaining1s exist.\n * \delta(q_3, Y) = (q_3, Y, R)\n * \delta(q_3, b) = (q_4, b, R): Halting accept state reached.\n\n* **Storage in State Technique:**\n * Turing machine states can be structured as tuples [q, a] to store a finite amount of data directly in the control unit.\n * Application for L = 01^* + 10^*:\n * States: Q = {(q_0, b), (q_1, 0), (q_1, 1), (q_1, b)}.\n * (q_0, b): Start state; remembers that no symbol has been read.\n * (q_1, 0):Remembersfirstsymbolwas: Remembers first symbol was0;allowsonlysubsequent; allows only subsequent1s.\n * (q_1, 1):Remembersfirstsymbolwas: Remembers first symbol was1;allowsonlysubsequent; allows only subsequent0s.\n * (q_1, b):Acceptingstatereacheduponencounteringblank: Accepting state reached upon encountering blankb.\n * Transitions:\n * \delta((q_0, b), 0) = ((q_1, 0), 0, R)\n * \delta((q_1, 0), 1) = ((q_1, 0), 1, R)\n * \delta((q_1, 0), b) = ((q_1, b), b, R)\n * \delta((q_0, b), 1) = ((q_1, 1), 1, R)\n * \delta((q_1, 1), 0) = ((q_1, 1), 0, R)\n * \delta((q_1, 1), b) = ((q_1, b), b, R)\n\n* **Multiplication of Two Unary Numbers:**\n * Computes m \times nbyrepeatedlycopyingablockofby repeatedly copying a block ofnonesonesm times onto a designated output tape segment.\n * Examples: 2 \times 3 = 6,,4 \times 2 = 8$$.