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 and can be merged into the same state if and only if for every future continuation string , both and 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 s Over Binary Alphabet :
- Language specification: .
- States:
- : Start state, representing the condition where an even number of s have been seen (Accepting state).
- : Representing the condition where an odd number of s have been seen.
- Transitions:
DFA: Substring :
- Condition tracking:
- : Starts with but is not yet seen (State ).
- : Does not start with (State , start state).
- : Substring has been matched (State , accepting state).
- State equivalence checking:
- Prefix
- Prefix
- For future string : (Accepted); (Rejected). Hence, .
- For future string : (Accepted).
- Prefix with future string : (Accepted). Prefix behaves identically to prefix , mapping to state .
- Total states:
- Transitions:
- ,
- ,
- ,
- Condition tracking:
DFA: Substring :
- States and progress conditions:
- : Start state; no part of the pattern is matched.
- : Last symbol read is ; pattern matched, not yet seen.
- : Pattern matched, final not yet seen.
- : Pattern matched (Accepting state).
- Behavioral analysis for merges:
- behaves identically to : on input , requires future to accept; on input , requires future to accept.
- Transitions:
- ,
- ,
- ,
- ,
- States and progress conditions:
DFA: Starting with Over Alphabet :
- Conditions:
- : Starts with (, accepting state).
- : Does not start with (starts with ) (, trap/dead state).
- : Start state (before reading any input).
- Total states:
- Transitions:
- ,
- ,
- ,
- Conditions:
DFA: Starting with and Ending with Over :
- Condition tracking:
- : Initial state, no symbols read.
- : Starts with , but does not currently end with .
- : Does not start with (Dead/Trap state).
- : Starts with and currently ends with (Accepting state).
- Transitions:
- , ,
- , ,
- , ,
- , ,
- Total states:
- Condition tracking:
DFA: Ending with Over :
- States:
- : Does not end with (Start state; includes empty string and strings ending in ).
- : Ends with (Accepting state).
- Transitions:
- ,
- ,
- Total states:
- States:
DFA: Number of s Divisible by :
- Condition: Count of s modulo .
- : ( ones seen; Start and Accepting state).
- : ( ones seen; Non-accepting).
- : ( ones seen; Non-accepting).
- Transitions:
- ,
- ,
- ,
- Total states:
- Condition: Count of s modulo .
DFA: Beginning with and of Even Length Over :
- Conditions:
- : Start state, length (even).
- : Seen , length (odd).
- : Dead state; strings that do not begin with .
- : Seen , length (even, prefix verified; Accepting state).
- : Began with , currently odd length (Non-accepting).
- Transitions:
- ,
- ,
- ,
- ,
- ,
- Total states:
- Conditions:
DFA: Strings Not Containing Over :
- States:
- : Start state; have not seen , no trailing (Accepting state).
- : Have not seen , trailing (Accepting state).
- : Have not seen , trailing (Accepting state).
- : Substring seen (Dead/Trap state, non-accepting).
- Transitions:
- ,
- ,
- ,
- ,
- States:
DFA: Exactly Three Consecutive s:
- States:
- : No consecutive s seen (Start state).
- : Exactly one consecutive seen.
- : Exactly two consecutive s seen.
- : Exactly three consecutive s seen (Accepting state).
- Transitions:
- ,
- ,
- ,
- ,
- Total states:
- States:
DFA: Beginning with and Ending with Over :
- Conditions and state progression:
- : Start state; does not begin with .
- : Began with , next symbol must be .
- : Trap state; strings that fail to begin with .
- : Began with , current suffix is neither nor .
- : Began with , current suffix is (not ).
- : Began with , current suffix is (Accepting state).
- Transitions:
- ,
- ,
- ,
- ,
- ,
- ,
- Total states:
- Conditions and state progression:
DFA: Starting with Over :
- States:
- : Start state.
- : Seen single at the start.
- : Seen at the start (Accepting state).
- : Started with or (Dead state).
- Transitions:
- ,
- ,
- ,
- ,
- Total states:
- States:
DFA: Ending with or Over :
- States:
- : Start state, no suffix matched.
- : Last symbol read is .
- : Suffix is (Accepting state).
- : Last symbol read is .
- : Suffix is (Accepting state).
- Transitions:
- ,
- ,
- ,
- ,
- ,
- Total states:
- States:
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 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 s:
- States:
- : Even number of s seen.
- : Odd number of s seen (Accepting state).
- Transitions:
- ,
- ,
- States:
NFA: Second Symbol from the Last is :
- Conceptual operation:
- : Scanning the input string; non-deterministically guesses when the symbol is the second-to-last symbol.
- : Guessed that current is the second-to-last symbol.
- : Exactly one symbol has been read after the guessed (Accepting state).
- Transitions:
- ,
- Rule constraint: Adding a self-loop on would incorrectly enforce that the first read is fixed rather than guessed, breaking the second-last specification.
- Conceptual operation:
NFA: Strings Containing Substring :
- States:
- : Scanning string, searching for substring .
- : Matched initial .
- : Matched sequence .
- : Matched sequence (Accepting state).
- Transitions:
- ,
- ,
- States:
NFA: Starting with :
- States:
- : Start state, awaiting first symbol .
- : Matched first .
- : Matched (Accepting state).
- Transitions:
- ,
- States:
NFA: Ending with :
- States:
- : Scanning string.
- : Guessed that current symbol is the final symbol (Accepting state).
- Transitions:
- ,
- States:
NFA: Having or as Substring:
- States:
- : Scanning input.
- : Matched .
- : Matched .
- : Matched (Accepting state).
- : Matched .
- : Matched (Accepting state).
- Transitions:
- ,
- ,
- ,
- ,
- States:
NFA: Third Character is :
- States:
- : Start state, awaiting 1st character.
- : 1st character scanned.
- : 2nd character scanned.
- : 3rd character scanned and confirmed as (Accepting state).
- Transitions:
- ,
- ,
- ,
- States:
NFA: Starting with and Ending with Over :
- States:
- : Start state.
- : Verified string started with .
- : Last symbol read is (Accepting state).
- Transitions:
- , ,
- Total states:
- States:
NFA: Ending with :
- States:
- : Scanning string.
- : Guessed is penultimate symbol.
- : Read following guessed (Accepting state).
- Transitions:
- ,
- States:
NFA: Starting with "cat" and Ending with "bat" Over :
- States:
- : Initial state.
- : Read .
- : Read .
- : Read .
- : Guessed is start of final "bat".
- : Read .
- : Matched (Accepting state).
- Transitions:
- ,
- Total states:
- States:
Extended Transition Functions and State Traces
DFA State Trace for String (Testing Non-containment of ):
- Since is a non-accepting dead state, the string is rejected.
NFA Traces for Third Character is :
- Input :
- Branch terminates in failure; string rejected.
- Input :
- State is reached; string accepted.
- Input :
Formal Definition of NFA Extended Transition Function :
- Base case:
- Recursive step: For string where and :
- If , then:
Trace of String on NFA (Second Symbol from Last is ):
- Initial condition:
- Symbol :
- Symbol :
- Symbol :
- Symbol :
- Symbol :
- Result: Since the final set of reachable states contains the accepting state , the string is accepted.
Automata Conversions: Powerset Construction and Epsilon-Closures
NFA to DFA Conversion via Powerset Construction:
- Given NFA specification: states , alphabet , start state , accepting state .
- Transition table of original NFA:
- ,
- ,
- ,
- Complete powerset: subsets: .
- Powerset evaluation:
- ,
- ,
- ,
- Reachable DFA states from start state :
- Initial state:
- From : on ; on
- From : on ; on
- From : on ; on
- From : on ; on
- Final reachable states: .
- Final accepting states (any state containing ): .
-Closure Computation ():
- is the set of all states reachable from state via zero or more -transitions.
- Example 1:
- Since start state has , empty string (length ) is accepted.
- Transition computations:
- , ,
- , ,
- Resulting DFA contains exactly one reachable state: , which acts as an accepting self-loop state on all inputs .
-NFA to DFA Conversion (3-Input System ):
- Given -closures:
- Start state of DFA: . Since it contains , is an accepting state.
- Evaluating transitions from :
- Input :
- , ,
- Input :
- , ,
- Input :
- , ,
- Input :
- Evaluating transitions from :
- Input :
- ,
- Input :
- ,
- Input :
- ,
- Input :
- Evaluating transitions from :
- State is the dead/trap state.
- Given -closures:
-NFA to Standard NFA Conversion:
- Transition rule: .
- Accepting states: Any state whose -closure contains an original accepting state.
- For state : . Since is accepting, becomes an accepting state in the NFA.
- Transitions for state :
- Transitions for state :
- Transitions for state :
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 , where .
- Mealy Machine: Output depends on both the current state and the current input symbol. Represented as a 6-tuple , 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 aq' = \delta(q, a)q'\lambda(q').\n * Given Moore transition table:\n * State q_0a=0q_3a=1q_1= 0.\n * State q_1a=0q_1a=1q_2= 1.\n * State q_2a=0q_2a=1q_3= 0.\n * State q_3a=0q_3a=1q_0= 0.\n * Computing Mealy outputs:\n * At q_00 \rightarrow q_3\lambda(q_3) = 01 \rightarrow q_1\lambda(q_1) = 1.\n * At q_10 \rightarrow q_1\lambda(q_1) = 11 \rightarrow q_2\lambda(q_2) = 0.\n * At q_20 \rightarrow q_2\lambda(q_2) = 01 \rightarrow q_3\lambda(q_3) = 0.\n * At q_30 \rightarrow q_3\lambda(q_3) = 01 \rightarrow q_0\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_1a=0 \rightarrow q_30a=1 \rightarrow q_20).\n * State q_2a=0 \rightarrow q_11a=1 \rightarrow q_40).\n * State q_3a=0 \rightarrow q_21a=1 \rightarrow q_11).\n * State q_4a=0 \rightarrow q_41a=1 \rightarrow q_30).\n * Analysis of incoming outputs per state:\n * State q_11q_20/1q_31/1= 1A = (q_1, 1).\n * State q_20q_11/01q_30/1B = (q_2, 0)C = (q_2, 1).\n * State q_30q_10/0q_41/0= 0D = (q_3, 0).\n * State q_40q_21/01q_40/1E = (q_4, 0)F = (q_4, 1).\n * Initial state assignment: Original start was q_1S0q_1:\n * From S0 \rightarrow (q_3, \text{out } 0) = D\n * From S1 \rightarrow (q_2, \text{out } 0) = B\n * Transitions for split Moore states:\n * From A (q_1)0 \rightarrow D1 \rightarrow B\n * From B (q_2, 0)0 \rightarrow A1 \rightarrow E\n * From C (q_2, 1)0 \rightarrow A1 \rightarrow E\n * From D (q_3)0 \rightarrow C1 \rightarrow A\n * From E (q_4, 0)0 \rightarrow F1 \rightarrow D\n * From F (q_4, 1)0 \rightarrow F1 \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_0q_7:\n * q_00 \rightarrow q_11 \rightarrow q_5\n * q_10 \rightarrow q_61 \rightarrow q_2\n * q_20 \rightarrow q_01 \rightarrow q_2\n * q_30 \rightarrow q_21 \rightarrow q_6\n * q_40 \rightarrow q_71 \rightarrow q_5\n * q_50 \rightarrow q_21 \rightarrow q_6\n * q_60 \rightarrow q_61 \rightarrow q_4\n * q_70 \rightarrow q_61 \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}B = {q_0, q_1, q_3, q_4, q_5, q_6, q_7} (Non-final).\n * Step 2: Signatures on (0, 1)\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 B\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 B{q_0, q_4}{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_5F = {q_3, q_5}.\n * q_00 \rightarrow q_11 \rightarrow q_3\n * q_10 \rightarrow q_01 \rightarrow q_3\n * q_20 \rightarrow q_11 \rightarrow q_4\n * q_30 \rightarrow q_51 \rightarrow q_5\n * q_40 \rightarrow q_31 \rightarrow q_3\n * q_50 \rightarrow q_51 \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}B = {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_0q_1{q_0, q_1}0{q_3, q_5}1.\n * Comparing q_3q_5{q_3, q_5}01.\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 ab\Sigma = {a, b, c}:**\n * Two mutually exclusive chronological cases:\n * Case 1: ab(a + b + c)^* a (a + b + c)^* b (a + b + c)^\n * Case 2: ba(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 1\Sigma = {0, 1}:**\n * The prefix can be arbitrary, followed by 19 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 05\Sigma = {0, 1}:**\n * Allowed counts of 00, 5, 10, 15, \dots\n * Any number of 10s.\n * Elementary block containing five 00 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 101\Sigma = {0, 1}:**\n * Safe building blocks that cannot create the sequence 101011100.\n * Valid terminal endings that do not complete 101\epsilon110.\n * Regular expression: (0 + 11 + 100)^* (\epsilon + 1 + 10)\n\n* **Equal Number of 011:**\n * Condition: In every prefix, |\text{count}(0) - \text{count}(1)| \le 1.\n * An immediate 0011.\n * The string must be composed of balanced consecutive pairs: 0110.\n * Regular expression: (01 + 10)^\n\n* **Odd Number of 0\Sigma = {0, 1}:**\n * After seeing the first 00s 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 11\Sigma = {0, 1}:**\n * Every 10, 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)1 or nothing (empty string).\n * (00^1)^01.\n * 0^0s.\n * Expression: (0 + 10)^* 1^\n * Repeats blocks of either 0101s.\n\n\n# Conversion of Finite Automata to Regular Expressions\n\n* **Inductive Formulation (R_{ij}^{(k)} Method):**\n * R_{ij}^{(k)}ijk.\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 = jR_{ii}^{(0)} = \epsilon + \sum aaii).\n * If i eq jR_{ij}^{(0)} = \sum aaij\emptyset if no edge exists.\n\n* **Inductive Computation for 2-State DFA:**\n * States: 12 (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 = 221):\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)^(\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_kq_iq_j:\n * R_{ij}' = R_{ij} + Q_i S^ P_j\n * R_{ij}q_iq_j.\n * Q_iq_i.\n * SS^* = \epsilon if no self-loop).\n * P_jq_j.\n * Application on 3-State DFA (States q_1, q_2, q_3q_2):\n * Path q_1 \rightarrow q_2 \rightarrow q_1S = 0S^* = \epsilonQ_i = 0P_j = 0R_{11} = 0 \implies R = 00.\n * Path q_1 \rightarrow q_2 \rightarrow q_3S^* = \epsilonQ_i = 0P_j = 1R_{13} = 1 \implies S = 1 + 01.\n * Path q_3 \rightarrow q_2 \rightarrow q_1S^* = \epsilonQ_i = 0P_j = 0R_{31} = 1 \implies T = 1 + 00.\n * Path q_3 \rightarrow q_2 \rightarrow q_3S^* = \epsilonQ_i = 0P_j = 1R_{33} = \emptyset \implies U = 01.\n * Final regular expression between start q_1q_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 PQ\Sigma\epsilon otin PR = Q + RPR = QP^.\n* Example 1 (2-State Automaton):\n * Equations: R_1 = \epsilon + R_1 1R_2 = R_1 0 + R_2 0 + R_2 1.\n * Solving for R_1R_1 = \epsilon (1)^* = 1^.\n * Substituting R_1R_2R_2 = 1^ 0 + R_2 (0 + 1).\n * Applying Arden's Theorem on R_2Q = 1^* 0P = (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_2R_2 = R_1 0 (1)^\n * Substitute R_2R_3R_3 = R_1 1 + R_1 0 1^* 1 = R_1 (1 + 0 1^* 1)\n * Substitute into R_1R_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 aa.\n * For \epsilon\epsilon-transition.\n * Union (R_1 + R_2):\n * Introduce new start state with \epsilonR_1R_2.\n * Join final states of R_1R_2\epsilon-transitions.\n * Concatenation (R_1 R_2):\n * Connect the accepting state of R_1R_2\epsilon-transition.\n * Kleene Star (R_1^):\n * Introduce new start and final states.\n * Add \epsilon\epsilon).\n * Add \epsilonR_1 for repetition.\n\n* **Construction for (0 + 1)^* 1 (0 + 1):**\n * Sub-automaton for (0 + 1)q_0, q_10q_2, q_31q_4q_5\epsilon-transitions.\n * Sub-automaton for (0 + 1)^q_6q_7\epsilon-loops.\n * Concatenation with 1q_7\epsilonq_81q_9.\n * Concatenation with (0 + 1)q_9\epsilon(0 + 1)q_{10}q_{15}.\n\n* **Construction for 0 1^:**\n * Primitive for 0q_0 \xrightarrow{0} q_1.\n * Sub-automaton for 1^q_2 \xrightarrow{1} q_3q_4q_5\epsilonq_4 \xrightarrow{\epsilon} q_2q_3 \xrightarrow{\epsilon} q_5q_3 \xrightarrow{\epsilon} q_2q_4 \xrightarrow{\epsilon} q_5.\n * Concatenation: Connect q_1q_4\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 nn(n-1)/2(p, q).\n * Step 1: Mark with an X(p, q)FQ - F).\n * Step 2: Iteratively check each unmarked pair (p, q)a \in \Sigma(\delta(p, a), \delta(q, a))X(p, q)X.\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, E5(4)/2 = 10.\n * Final states: B, EA, C, D.\n * Step 1 marks: AB, AE, BC, BD, CE, DEX.\n * Step 2 checking remaining pairs: AC, AD, BE, CD:\n * For AC0 \rightarrow AD1 \rightarrow BEADBEAC remains unmarked.\n * For AD0 \rightarrow AD1 \rightarrow BE. Remains unmarked.\n * For BE0 \rightarrow AC1 \rightarrow BE. Remains unmarked.\n * For CD: both map to unmarked pairs.\n * Initial states ACA \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 Lnw \in L|w| \ge nww = xyz satisfying:\n 1. |xy| \le n\n 2. |y| \ge 1y eq \epsilon)\n 3. For all k \ge 0x 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^nw \in L_{eq}|w| = 2n \ge n.\n * Since |xy| \le ny0|y| = m \ge 1).\n * Pump down with k = 0x y^0 z = xz = 0^{n-m} 1^n.\n * The number of 0n - m eq nxz 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 ny = 0^m1 \le m \le n.\n * For k = 0w' = xz = 0^{n-m} 1 0^n.\n * The prefix has n-mnw' 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 ny0s.\n * Pumping with k = 00^{n-m} 1^m 2^n02s. Contradiction.\n * **Language L = {0^n 1^m \mid n \le m}:**\n * Choose w = 0^n 1^ny = 0^mm \ge 1).\n * Pump up with k = 2x y^2 z = 0^{n+m} 1^n.\n * Here, number of 0n+m > nn \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 nn^2 < n^2 + m < n^2 + 2n + 1 = (n+1)^2.\n * The length strictly falls between consecutive perfect squares n^2(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) = ah(1) = abh(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}wh(w) = ababa:\n * Partitioning options: ab \cdot ab \cdot a = 110ab \cdot a \cdot b \cdot a = 1020a \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)V_N\SigmaPA \rightarrow \alphaA \in V_N, \alpha \in (V_N \cup \Sigma)^*S \in V_N is the start symbol.\n\n* **Language Generation Examples:**\n * Grammar S \rightarrow aS \mid aL(G) = {a^n \mid n \ge 1} = a^+.\n * Grammar S \rightarrow 0S1 \mid \epsilonL(G) = {0^n 1^n \mid n \ge 0}.\n * Grammar S \rightarrow SSL(G) = \emptyset.\n * Grammar S \rightarrow aCaC \rightarrow aCa \mid bL(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 bw = a + a * b:\n * Tree 1: Root +aS * Sa * b\implies a + (a * b).\n * Tree 2: Root *S + Sa + ab\implies (a + a) * b.\n * The grammar produces two distinct parse trees; hence it is ambiguous.\n * Case 2: Grammar S \rightarrow SbS \mid aw = 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\alpha, \beta \in (V_N \cup \Sigma)^|\alpha| \ge 1.\n * **Type 1 (Context-Sensitive Grammar - CSG):** Rules of the form \alpha \rightarrow \beta|\alpha| \le |\beta|S \rightarrow \epsilonS does not appear on the RHS.\n * **Type 2 (Context-Free Grammar - CFG):** Rules of the form A \rightarrow \alphaA \in V_N\alpha \in (V_N \cup \Sigma)^.\n * **Type 3 (Regular Grammar - RG):** Rules restricted to Right-Linear (A \rightarrow aBA \rightarrow aA \rightarrow BaA \rightarrow a).\n\n* **Production Analysis Examples:**\n * Grammar 1: S \rightarrow AaA \rightarrow c \mid BaB \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 abcV \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 dA \rightarrow aA:\n * S \rightarrow ASBV \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 asV \rightarrow TV).\n * S \rightarrow abV \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_kW_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 CAB \rightarrow BC \mid ABA \rightarrow aC \rightarrow aB \mid b:\n * Generating check: W_1 = {A, C}W_2 = {A, C, S}W_3 = {A, C, S}B is non-generating and removed.\n * Reachable check from SY_1 = {S}Y_2 = {S, A, C}Y_3 = {S, A, C, a, b}.\n * Reduced grammar: S \rightarrow CAA \rightarrow aC \rightarrow b.\n\n* **Phase 2: Elimination of \epsilon-Productions (Nullable Variables):**\n * A variable AA \Rightarrow^* \epsilon.\n * Identify nullable variables: If A \rightarrow \epsilonA \in W_1B \rightarrow A_1 A_2 \dots A_mA_iB \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 ABA \rightarrow \epsilonB \rightarrow \epsilonD \rightarrow b:\n * Nullable variables: W_1 = {A, B}W_2 = {A, B, S}.\n * Modified productions P':\n * From S \rightarrow aSS \rightarrow aS \mid a\n * From S \rightarrow ABS \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)A:\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)B \rightarrow \alphaA.\n * Example: S \rightarrow ABA \rightarrow aB \rightarrow C \mid bC \rightarrow DD \rightarrow EE \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 BCA \rightarrow aA, B, C \in V_Na \in \Sigma.\n * Conversion procedure:\n 1. Eliminate \epsilon-productions and unit productions.\n 2. Replace terminals in productions of length \ge 2C_a \rightarrow a).\n 3. Cascade long variable chains (A \rightarrow B_1 B_2 \dots B_mm \ge 3) using binary variables.\n * Example 1: S \rightarrow aADA \rightarrow aB \mid bB \rightarrow bD \rightarrow d:\n * Introduce C \rightarrow a.\n * S \rightarrow CADA \rightarrow CB \mid bB \rightarrow bD \rightarrow d.\n * Cascade S \rightarrow CADE \rightarrow ADS \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 aAbBA \rightarrow aA \mid aB \rightarrow bB \mid b:\n * Introduce C \rightarrow aD \rightarrow b.\n * Productions become: S \rightarrow CADBA \rightarrow CA \mid aB \rightarrow DB \mid b.\n * Cascade S \rightarrow CADBX \rightarrow ADBY \rightarrow DBS \rightarrow CXX \rightarrow AYY \rightarrow DB.\n\n* **Greibach Normal Form (GNF):**\n * Every production is of the form: A \rightarrow a\alphaa \in \Sigma\alpha \in V_N^.\n * **Lemma 1 (Substitution):** If A \rightarrow B\gammaB \rightarrow \beta_1 \mid \beta_2 \mid \dots \mid \beta_kA \rightarrow B\gammaA \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_2\beta_iA:\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 aA \rightarrow SS \mid b):\n * Order variables: A_1 = SA_2 = A.\n * A_1 \rightarrow A_2 A_2 \mid a2 > 1; valid).\n * A_2 \rightarrow A_1 A_1 \mid b1 < 2A_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_2ZZ conform to GNF.\n * Substitute A_2A_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 Lnz \in L|z| \ge nzz = uvwxy satisfying:\n 1. |vwx| \le n\n 2. |vx| \ge 1\n 3. u v^i w x^i y \in Li \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 vwx\le n0, 1, 2 simultaneously.\n * Case 1: vwx012i = 001n2nuwy otin L.\n* Case 2: vwx120i = 0nnuwy 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 nvx cannot span more than two contiguous blocks.\n * Pumping down (i = 0w w.\n * Contradiction; L is not context-free.\n * **Language L = {0^p \mid p \text{ is prime}}:**\n * Choose z = 0^pp \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 vwxabbc).\n * Pumping down with i = 0abcabci > n). Contradiction.\n\n* **Closure Properties of Context-Free Languages:**\n * **Closed under Union:** Given G_1 = (V_1, \Sigma, P_1, S_1)G_2 = (V_2, \Sigma, P_2, S_2)S \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)S \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}L_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)Q\Sigma\Gamma\delta: Q \times (\Sigma \cup {\epsilon}) \times \Gamma \rightarrow \mathcal{P}(Q \times \Gamma^)q_0 \in QZ_0 \in \GammaF \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)}(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 wq_0.\n * Transition on delimiter cq_1\delta(q_0, c, X) = {(q_1, X)}X \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_2Z_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\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 AA \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]q, p \in QX \in \GammaqpX.\n * Start rules:\n * S \rightarrow [q_0 Z_0 p]p \in Q.\n * Production generation from transitions:\n * If \delta(q, a, X)(r, \epsilon)[q X r] \rightarrow a.\n * If \delta(q, a, X)(r, Y_1 Y_2 \dots Y_k)s_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 Qa \in \Sigma \cup {\epsilon}X \in \Gamma\delta(q, a, X) contains at most one element.\n 2. If \delta(q, \epsilon, X) eq \emptyset\delta(q, a, X) = \emptyseta \in \Sigma.\n\n* **DPDA Design Examples:**\n * **Language L = {0^n 1^m \mid n \le m}:**\n * q_00\delta(q_0, 0, Z_0) = (q_0, 0Z_0)\delta(q_0, 0, 0) = (q_0, 00).\n * q_110\delta(q_0, 1, 0) = (q_1, \epsilon)\delta(q_1, 1, 0) = (q_1, \epsilon).\n * q_2Z_0\delta(q_1, \epsilon, Z_0) = (q_2, Z_0).\n * Excess 1q_2\delta(q_2, 1, Z_0) = (q_2, Z_0).\n * **Language L = {0^n 1^m \mid n > m}:**\n * Push all 0q_0.\n * Pop 01q_1.\n * Accepting state requires that the input has been fully consumed while stack still contains unmatched 0\delta(q_1, \epsilon, 0) = (q_f, \epsilon)).\n\n* **Non-DPDA Languages:**\n * Languages such as L = {0^n 1^m 0^n}n, 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)Q\Sigma\Gamma\Sigma \subset \GammaB \in \Gamma - \Sigma\delta: Q \times \Gamma \rightarrow Q \times \Gamma \times {L, R}q_0 \in QF \subseteq Q is the set of final/halting states.\n\n* **Instantaneous Description (ID) Execution Traces:**\n * An ID is denoted as \alpha q \betaq\alpha\beta\beta.\n * Trace for TM on input 00b:\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_5q_500 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_60011 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 1\Sigma = {1}:**\n * States: Q = {q_0, q_1}\Gamma = {1, b}q_0F = {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 11b q_0 11b \vdash bb q_1 1b \vdash bbb q_0 bq_0; Accepted.\n * Trace on 111b q_0 111b \vdash bb q_1 11b \vdash bbb q_0 1b \vdash bbbb q_1 bq_1 otin F; Rejected.\n\n* **TM Design: Concatenation of Two Unary Strings (w_1 w_2):**\n * Objective: Connect two blocks of 1b1 to maintain total count, returning head to the start.\n * States and roles:\n * q_0b.\n * q_11b.\n * q_21b.\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\Gamma = {0, 1, X, Y, b}.\n * Transitions:\n * \delta(q_0, 0) = (q_1, X, R)0X.\n * \delta(q_1, 0) = (q_1, 0, R)\delta(q_1, Y) = (q_1, Y, R)0Ys.\n * \delta(q_1, 1) = (q_2, Y, L)1Y.\n * \delta(q_2, Y) = (q_2, Y, L)\delta(q_2, 0) = (q_2, 0, L)Y0s.\n * \delta(q_2, X) = (q_0, X, R)X.\n * \delta(q_0, Y) = (q_3, Y, R)01s 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)01s.\n * (q_1, 1)10s.\n * (q_1, b)b.\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 nnm times onto a designated output tape segment.\n * Examples: 2 \times 3 = 64 \times 2 = 8$$.