100% FREE Updated: Mar 2026 Formal Languages and Automata Theory Regular Languages and Finite Automata

Properties of Regular Languages

Comprehensive study notes on Properties of Regular Languages for CMI M.Sc. and Ph.D. Computer Science preparation. This chapter covers key concepts, formulas, and examples needed for your exam.

Properties of Regular Languages

This chapter rigorously examines the fundamental properties of regular languages, specifically their closure under various operations and the application of the Pumping Lemma. Mastery of these concepts is critical for classifying languages, proving non-regularity, and is frequently assessed in advanced theoretical computer science examinations.

---

Chapter Contents

|

| Topic |

|---|-------| |---|-------| | 1 | Closure Properties | | 2 | The Pumping Lemma for Regular Languages |

---

We begin with Closure Properties.

Part 1: Closure Properties

Regular languages are fundamental in formal language theory and computer science, possessing a robust set of properties under various operations. Understanding these closure properties is essential for proving the regularity of languages and for constructing automata.

---

Core Concepts

1. Union

We define the union of two languages L1L_1 and L2L_2 as the set of all strings that are in L1L_1 or in L2L_2 (or both). Regular languages are closed under union.

πŸ“ Closure Under Union

If L1L_1 and L2L_2 are regular languages over an alphabet Ξ£\Sigma, then L1βˆͺL2L_1 \cup L_2 is also a regular language.
Where:
L1,L2L_1, L_2 are regular languages.
L1βˆͺL2={w∣w∈L1Β orΒ w∈L2}L_1 \cup L_2 = \{w \mid w \in L_1 \text{ or } w \in L_2\}.
When to use: To combine two regular languages.

Worked Example:
Let L1L_1 be the language of strings over {a,b}\{a,b\} ending with aa, and L2L_2 be the language of strings over {a,b}\{a,b\} starting with bb. We show that L1βˆͺL2L_1 \cup L_2 is regular.

Step 1: Define regular expressions for L1L_1 and L2L_2.

> r1=(a+b)βˆ—ar_1 = (a+b)^*a
> r2=b(a+b)βˆ—r_2 = b(a+b)^*

Step 2: Construct an NFA for L1L_1.

>

q0β†’a,bq0β†’aq1Β (final)q0β†’bq0\begin{array}{rcccl} q_0 & \xrightarrow{a,b} & q_0 & \xrightarrow{a} & q_1 \text{ (final)} \\ & & q_0 \xrightarrow{b} q_0 & & \end{array}

> This is a simplified representation. A proper NFA construction for r1r_1 would be:
>
s0β†’Ξ΅q1,0β†’a,bq1,0q1,0β†’aq1,1Β (final)\begin{array}{rcccl} s_0 & \xrightarrow{\varepsilon} & q_{1,0} & \xrightarrow{a,b} & q_{1,0} \\ q_{1,0} & \xrightarrow{a} & q_{1,1} \text{ (final)} & & \end{array}

Step 3: Construct an NFA for L2L_2.

>

s0β†’Ξ΅q2,0β†’bq2,1q2,1β†’a,bq2,1Β (final)\begin{array}{rcccl} s_0 & \xrightarrow{\varepsilon} & q_{2,0} & \xrightarrow{b} & q_{2,1} \\ q_{2,1} & \xrightarrow{a,b} & q_{2,1} \text{ (final)} & & \end{array}

Step 4: Combine the NFAs for L1L_1 and L2L_2 using a new start state and Ξ΅\varepsilon-transitions.

> Let N1=(Q1,Ξ£,Ξ΄1,s1,F1)N_1 = (Q_1, \Sigma, \delta_1, s_1, F_1) be an NFA for L1L_1 and N2=(Q2,Ξ£,Ξ΄2,s2,F2)N_2 = (Q_2, \Sigma, \delta_2, s_2, F_2) be an NFA for L2L_2.
> Construct Nunion=(Q1βˆͺQ2βˆͺ{snew},Ξ£,Ξ΄union,snew,F1βˆͺF2)N_{union} = (Q_1 \cup Q_2 \cup \{s_{new}\}, \Sigma, \delta_{union}, s_{new}, F_1 \cup F_2).
> Ξ΄union(snew,Ξ΅)={s1,s2}\delta_{union}(s_{new}, \varepsilon) = \{s_1, s_2\}
> For any other state q∈Q1βˆͺQ2q \in Q_1 \cup Q_2 and symbol c∈Σβˆͺ{Ξ΅}c \in \Sigma \cup \{\varepsilon\}, Ξ΄union(q,c)=Ξ΄1(q,c)\delta_{union}(q, c) = \delta_1(q, c) if q∈Q1q \in Q_1 and Ξ΄union(q,c)=Ξ΄2(q,c)\delta_{union}(q, c) = \delta_2(q, c) if q∈Q2q \in Q_2.

Answer: Since we can construct an NFA for L1βˆͺL2L_1 \cup L_2, L1βˆͺL2L_1 \cup L_2 is regular.

:::question type="MCQ" question="Let L1L_1 be the language accepted by the regular expression aβˆ—ba^b and L2L_2 be the language accepted by bβˆ—ab^a. Which of the following regular expressions accepts L1βˆͺL2L_1 \cup L_2?" options=["aβˆ—b+bβˆ—aa^b + b^a","(a+b)βˆ—(a+b)(a+b)^(a+b)","aβˆ—bbβˆ—aa^b b^a","(a+b)βˆ—(a+b)^"] answer="aβˆ—b+bβˆ—aa^b + b^a" hint="The union of two regular languages is represented by the sum of their regular expressions." solution="The union of two regular languages L1L_1 and L2L_2 is denoted by L1βˆͺL2L_1 \cup L_2. If r1r_1 is a regular expression for L1L_1 and r2r_2 is a regular expression for L2L_2, then r1+r2r_1 + r_2 is a regular expression for L1βˆͺL2L_1 \cup L_2.
In this case, r1=aβˆ—br_1 = a^b and r2=bβˆ—ar_2 = b^a.
Therefore, r1+r2=aβˆ—b+bβˆ—ar_1 + r_2 = a^b + b^a accepts L1βˆͺL2L_1 \cup L_2.
This corresponds to the first option."
:::

---

2. Intersection

We define the intersection of two languages L1L_1 and L2L_2 as the set of all strings that are in both L1L_1 and L2L_2. Regular languages are closed under intersection.

πŸ“ Closure Under Intersection

If L1L_1 and L2L_2 are regular languages over an alphabet Σ\Sigma, then L1∩L2L_1 \cap L_2 is also a regular language.
Where:
L1,L2L_1, L_2 are regular languages.
L1∩L2={w∣w∈L1 and w∈L2}L_1 \cap L_2 = \{w \mid w \in L_1 \text{ and } w \in L_2\}.
When to use: To find common strings between two regular languages. Often proved using product construction of DFAs.

Worked Example:
Let L1L_1 be the language of strings over {a,b}\{a,b\} with an even number of aa's, and L2L_2 be the language of strings over {a,b}\{a,b\} with an even number of bb's. We show that L1∩L2L_1 \cap L_2 is regular.

Step 1: Construct a DFA for L1L_1.

>

statesinput ainput b→q0eq0oq0e (final)q0oq0eq0o\begin{array}{rcccl} & \text{states} & \text{input } a & \text{input } b \\ \rightarrow & q_{0e} & q_{0o} & q_{0e} \text{ (final)} \\ & q_{0o} & q_{0e} & q_{0o} \end{array}

> Where q0eq_{0e} is even aa's, q0oq_{0o} is odd aa's.

Step 2: Construct a DFA for L2L_2.

>

statesinput ainput b→qe0qe0qo0 (final)qo0qo0qe0\begin{array}{rcccl} & \text{states} & \text{input } a & \text{input } b \\ \rightarrow & q_{e0} & q_{e0} & q_{o0} \text{ (final)} \\ & q_{o0} & q_{o0} & q_{e0} \end{array}

> Where qe0q_{e0} is even bb's, qo0q_{o0} is odd bb's.

Step 3: Perform a product construction for L1∩L2L_1 \cap L_2.
The states of the new DFA MintM_{int} are pairs (qi,qj)(q_i, q_j) where qi∈Q1q_i \in Q_1 and qj∈Q2q_j \in Q_2. The start state is (s1,s2)(s_1, s_2). A state (qi,qj)(q_i, q_j) is final if qi∈F1q_i \in F_1 AND qj∈F2q_j \in F_2.
The transition function is Ξ΄int((qi,qj),x)=(Ξ΄1(qi,x),Ξ΄2(qj,x))\delta_{int}((q_i, q_j), x) = (\delta_1(q_i, x), \delta_2(q_j, x)).

>

statesinput ainput b→(q0e,qe0)(q0o,qe0)(q0e,qo0) (final)(q0o,qe0)(q0e,qe0)(q0o,qo0)(q0e,qo0)(q0o,qo0)(q0e,qe0)(q0o,qo0)(q0e,qo0)(q0o,qe0)\begin{array}{rcccl} & \text{states} & \text{input } a & \text{input } b \\ \rightarrow & (q_{0e}, q_{e0}) & (q_{0o}, q_{e0}) & (q_{0e}, q_{o0}) \text{ (final)} \\ & (q_{0o}, q_{e0}) & (q_{0e}, q_{e0}) & (q_{0o}, q_{o0}) \\ & (q_{0e}, q_{o0}) & (q_{0o}, q_{o0}) & (q_{0e}, q_{e0}) \\ & (q_{0o}, q_{o0}) & (q_{0e}, q_{o0}) & (q_{0o}, q_{e0}) \end{array}

Answer: The state (q0e,qe0)(q_{0e}, q_{e0}) is the initial state and also a final state because both q0eq_{0e} and qe0q_{e0} are final states in their respective DFAs. This implies that the empty string Ρ\varepsilon is in L1∩L2L_1 \cap L_2. The resulting DFA accepts L1∩L2L_1 \cap L_2, hence it is regular.

:::question type="NAT" question="Let L1L_1 be the language of strings over {0,1}\{0,1\} containing an even number of 00 s, and L2L_2 be the language of strings over {0,1}\{0,1\} containing at least two 11 s. What is the minimum number of states in a DFA for L1∩L2L_1 \cap L_2?" answer="6" hint="Construct DFAs for L1L_1 and L2L_2 separately, then perform a product construction for their intersection. Count the reachable states." solution="Step 1: DFA for L1L_1 (even number of 0s)
Let M1=(Q1,Ξ£,Ξ΄1,q0e,F1)M_1 = (Q_1, \Sigma, \delta_1, q_{0e}, F_1)
Q1={q0e,q0o}Q_1 = \{q_{0e}, q_{0o}\} (even 0s, odd 0s)
F1={q0e}F_1 = \{q_{0e}\}
Transitions:
Ξ΄1(q0e,0)=q0o\delta_1(q_{0e}, 0) = q_{0o}
Ξ΄1(q0e,1)=q0e\delta_1(q_{0e}, 1) = q_{0e}
Ξ΄1(q0o,0)=q0e\delta_1(q_{0o}, 0) = q_{0e}
Ξ΄1(q0o,1)=q0o\delta_1(q_{0o}, 1) = q_{0o}
This DFA has 2 states.

Step 2: DFA for L2L_2 (at least two 1s)
Let M2=(Q2,Ξ£,Ξ΄2,qs,F2)M_2 = (Q_2, \Sigma, \delta_2, q_{s}, F_2)
Q2={qs,q1,q2}Q_2 = \{q_s, q_1, q_2\} (start, one 1 seen, two or more 1s seen)
F2={q2}F_2 = \{q_2\}
Transitions:
Ξ΄2(qs,0)=qs\delta_2(q_s, 0) = q_s
Ξ΄2(qs,1)=q1\delta_2(q_s, 1) = q_1
Ξ΄2(q1,0)=q1\delta_2(q_1, 0) = q_1
Ξ΄2(q1,1)=q2\delta_2(q_1, 1) = q_2
Ξ΄2(q2,0)=q2\delta_2(q_2, 0) = q_2
Ξ΄2(q2,1)=q2\delta_2(q_2, 1) = q_2
This DFA has 3 states.

Step 3: Product Construction for L1∩L2L_1 \cap L_2
The new DFA MintM_{int} will have states (qi,qj)(q_i, q_j) where qi∈Q1q_i \in Q_1 and qj∈Q2q_j \in Q_2. The initial state is (q0e,qs)(q_{0e}, q_s). A state (qi,qj)(q_i, q_j) is final if qi∈F1q_i \in F_1 AND qj∈F2q_j \in F_2.
Number of potential states = ∣Q1βˆ£Γ—βˆ£Q2∣=2Γ—3=6|Q_1| \times |Q_2| = 2 \times 3 = 6.
Let's list the reachable states and their transitions:

  • (q0e,qs)(q_{0e}, q_s) (Start state)

  • * (q0e,qs)β†’0(Ξ΄1(q0e,0),Ξ΄2(qs,0))=(q0o,qs)(q_{0e}, q_s) \xrightarrow{0} (\delta_1(q_{0e}, 0), \delta_2(q_s, 0)) = (q_{0o}, q_s)
    * (q0e,qs)β†’1(Ξ΄1(q0e,1),Ξ΄2(qs,1))=(q0e,q1)(q_{0e}, q_s) \xrightarrow{1} (\delta_1(q_{0e}, 1), \delta_2(q_s, 1)) = (q_{0e}, q_1)
  • (q0o,qs)(q_{0o}, q_s)

  • * (q0o,qs)β†’0(Ξ΄1(q0o,0),Ξ΄2(qs,0))=(q0e,qs)(q_{0o}, q_s) \xrightarrow{0} (\delta_1(q_{0o}, 0), \delta_2(q_s, 0)) = (q_{0e}, q_s)
    * (q0o,qs)β†’1(Ξ΄1(q0o,1),Ξ΄2(qs,1))=(q0o,q1)(q_{0o}, q_s) \xrightarrow{1} (\delta_1(q_{0o}, 1), \delta_2(q_s, 1)) = (q_{0o}, q_1)
  • (q0e,q1)(q_{0e}, q_1)

  • * (q0e,q1)β†’0(Ξ΄1(q0e,0),Ξ΄2(q1,0))=(q0o,q1)(q_{0e}, q_1) \xrightarrow{0} (\delta_1(q_{0e}, 0), \delta_2(q_1, 0)) = (q_{0o}, q_1)
    * (q0e,q1)β†’1(Ξ΄1(q0e,1),Ξ΄2(q1,1))=(q0e,q2)(q_{0e}, q_1) \xrightarrow{1} (\delta_1(q_{0e}, 1), \delta_2(q_1, 1)) = (q_{0e}, q_2) (Final if q0e∈F1q_{0e} \in F_1 and q2∈F2q_2 \in F_2)
  • (q0o,q1)(q_{0o}, q_1)

  • * (q0o,q1)β†’0(Ξ΄1(q0o,0),Ξ΄2(q1,0))=(q0e,q1)(q_{0o}, q_1) \xrightarrow{0} (\delta_1(q_{0o}, 0), \delta_2(q_1, 0)) = (q_{0e}, q_1)
    * (q0o,q1)β†’1(Ξ΄1(q0o,1),Ξ΄2(q1,1))=(q0o,q2)(q_{0o}, q_1) \xrightarrow{1} (\delta_1(q_{0o}, 1), \delta_2(q_1, 1)) = (q_{0o}, q_2)
  • (q0e,q2)(q_{0e}, q_2) (Final state, as q0e∈F1q_{0e} \in F_1 and q2∈F2q_2 \in F_2)

  • * (q0e,q2)β†’0(Ξ΄1(q0e,0),Ξ΄2(q2,0))=(q0o,q2)(q_{0e}, q_2) \xrightarrow{0} (\delta_1(q_{0e}, 0), \delta_2(q_2, 0)) = (q_{0o}, q_2)
    * (q0e,q2)β†’1(Ξ΄1(q0e,1),Ξ΄2(q2,1))=(q0e,q2)(q_{0e}, q_2) \xrightarrow{1} (\delta_1(q_{0e}, 1), \delta_2(q_2, 1)) = (q_{0e}, q_2)
  • (q0o,q2)(q_{0o}, q_2)

  • * (q0o,q2)β†’0(Ξ΄1(q0o,0),Ξ΄2(q2,0))=(q0e,q2)(q_{0o}, q_2) \xrightarrow{0} (\delta_1(q_{0o}, 0), \delta_2(q_2, 0)) = (q_{0e}, q_2)
    * (q0o,q2)β†’1(Ξ΄1(q0o,1),Ξ΄2(q2,1))=(q0o,q2)(q_{0o}, q_2) \xrightarrow{1} (\delta_1(q_{0o}, 1), \delta_2(q_2, 1)) = (q_{0o}, q_2)

    All 6 possible product states are reachable.
    The final states are those where both components are final: (q0e,q2)(q_{0e}, q_2).
    The minimum number of states in a DFA for L1∩L2L_1 \cap L_2 is 6."
    :::

    ---

    3. Complement

    The complement of a language LL over an alphabet Ξ£\Sigma is the set of all strings in Ξ£βˆ—\Sigma^* that are not in LL. Regular languages are closed under complementation.

    πŸ“ Closure Under Complement

    If LL is a regular language over an alphabet Ξ£\Sigma, then its complement Lβ€Ύ=Ξ£βˆ—βˆ–L\overline{L} = \Sigma^* \setminus L is also a regular language.
    When to use: To define languages consisting of all strings NOT accepted by a given regular language. This property applies directly to DFAs.

    Worked Example:
    Let LL be the language of strings over {a,b}\{a,b\} containing at least one aa. We show that Lβ€Ύ\overline{L} is regular.

    Step 1: Construct a DFA for LL.

    >

    β†’q0β†’aq1Β (final)q0β†’bq0q1β†’a,bq1\begin{array}{rcccl} \rightarrow & q_0 & \xrightarrow{a} & q_1 \text{ (final)} \\ & q_0 & \xrightarrow{b} & q_0 \\ & q_1 & \xrightarrow{a,b} & q_1 \end{array}

    Step 2: To obtain a DFA for Lβ€Ύ\overline{L}, we swap the final and non-final states of the DFA for LL.
    The new final states are the old non-final states, and the new non-final states are the old final states.

    >

    β†’q0Β (final)β†’aq1q0β†’bq0Β (final)q1β†’a,bq1\begin{array}{rcccl} \rightarrow & q_0 \text{ (final)} & \xrightarrow{a} & q_1 \\ & q_0 & \xrightarrow{b} & q_0 \text{ (final)} \\ & q_1 & \xrightarrow{a,b} & q_1 \end{array}

    > The new DFA has q0q_0 as the only final state. q1q_1 is now a non-final state.

    Answer: The resulting DFA accepts only strings consisting solely of bb's, i.e., bβˆ—b^. This is precisely Lβ€Ύ\overline{L}, which consists of all strings over {a,b}\{a,b\} that do not contain any aa. Since bβˆ—b^ is a regular language, Lβ€Ύ\overline{L} is regular.

    ⚠️ Common Mistake: Complementing NFA Directly

    ❌ Naively swapping final and non-final states in an NFA does NOT generally yield an NFA for the complement.
    βœ… To complement an NFA, first convert it to an equivalent DFA, then swap the final and non-final states of the DFA.

    :::question type="MSQ" question="Let LL be a regular language over Ξ£={0,1}\Sigma = \{0,1\} such that LL contains all strings with an even number of 00 s. Which of the following statements about Lβ€Ύ\overline{L} (the complement of LL) are true?" options=["Lβ€Ύ\overline{L} is the set of all strings with an odd number of 00 s.","Lβ€Ύ\overline{L} is regular.","A DFA for LL can be transformed into a DFA for Lβ€Ύ\overline{L} by swapping final and non-final states.","Lβ€Ύ\overline{L} is equal to LA∩LBL_A \cap L_B for some non-regular languages LA,LBL_A, L_B."] answer="Lβ€Ύ\overline{L} is the set of all strings with an odd number of 00 s.,Lβ€Ύ\overline{L} is regular.,A DFA for LL can be transformed into a DFA for Lβ€Ύ\overline{L} by swapping final and non-final states." hint="Recall the definition of complement and the closure property for regular languages. Consider how complementation works for DFAs." solution="1. Lβ€Ύ\overline{L} is the set of all strings with an odd number of 00 s.
    If LL contains all strings with an even number of 00 s, then its complement Lβ€Ύ\overline{L} must contain all strings that do NOT have an even number of 00 s. This means Lβ€Ύ\overline{L} contains all strings with an odd number of 00 s. This statement is TRUE.

  • Lβ€Ύ\overline{L} is regular.

  • Regular languages are closed under complementation. If LL is regular, then Lβ€Ύ\overline{L} must also be regular. This statement is TRUE.
  • A DFA for LL can be transformed into a DFA for Lβ€Ύ\overline{L} by swapping final and non-final states.

  • This is the standard procedure for constructing a DFA for the complement of a language LL from a DFA for LL. This statement is TRUE.
  • Lβ€Ύ\overline{L} is equal to LA∩LBL_A \cap L_B for some non-regular languages LA,LBL_A, L_B.

  • While it might be possible to construct such LA,LBL_A, L_B for specific cases, the statement implies that this is a general property of complements of regular languages. The intersection of two non-regular languages can be regular, but Lβ€Ύ\overline{L} being regular does not necessitate such a decomposition. For instance, Lβ€Ύ\overline{L} is regular itself, and we can trivially say Lβ€Ύ=Lβ€Ύβˆ©Ξ£βˆ—\overline{L} = \overline{L} \cap \Sigma^, where Ξ£βˆ—\Sigma^ is regular. More importantly, this statement doesn't reflect a direct closure property or a standard way to characterize Lβ€Ύ\overline{L}. It's a distractor. This statement is FALSE."
    :::

    ---

    4. Concatenation

    The concatenation of two languages L1L_1 and L2L_2 is the set of all strings formed by taking a string from L1L_1 and appending a string from L2L_2. Regular languages are closed under concatenation.

    πŸ“ Closure Under Concatenation

    If L1L_1 and L2L_2 are regular languages over an alphabet Ξ£\Sigma, then L1L2L_1 L_2 is also a regular language.
    Where:
    L1,L2L_1, L_2 are regular languages.
    L1L2={w1w2∣w1∈L1 and w2∈L2}L_1 L_2 = \{w_1 w_2 \mid w_1 \in L_1 \text{ and } w_2 \in L_2\}.
    When to use: To combine two regular languages sequentially.

    Worked Example:
    Let L1={an∣nβ‰₯0}L_1 = \{a^n \mid n \ge 0\} and L2={bm∣mβ‰₯1}L_2 = \{b^m \mid m \ge 1\}. We show that L1L2L_1 L_2 is regular.

    Step 1: Define regular expressions for L1L_1 and L2L_2.

    > r1=aβˆ—r_1 = a^*
    > r2=bbβˆ—r_2 = b b^*

    Step 2: Construct an NFA for L1L_1.

    >

    β†’Β (final)q0β†’aq0\begin{array}{rcl} \rightarrow \text{ (final)} q_0 & \xrightarrow{a} & q_0 \end{array}

    Step 3: Construct an NFA for L2L_2.

    >

    β†’q2β†’bq3Β (final)q3β†’bq3\begin{array}{rcl} \rightarrow q_2 & \xrightarrow{b} & q_3 \text{ (final)} \\ q_3 & \xrightarrow{b} & q_3 \end{array}

    Step 4: Combine the NFAs for L1L_1 and L2L_2 using Ξ΅\varepsilon-transitions from final states of N1N_1 to the start state of N2N_2.

    > Let N1=(Q1,Ξ£,Ξ΄1,s1,F1)N_1 = (Q_1, \Sigma, \delta_1, s_1, F_1) for L1L_1 and N2=(Q2,Ξ£,Ξ΄2,s2,F2)N_2 = (Q_2, \Sigma, \delta_2, s_2, F_2) for L2L_2.
    > Construct Nconcat=(Q1βˆͺQ2,Ξ£,Ξ΄concat,s1,F2)N_{concat} = (Q_1 \cup Q_2, \Sigma, \delta_{concat}, s_1, F_2).
    > δconcat(q,c)=δ1(q,c)\delta_{concat}(q, c) = \delta_1(q, c) for q∈Q1q \in Q_1, c∈Σc \in \Sigma.
    > δconcat(q,c)=δ2(q,c)\delta_{concat}(q, c) = \delta_2(q, c) for q∈Q2q \in Q_2, c∈Σc \in \Sigma.
    > For each f∈F1f \in F_1, add an Ξ΅\varepsilon-transition: Ξ΄concat(f,Ξ΅)=Ξ΄1(f,Ξ΅)βˆͺ{s2}\delta_{concat}(f, \varepsilon) = \delta_1(f, \varepsilon) \cup \{s_2\}.

    >

    β†’Β (final)q0β†’aq0q0β†’Ξ΅q2q2β†’bq3Β (final)q3β†’bq3\begin{array}{rcccl} \rightarrow \text{ (final)} q_0 & \xrightarrow{a} & q_0 \\ q_0 & \xrightarrow{\varepsilon} & q_2 \\ q_2 & \xrightarrow{b} & q_3 \text{ (final)} \\ q_3 & \xrightarrow{b} & q_3 \end{array}

    > Note: q0q_0 is final in N1N_1, so it has an Ξ΅\varepsilon-transition to q2q_2. The final states of NconcatN_{concat} are only those of N2N_2.

    Answer: The resulting NFA accepts L1L2=aβˆ—b+L_1 L_2 = a^* b^+, which is regular.

    :::question type="MCQ" question="Given two regular languages L1={w∈{0,1}βˆ—βˆ£wΒ endsΒ withΒ 0}L_1 = \{w \in \{0,1\}^ \mid w \text{ ends with } 0\} and L2={w∈{0,1}βˆ—βˆ£wΒ beginsΒ withΒ 1}L_2 = \{w \in \{0,1\}^ \mid w \text{ begins with } 1\}. Which of the following regular expressions correctly represents L1L2L_1 L_2?" options=["(0+1)βˆ—01(0+1)βˆ—(0+1)^01(0+1)^","(0+1)βˆ—0+1(0+1)βˆ—(0+1)^0 + 1(0+1)^","(0+1)βˆ—(0+1)(0+1)^(0+1)","(0+1)βˆ—0β‹…1(0+1)βˆ—(0+1)^0 \cdot 1(0+1)^"] answer="(0+1)βˆ—01(0+1)βˆ—(0+1)^01(0+1)^*" hint="Concatenation of regular expressions is simply placing them side-by-side. Simplify the resulting expression if possible." solution="Step 1: Write regular expressions for L1L_1 and L2L_2.
    L1L_1: strings ending with 00. Regular expression r1=(0+1)βˆ—0r_1 = (0+1)^*0.
    L2L_2: strings beginning with 11. Regular expression r2=1(0+1)βˆ—r_2 = 1(0+1)^*.

    Step 2: Concatenate the regular expressions.
    The regular expression for L1L2L_1 L_2 is r1r2r_1 r_2.
    r1r2=(0+1)βˆ—0β‹…1(0+1)βˆ—r_1 r_2 = (0+1)^0 \cdot 1(0+1)^.

    Step 3: Simplify the expression.
    The expression (0+1)βˆ—01(0+1)βˆ—(0+1)^01(0+1)^ is equivalent to (0+1)βˆ—0β‹…1(0+1)βˆ—(0+1)^0 \cdot 1(0+1)^.
    This represents all strings that contain the substring 0101.
    Thus, (0+1)βˆ—01(0+1)βˆ—(0+1)^01(0+1)^ is the correct regular expression for L1L2L_1 L_2."
    :::

    ---

    5. Kleene Star (Closure)

    The Kleene star of a language LL, denoted Lβˆ—L^*, is the set of all strings formed by concatenating zero or more strings from LL. Regular languages are closed under the Kleene star operation.

    πŸ“ Closure Under Kleene Star

    If LL is a regular language over an alphabet Ξ£\Sigma, then Lβˆ—L^ is also a regular language.
    Where:
    LL is a regular language.
    Lβˆ—={Ξ΅}βˆͺLβˆͺLLβˆͺLLLβˆͺβ‹―L^
    = \{\varepsilon\} \cup L \cup LL \cup LLL \cup \cdots.
    When to use: To represent repetition of patterns.

    Worked Example:
    Let L={ab}L = \{ab\}. We show that Lβˆ—L^* is regular.

    Step 1: Construct an NFA for LL.

    >

    β†’q0β†’aq1q1β†’bq2Β (final)\begin{array}{rcl} \rightarrow q_0 & \xrightarrow{a} & q_1 \\ q_1 & \xrightarrow{b} & q_2 \text{ (final)} \end{array}

    Step 2: Construct an NFA for Lβˆ—L^*.
    Add a new start state snews_{new} which is also a final state. Add an Ξ΅\varepsilon-transition from snews_{new} to the original start state s0s_0. Add Ξ΅\varepsilon-transitions from all original final states to s0s_0.

    > Let N=(Q,Ξ£,Ξ΄,s0,F)N = (Q, \Sigma, \delta, s_0, F) be an NFA for LL.
    > Construct Nβˆ—=(Qβˆͺ{snew},Ξ£,Ξ΄βˆ—,snew,Fβˆͺ{snew})N^ = (Q \cup \{s_{new}\}, \Sigma, \delta^, s_{new}, F \cup \{s_{new}\}).
    > Ξ΄βˆ—(snew,Ξ΅)={s0}\delta^*(s_{new}, \varepsilon) = \{s_0\}
    > For each f∈Ff \in F, Ξ΄βˆ—(f,Ξ΅)=Ξ΄(f,Ξ΅)βˆͺ{s0}\delta^*(f, \varepsilon) = \delta(f, \varepsilon) \cup \{s_0\}
    > For all other transitions, Ξ΄βˆ—(q,c)=Ξ΄(q,c)\delta^*(q, c) = \delta(q, c).

    > For L={ab}L = \{ab\}:
    >

    → (final)qnew→Ρq0q0→aq1q1→bq2 (final)q2→Ρq0\begin{array}{rcccl} \rightarrow \text{ (final)} q_{new} & \xrightarrow{\varepsilon} & q_0 \\ q_0 & \xrightarrow{a} & q_1 \\ q_1 & \xrightarrow{b} & q_2 \text{ (final)} \\ q_2 & \xrightarrow{\varepsilon} & q_0 \end{array}

    Answer: The resulting NFA accepts (ab)βˆ—(ab)^*, which is regular.

    :::question type="MCQ" question="Let LL be the language of strings over {x,y}\{x,y\} consisting of a single xx followed by any number of yy's (i.e., xyβˆ—xy^). Which of the following regular expressions represents Lβˆ—L^?" options=["(xyβˆ—)βˆ—(xy^)^","xβˆ—yβˆ—x^y^","x(yβˆ—)βˆ—x(y^)^","(x+y)βˆ—(x+y)^"] answer="(xyβˆ—)βˆ—(xy^)^" hint="The Kleene star operation applies to the entire language LL as a single unit." solution="The language LL is given by the regular expression xyβˆ—xy^.
    The Kleene star of LL, denoted Lβˆ—L^*, means taking zero or more concatenations of strings from LL.
    Therefore, the regular expression for Lβˆ—L^ is simply (xyβˆ—)βˆ—(xy^)^*.
    This matches the first option."
    :::

    ---

    6. Reverse

    The reverse of a string w=a1a2β‹―anw = a_1 a_2 \cdots a_n is wR=anβ‹―a2a1w^R = a_n \cdots a_2 a_1. The reverse of a language LL, denoted LRL^R (or rev⁑(L)\operatorname{rev}(L)), is the set of reverses of all strings in LL. Regular languages are closed under reversal.

    πŸ“ Closure Under Reverse

    If LL is a regular language over an alphabet Σ\Sigma, then LR={wR∣w∈L}L^R = \{w^R \mid w \in L\} is also a regular language.
    When to use: To check if a language formed by reversing all strings of a known regular language is also regular.

    Worked Example:
    Let LL be the language accepted by the DFA below. We show that LRL^R is regular.

    >

    β†’q0β†’aq1q0β†’bq0q1β†’aq1q1β†’bq0Β (final)\begin{array}{rcccl} \rightarrow q_0 & \xrightarrow{a} & q_1 \\ q_0 & \xrightarrow{b} & q_0 \\ q_1 & \xrightarrow{a} & q_1 \\ q_1 & \xrightarrow{b} & q_0 \text{ (final)} \end{array}

    This DFA accepts strings ending in bb and having an odd number of aa's before the last bb. For example, abab, aaabaaab, babbab.

    Step 1: Convert the DFA to an NFA where all original final states become new start states, and the original start state becomes the new (single) final state. Reverse all transitions.

    > Let M=(Q,Ξ£,Ξ΄,q0,F)M = (Q, \Sigma, \delta, q_0, F) be a DFA for LL.
    > Construct NR=(Q,Ξ£,Ξ΄R,Fnew,{q0})N^R = (Q, \Sigma, \delta^R, F_{new}, \{q_0\}), where FnewF_{new} is the set of states that were final in MM.
    > Ξ΄R(q,a)\delta^R(q, a) contains pp if Ξ΄(p,a)=q\delta(p, a) = q.
    > If there are multiple final states in MM, we introduce a new start state snews_{new} with Ξ΅\varepsilon-transitions to each state in FF. The final state is q0q_0.

    > Original DFA:
    > q0β†’aq1q_0 \xrightarrow{a} q_1
    > q0β†’bq0q_0 \xrightarrow{b} q_0
    > q1β†’aq1q_1 \xrightarrow{a} q_1
    > q1β†’bq0q_1 \xrightarrow{b} q_0 (final)

    > New NFA (after reversing transitions and swapping start/final):
    > The original final state is q0q_0. So q0q_0 becomes the new start state.
    > The original start state is q0q_0. So q0q_0 becomes the new final state. (This is a bit confusing because q0q_0 is used for both roles. Let's be explicit.)
    > New Start State: q0β€²q_0' (This is the original final state q0q_0 from the DFA)
    > New Final State: q0β€²β€²q_0'' (This is the original start state q0q_0 from the DFA)
    >
    > From the original transitions:
    > Ξ΄(q0,a)=q1β€…β€ŠβŸΉβ€…β€ŠΞ΄R(q1,a)=q0\delta(q_0, a) = q_1 \implies \delta^R(q_1, a) = q_0
    > Ξ΄(q0,b)=q0β€…β€ŠβŸΉβ€…β€ŠΞ΄R(q0,b)=q0\delta(q_0, b) = q_0 \implies \delta^R(q_0, b) = q_0
    > Ξ΄(q1,a)=q1β€…β€ŠβŸΉβ€…β€ŠΞ΄R(q1,a)=q1\delta(q_1, a) = q_1 \implies \delta^R(q_1, a) = q_1
    > Ξ΄(q1,b)=q0β€…β€ŠβŸΉβ€…β€ŠΞ΄R(q0,b)=q1\delta(q_1, b) = q_0 \implies \delta^R(q_0, b) = q_1 (This is where the original q0q_0 was a final state).

    Step 2: Let's denote the states of the original DFA as q0,q1q_0, q_1.
    The original start state is q0q_0. The original final state is q0q_0.
    So the NFA for LRL^R has q0q_0 as the new start state, and q0q_0 as the new final state.

    >

    β†’Β (final)q0β†’bq0q0β†’bq1q1β†’aq0q1β†’aq1\begin{array}{rcccl} \rightarrow \text{ (final)} q_0 & \xrightarrow{b} & q_0 \\ q_0 & \xrightarrow{b} & q_1 \\ q_1 & \xrightarrow{a} & q_0 \\ q_1 & \xrightarrow{a} & q_1 \end{array}

    > Note: The new start state is q0q_0 (because it was the only final state in the original DFA). The new final state is q0q_0 (because it was the original start state).

    Answer: The resulting NFA accepts LRL^R. Since we can construct an NFA for LRL^R, LRL^R is regular. This NFA needs to be converted to a DFA to be minimized and properly analyzed. For example, LRL^R would accept strings starting with bb and having an odd number of aa's after the first bb.

    :::question type="MCQ" question="Let LL be the language of strings over {0,1}\{0,1\} such that every string contains at least one 00 and ends with 11. Which of the following is true about LRL^R?" options=["LRL^R is regular and consists of strings starting with 11 and containing at least one 00.","LRL^R is regular and consists of strings ending with 00 and containing at least one 11.","LRL^R is not regular.","The regular expression for LRL^R is 0(0+1)βˆ—1(0+1)βˆ—0(0+1)^1(0+1)^."] answer="LRL^R is regular and consists of strings starting with 11 and containing at least one 00." hint="First, define LL with a regular expression or DFA. Then, apply the reversal operation to its definition. Remember that regular languages are closed under reversal." solution="Step 1: Define LL.
    LL consists of strings over {0,1}\{0,1\} that contain at least one 00 AND end with 11.
    A regular expression for LL is (0+1)βˆ—0(0+1)βˆ—1(0+1)^0(0+1)^1.
    For example, 0101, 101101, 001001, 11011101.

    Step 2: Apply reversal to LL.
    If w∈Lw \in L, then w=x0y1w = x0y1 for some x,y∈{0,1}βˆ—x,y \in \{0,1\}^*.
    Then wR=(x0y1)R=1RyR0RxR=1yR0xRw^R = (x0y1)^R = 1^R y^R 0^R x^R = 1 y^R 0 x^R.
    This means strings in LRL^R start with 11, contain at least one 00, and have an arbitrary suffix.
    More formally, if ww ends with 11, then wRw^R starts with 11.
    If ww contains at least one 00, then wRw^R also contains at least one 00.
    So LRL^R is the language of strings that start with 11 and contain at least one 00.

    Step 3: Check regularity.
    Since LL is regular, LRL^R must also be regular because regular languages are closed under reversal.
    The regular expression for LRL^R would be 1(0+1)βˆ—0(0+1)βˆ—1(0+1)^0(0+1)^.

    Step 4: Evaluate options.
    * "LRL^R is regular and consists of strings starting with 11 and containing at least one 00." - This matches our analysis.
    * "LRL^R is regular and consists of strings ending with 00 and containing at least one 11." - Incorrect.
    * "LRL^R is not regular." - Incorrect, as regular languages are closed under reversal.
    "The regular expression for LRL^R is 0(0+1)βˆ—1(0+1)βˆ—0(0+1)^1(0+1)^" - This is the reverse of 1(0+1)βˆ—0(0+1)βˆ—1(0+1)^0(0+1)^*, not for LRL^R itself. It would describe strings starting with 0 and containing at least one 1. Incorrect.

    Therefore, the first option is correct."
    :::

    ---

    7. Homomorphism

    A homomorphism is a function h:Ξ£βˆ—β†’Ξ”βˆ—h: \Sigma^ \to \Delta^ that maps strings from one alphabet to strings over another alphabet, such that h(Ξ΅)=Ξ΅h(\varepsilon) = \varepsilon and h(w1w2)=h(w1)h(w2)h(w_1 w_2) = h(w_1) h(w_2). Regular languages are closed under homomorphism.

    πŸ“ Closure Under Homomorphism

    If LL is a regular language over an alphabet Ξ£\Sigma and h:Ξ£βˆ—β†’Ξ”βˆ—h: \Sigma^ \to \Delta^ is a homomorphism, then h(L)={h(w)∣w∈L}h(L) = \{h(w) \mid w \in L\} is also a regular language.
    When to use: To transform a regular language by substituting each symbol with a string.

    Worked Example:
    Let LL be the language (01)βˆ—(01)^*, and let hh be a homomorphism defined by h(0)=aah(0) = aa and h(1)=bh(1) = b. We show that h(L)h(L) is regular.

    Step 1: Understand the language LL.
    L={Ξ΅,01,0101,010101,… }L = \{\varepsilon, 01, 0101, 010101, \dots\}.

    Step 2: Apply the homomorphism to the regular expression for LL.
    The regular expression for LL is (01)βˆ—(01)^*.
    h((01)βˆ—)=(h(0)h(1))βˆ—h((01)^) = (h(0)h(1))^.
    Substitute the definitions of h(0)h(0) and h(1)h(1).

    > h(0)=aah(0) = aa
    > h(1)=bh(1) = b
    > h(01)=h(0)h(1)=aabh(01) = h(0)h(1) = aab

    Step 3: Form the regular expression for h(L)h(L).

    > h(L)=(aab)βˆ—h(L) = (aab)^*

    Answer: Since (aab)βˆ—(aab)^* is a regular expression, h(L)h(L) is a regular language.

    :::question type="MCQ" question="Let LL be the language defined by the regular expression aβˆ—b+a^b^+. Let hh be a homomorphism defined as h(a)=01h(a) = 01 and h(b)=1h(b) = 1. Which of the following regular expressions represents h(L)h(L)?" options=["(01)βˆ—1+(01)^1^+","(01)βˆ—+1+(01)^+1^+","(01)1(01)1","(01)1βˆ—(01)1^"] answer="(01)βˆ—1+(01)^1^+" hint="Apply the homomorphism to each symbol in the regular expression, then combine the results according to the original structure." solution="Step 1: Start with the regular expression for LL: aβˆ—b+a^b^+.

    Step 2: Apply the homomorphism hh to each part of the regular expression.
    h(aβˆ—)=(h(a))βˆ—=(01)βˆ—h(a^) = (h(a))^ = (01)^*.
    h(b+)=(h(b))+=(1)+=1+h(b^+) = (h(b))^+ = (1)^+ = 1^+.

    Step 3: Combine the homomorphic images according to the original concatenation.
    h(L)=h(aβˆ—b+)=h(aβˆ—)h(b+)=(01)βˆ—1+h(L) = h(a^b^+) = h(a^)h(b^+) = (01)^*1^+.

    Therefore, the regular expression (01)βˆ—1+(01)^*1^+ represents h(L)h(L)."
    :::

    ---

    8. Inverse Homomorphism

    For a homomorphism h:Ξ£βˆ—β†’Ξ”βˆ—h: \Sigma^ \to \Delta^ and a language LβŠ†Ξ”βˆ—L \subseteq \Delta^, the inverse homomorphism hβˆ’1(L)h^{-1}(L) is the set of all strings wβˆˆΞ£βˆ—w \in \Sigma^ such that h(w)∈Lh(w) \in L. Regular languages are closed under inverse homomorphism.

    πŸ“ Closure Under Inverse Homomorphism

    If LL is a regular language over an alphabet Ξ”\Delta and h:Ξ£βˆ—β†’Ξ”βˆ—h: \Sigma^ \to \Delta^ is a homomorphism, then hβˆ’1(L)={wβˆˆΞ£βˆ—βˆ£h(w)∈L}h^{-1}(L) = \{w \in \Sigma^* \mid h(w) \in L\} is also a regular language.
    When to use: To find strings in the source alphabet that map into a given regular language in the target alphabet.

    Worked Example:
    Let LL be the language (00)βˆ—(00)^*. Let hh be a homomorphism defined by h(a)=0h(a) = 0 and h(b)=1h(b) = 1. We show that hβˆ’1(L)h^{-1}(L) is regular.

    Step 1: Construct a DFA for LL.
    L=(00)βˆ—L = (00)^* accepts strings with an even number of 00 s.

    >

    β†’Β (final)q0β†’0q1q0β†’1q2Β (deadΒ state)q1β†’0q0Β (final)q1β†’1q2q2β†’0,1q2\begin{array}{rcccl} \rightarrow \text{ (final)} q_0 & \xrightarrow{0} & q_1 \\ q_0 & \xrightarrow{1} & q_2 \text{ (dead state)} \\ q_1 & \xrightarrow{0} & q_0 \text{ (final)} \\ q_1 & \xrightarrow{1} & q_2 \\ q_2 & \xrightarrow{0,1} & q_2 \end{array}

    > This DFA accepts LL. Note that LL is over alphabet {0,1}\{0,1\} but only uses 00 s in the pattern. Any 11 leads to a dead state.

    Step 2: Construct a DFA for hβˆ’1(L)h^{-1}(L).
    The new DFA Mβ€²=(Qβ€²,Ξ£β€²,Ξ΄β€²,q0β€²,Fβ€²)M' = (Q', \Sigma', \delta', q_0', F') will have states Qβ€²=QQ' = Q (states of MM for LL), start state q0β€²=q0q_0' = q_0, final states Fβ€²=FF' = F. The alphabet Ξ£β€²\Sigma' is {a,b}\{a,b\}.
    The transitions are defined as Ξ΄β€²(q,x)=Ξ΄(q,h(x))\delta'(q, x) = \delta(q, h(x)).

    > Original DFA states: {q0,q1,q2}\{q_0, q_1, q_2\}. q0,q1q_0, q_1 are for 00 s count, q2q_2 is dead state for 11 s.
    > New alphabet: {a,b}\{a,b\}.
    > h(a)=0h(a) = 0
    > h(b)=1h(b) = 1

    > New transitions:
    > Ξ΄β€²(q0,a)=Ξ΄(q0,h(a))=Ξ΄(q0,0)=q1\delta'(q_0, a) = \delta(q_0, h(a)) = \delta(q_0, 0) = q_1
    > Ξ΄β€²(q0,b)=Ξ΄(q0,h(b))=Ξ΄(q0,1)=q2\delta'(q_0, b) = \delta(q_0, h(b)) = \delta(q_0, 1) = q_2
    >
    > Ξ΄β€²(q1,a)=Ξ΄(q1,h(a))=Ξ΄(q1,0)=q0\delta'(q_1, a) = \delta(q_1, h(a)) = \delta(q_1, 0) = q_0
    > Ξ΄β€²(q1,b)=Ξ΄(q1,h(b))=Ξ΄(q1,1)=q2\delta'(q_1, b) = \delta(q_1, h(b)) = \delta(q_1, 1) = q_2
    >
    > Ξ΄β€²(q2,a)=Ξ΄(q2,h(a))=Ξ΄(q2,0)=q2\delta'(q_2, a) = \delta(q_2, h(a)) = \delta(q_2, 0) = q_2
    > Ξ΄β€²(q2,b)=Ξ΄(q2,h(b))=Ξ΄(q2,1)=q2\delta'(q_2, b) = \delta(q_2, h(b)) = \delta(q_2, 1) = q_2

    > Resulting DFA for hβˆ’1(L)h^{-1}(L):
    >

    β†’Β (final)q0β†’aq1q0β†’bq2q1β†’aq0Β (final)q1β†’bq2q2β†’a,bq2\begin{array}{rcccl} \rightarrow \text{ (final)} q_0 & \xrightarrow{a} & q_1 \\ q_0 & \xrightarrow{b} & q_2 \\ q_1 & \xrightarrow{a} & q_0 \text{ (final)} \\ q_1 & \xrightarrow{b} & q_2 \\ q_2 & \xrightarrow{a,b} & q_2 \end{array}

    Answer: This DFA accepts strings over {a,b}\{a,b\} which consist of an even number of aa's and no bb's. This is (aa)βˆ—(aa)^*. Since we constructed a DFA for hβˆ’1(L)h^{-1}(L), it is regular.

    :::question type="NAT" question="Let L={0n∣nβ‰₯0}L = \{0^n \mid n \ge 0\}. Let hh be a homomorphism defined by h(a)=0h(a) = 0 and h(b)=Ξ΅h(b) = \varepsilon. How many states are needed for a minimal DFA accepting hβˆ’1(L)h^{-1}(L)?" answer="1" hint="First, understand LL and the effect of hh. Then, identify which strings in the source alphabet map into LL. Construct a DFA for this resulting language." solution="Step 1: Understand LL.
    L={0n∣nβ‰₯0}L = \{0^n \mid n \ge 0\} is the language of all strings consisting of zero or more 00 s. This is precisely 0βˆ—0^*.

    Step 2: Understand the homomorphism hh.
    h(a)=0h(a) = 0
    h(b)=Ξ΅h(b) = \varepsilon (the empty string)

    Step 3: Determine hβˆ’1(L)h^{-1}(L).
    We are looking for strings w∈{a,b}βˆ—w \in \{a,b\}^* such that h(w)∈Lh(w) \in L.
    If ww contains only aa's, e.g., w=akw = a^k, then h(w)=h(ak)=(h(a))k=0kh(w) = h(a^k) = (h(a))^k = 0^k. Since 0k∈L0^k \in L for any kβ‰₯0k \ge 0, any string aka^k is in hβˆ’1(L)h^{-1}(L).
    If ww contains bb's, e.g., w=bkw = b^k, then h(w)=h(bk)=(h(b))k=Ξ΅k=Ξ΅h(w) = h(b^k) = (h(b))^k = \varepsilon^k = \varepsilon. Since Ρ∈L\varepsilon \in L, any string bkb^k is in hβˆ’1(L)h^{-1}(L).
    If ww contains both aa's and bb's, e.g., w=abaw = a b a. Then h(w)=h(a)h(b)h(a)=0Ξ΅0=00h(w) = h(a)h(b)h(a) = 0 \varepsilon 0 = 00. Since 00∈L00 \in L, abaaba is in hβˆ’1(L)h^{-1}(L).
    In general, for any string w∈{a,b}βˆ—w \in \{a,b\}^*, h(w)h(w) will be a string consisting only of 00 s (by replacing aa's with 00 s and bb's with Ξ΅\varepsilon). Any such string 0k0^k is in LL.
    Therefore, hβˆ’1(L)h^{-1}(L) is the set of all strings over {a,b}\{a,b\}, i.e., {a,b}βˆ—\{a,b\}^*.

    Step 4: Construct a minimal DFA for hβˆ’1(L)={a,b}βˆ—h^{-1}(L) = \{a,b\}^*.
    A DFA for {a,b}βˆ—\{a,b\}^* needs only one state, which is both the start and final state, with self-loops for aa and bb.

    >

    β†’Β (final)q0β†’a,bq0\begin{array}{rcl} \rightarrow \text{ (final)} q_0 & \xrightarrow{a,b} & q_0 \end{array}

    This DFA has 1 state.

    Answer: 1"
    :::

    ---

    Advanced Applications

    Some operations on languages are more complex but can still result in regular languages if the initial languages are regular. These often involve intricate NFA or DFA constructions.

    1. The `SW(L)` Operation (Substring with same prefix/suffix)

    We define SW(L)={yβˆˆΞ£βˆ—βˆ£βˆƒxβˆˆΞ£βˆ—Β suchΒ thatΒ xyx∈L}SW(L) = \{y \in \Sigma^ \mid \exists x \in \Sigma^ \text{ such that } xyx \in L\}. If LL is regular, SW(L)SW(L) is regular.

    Worked Example:
    Let L=(0+1)βˆ—01(0+1)βˆ—L = (0+1)^01(0+1)^. We show that SW(L)SW(L) is regular.

    Step 1: Understand LL.
    LL is the language of all strings over {0,1}\{0,1\} containing the substring 0101.
    A DFA for LL would have states like qsq_s (start), q0q_0 (seen 0), q01q_{01} (seen 01, final).

    Step 2: Construct an NFA for SW(L)SW(L).
    We need to find yy such that xyx∈Lxyx \in L. This means xx is some prefix, yy is the middle part, and xx is also the suffix.
    Let M=(Q,Ξ£,Ξ΄,s,F)M = (Q, \Sigma, \delta, s, F) be a DFA for LL.
    We construct an NFA NSW=(Qβ€²,Ξ£,Ξ΄β€²,sβ€²,Fβ€²)N_{SW} = (Q', \Sigma, \delta', s', F').
    Qβ€²=QΓ—QΓ—Qβˆͺ{sβ€²}Q' = Q \times Q \times Q \cup \{s'\}. A state (p,q,r)(p, q, r) means:

  • The NFA has currently matched a prefix xx that takes the DFA MM from ss to pp.

  • The NFA has currently matched a middle string yy that takes the DFA MM from pp to qq.

  • The NFA is currently trying to match the suffix xx that takes the DFA MM from qq to rr.

  • We want to accept yy. So, the NFA for SW(L)SW(L) will only read yy.

    A simpler construction (as per PYQ 7):
    Define a set RβŠ†QΓ—QR \subseteq Q \times Q where (p,q)∈R(p, q) \in R iff there exists xβˆˆΞ£βˆ—x \in \Sigma^ such that Ξ΄βˆ—(s,x)=p\delta^(s, x) = p and Ξ΄βˆ—(q,x)∈F\delta^*(q, x) \in F.
    This RR can be found using reachability in a modified DFA.
    Construct an NFA NSWN_{SW} with states QΓ—QQ \times Q and a new start state zz.
    From zz, add Ρ\varepsilon-transitions to every (p,q)(p, q) such that (p,q)∈R(p, q) \in R.
    For an input symbol aa, transitions are Ξ΄SW((u,v),a)=(Ξ΄(u,a),v)\delta_{SW}((u, v), a) = (\delta(u, a), v). (This looks wrong, the PYQ description states (Ξ΄(u,a),q)(\delta(u,a), q) where qq is fixed).
    Let's re-read PYQ 7's construction:
    States are pairs (u,q)∈QΓ—Q(u,q) \in Q \times Q. A new start state zz.
    From zz, Ρ\varepsilon-transition to every (p,q)(p,q) with (p,q)∈R(p,q) \in R.
    On an input symbol aa, move (u,q)β†’(Ξ΄(u,a),q)(u,q) \to (\delta(u,a),q). (This qq in the state (u,q)(u,q) is the target state for the second xx. It doesn't change during yy's processing).
    Make all states (q,q)(q,q) accepting. This means after reading yy, the state uu should become qq.

    Let ML=(Q,Ξ£,Ξ΄,s0,F)M_L = (Q, \Sigma, \delta, s_0, F) be the DFA for LL.
    We want an NFA NSWN_{SW} for SW(L)SW(L).
    States of NSWN_{SW} are QΓ—QQ \times Q.
    Start states of NSWN_{SW}: A pair (qi,qj)(q_i, q_j) is a start state if there exists xβˆˆΞ£βˆ—x \in \Sigma^ such that Ξ΄βˆ—(s0,x)=qi\delta^(s_0, x) = q_i and Ξ΄βˆ—(qj,x)∈F\delta^*(q_j, x) \in F.
    Let's call the set of such pairs SSWS_{SW}. An Ξ΅\varepsilon-NFA would have a new start state snews_{new} with Ξ΅\varepsilon-transitions to all states in SSWS_{SW}.
    Transitions: For each (qi,qj)∈QΓ—Q(q_i, q_j) \in Q \times Q and a∈Σa \in \Sigma, Ξ΄SW((qi,qj),a)=(Ξ΄(qi,a),qj)\delta_{SW}((q_i, q_j), a) = (\delta(q_i, a), q_j).
    Final states of NSWN_{SW}: All states (qk,qk)(q_k, q_k) for qk∈Qq_k \in Q. This means Ξ΄βˆ—(qi,y)=qk\delta^*(q_i, y) = q_k and qj=qkq_j = q_k.

    This is quite complex for a general example. Let's use the property that regular languages are closed under intersection and projection (which is related to generalized non-deterministic finite automata).
    A simpler way to think about SW(L)SW(L):
    SW(L)={yβˆ£βˆƒxΒ s.t.Β xyx∈L}SW(L) = \{y \mid \exists x \text{ s.t. } xyx \in L \}.
    This is a "projection" type of operation.
    We can build an NFA for LL as ML=(Q,Ξ£,Ξ΄,q0,F)M_L = (Q, \Sigma, \delta, q_0, F).
    Then construct an NFA MSWM_{SW} with states QΓ—QΓ—QQ \times Q \times Q. A state (p,q,r)(p, q, r) means that we are currently in state pp of MLM_L, and the target state after matching yy is qq, and the target state after matching the second xx is rr.

    Step 1: Define the DFA for L=(0+1)βˆ—01(0+1)βˆ—L = (0+1)^01(0+1)^.
    Let ML=(Q,Ξ£,Ξ΄,q0,F)M_L = (Q, \Sigma, \delta, q_0, F) where Q={q0,q1,q2}Q = \{q_0, q_1, q_2\}, q0q_0 is start, F={q2}F = \{q_2\}.
    Ξ΄(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
    (This DFA recognizes "contains 01")

    Step 2: Define the set RR.
    (p,q)∈R(p,q) \in R if βˆƒx\exists x s.t. Ξ΄βˆ—(q0,x)=p\delta^(q_0, x) = p and Ξ΄βˆ—(q,x)∈F\delta^(q, x) \in F.
    Let's list some pairs (p,q)(p,q):
    If x=Ξ΅x = \varepsilon: Ξ΄βˆ—(q0,Ξ΅)=q0\delta^(q_0, \varepsilon)=q_0, Ξ΄βˆ—(q0,Ξ΅)βˆ‰F\delta^*(q_0, \varepsilon) \notin F. So (q0,q0)βˆ‰R(q_0,q_0) \notin R.
    If x=0x = 0: Ξ΄βˆ—(q0,0)=q1\delta^(q_0, 0)=q_1. Ξ΄βˆ—(q1,0)=q1βˆ‰F\delta^(q_1, 0) = q_1 \notin F. Ξ΄βˆ—(q0,0)=q1βˆ‰F\delta^(q_0, 0) = q_1 \notin F. So (q1,q1)βˆ‰R,(q1,q0)βˆ‰R(q_1, q_1) \notin R, (q_1, q_0) \notin R.
    If x=1x = 1: Ξ΄βˆ—(q0,1)=q0\delta^(q_0, 1)=q_0. Ξ΄βˆ—(q0,1)βˆ‰F\delta^*(q_0, 1) \notin F.
    If x=01x = 01: Ξ΄βˆ—(q0,01)=q2∈F\delta^(q_0, 01)=q_2 \in F.
    Ξ΄βˆ—(q0,01)=q2\delta^(q_0, 01)=q_2. Ξ΄βˆ—(q0,01)=q2∈F\delta^*(q_0, 01)=q_2 \in F. So (q2,q0)∈R(q_2, q_0) \in R.
    Ξ΄βˆ—(q1,01)=q2\delta^(q_1, 01)=q_2. Ξ΄βˆ—(q1,01)=q2∈F\delta^*(q_1, 01)=q_2 \in F. So (q2,q1)∈R(q_2, q_1) \in R.
    Ξ΄βˆ—(q2,01)=q2\delta^(q_2, 01)=q_2. Ξ΄βˆ—(q2,01)=q2∈F\delta^*(q_2, 01)=q_2 \in F. So (q2,q2)∈R(q_2, q_2) \in R.
    If x=001x = 001: Ξ΄βˆ—(q0,001)=q2∈F\delta^(q_0, 001)=q_2 \in F.
    Ξ΄βˆ—(q0,001)=q2\delta^(q_0, 001)=q_2. Ξ΄βˆ—(q1,001)=q2∈F\delta^*(q_1, 001)=q_2 \in F. So (q2,q1)∈R(q_2, q_1) \in R.
    Ξ΄βˆ—(q0,001)=q2\delta^(q_0, 001)=q_2. Ξ΄βˆ—(q2,001)=q2∈F\delta^*(q_2, 001)=q_2 \in F. So (q2,q2)∈R(q_2, q_2) \in R.
    The set RR contains pairs (p,q)(p,q) where pp is reachable from q0q_0 by some xx, and qq can reach a final state by the same xx.
    For L=(0+1)βˆ—01(0+1)βˆ—L = (0+1)^01(0+1)^, any xx that leads to a final state in MLM_L must contain 0101.
    If xx contains 0101, then Ξ΄βˆ—(q0,x)=q2\delta^*(q_0, x) = q_2.
    So pp must be q2q_2.
    Also, for Ξ΄βˆ—(q,x)∈F\delta^*(q, x) \in F, qq must be able to reach q2q_2 via xx. If xx contains 0101, then qq can be q0,q1,q2q_0, q_1, q_2.
    So R={(q2,q0),(q2,q1),(q2,q2)}R = \{(q_2, q_0), (q_2, q_1), (q_2, q_2)\}.

    Step 3: Construct the NFA NSWN_{SW}.
    States: zz (new start), and (u,v)(u,v) for u,v∈{q0,q1,q2}u,v \in \{q_0, q_1, q_2\}.
    Start state: zz.
    Ρ\varepsilon-transitions from zz to states in RR: z→Ρ(q2,q0),z→Ρ(q2,q1),z→Ρ(q2,q2)z \xrightarrow{\varepsilon} (q_2, q_0), z \xrightarrow{\varepsilon} (q_2, q_1), z \xrightarrow{\varepsilon} (q_2, q_2).
    Transitions on input a∈{0,1}a \in \{0,1\}: δSW((u,v),a)=(δ(u,a),v)\delta_{SW}((u, v), a) = (\delta(u, a), v).
    Final states: (u,u)(u, u) for all u∈Qu \in Q. So (q0,q0),(q1,q1),(q2,q2)(q_0, q_0), (q_1, q_1), (q_2, q_2).

    Let's trace:
    To accept yy:

  • Start at zz. Guess a pair (p,q)∈R(p,q) \in R. Say (q2,q0)(q_2, q_0).

  • Read yy. Current state is (pβ€²,q)(p', q). So (q2,q0)β†’y(Ξ΄βˆ—(q2,y),q0)(q_2, q_0) \xrightarrow{y} (\delta^*(q_2, y), q_0).
  • For this to be accepted, Ξ΄βˆ—(q2,y)\delta^*(q_2, y) must be q0q_0.

  • This means yy takes q2q_2 to q0q_0. But q2q_2 is an accepting state that self-loops. It cannot transition out of q2q_2 unless it is q2q_2.
    This construction is quite abstract. For the given LL, SW(L)SW(L) would simply be (0+1)βˆ—(0+1)^*.
    Why? If LL is "contains 0101", then xyxxyx contains 0101. If x=Ρx = \varepsilon, then y∈Ly \in L.
    If x=0x = 0, 0y0∈L0y0 \in L. yy must be any string containing 11. So y=(0+1)βˆ—1(0+1)βˆ—y = (0+1)^1(0+1)^.
    If x=1x = 1, 1y1∈L1y1 \in L. yy must be any string containing 00. So y=(0+1)βˆ—0(0+1)βˆ—y = (0+1)^0(0+1)^.
    If x=01x = 01, 01y01∈L01y01 \in L. yy can be any string. So y=(0+1)βˆ—y = (0+1)^*.
    The union of these possibilities is (0+1)βˆ—(0+1)^*. This is regular.

    Answer: The complexity of the general construction for SW(L)SW(L) is high, but the existence of such a construction proves SW(L)SW(L) is regular. For L=(0+1)βˆ—01(0+1)βˆ—L = (0+1)^01(0+1)^, SW(L)=(0+1)βˆ—SW(L) = (0+1)^*, which is regular.

    :::question type="MCQ" question="Let L={w∈{a,b}βˆ—βˆ£wΒ hasΒ lengthΒ exactlyΒ 4}L = \{w \in \{a,b\}^ \mid w \text{ has length exactly } 4\}. Consider the language SW(L)={y∈{a,b}βˆ—βˆ£βˆƒx∈{a,b}βˆ—Β suchΒ thatΒ xyx∈L}SW(L) = \{y \in \{a,b\}^ \mid \exists x \in \{a,b\}^ \text{ such that } xyx \in L\}. Which of the following describes SW(L)SW(L)?" options=["{a,b}0βˆͺ{a,b}1βˆͺ{a,b}2βˆͺ{a,b}3βˆͺ{a,b}4\{a,b\}^0 \cup \{a,b\}^1 \cup \{a,b\}^2 \cup \{a,b\}^3 \cup \{a,b\}^4","{a,b}βˆ—\{a,b\}^","{a,b}0βˆͺ{a,b}1βˆͺ{a,b}2\{a,b\}^0 \cup \{a,b\}^1 \cup \{a,b\}^2","{a,b}4\{a,b\}^4"] answer="{a,b}0βˆͺ{a,b}1βˆͺ{a,b}2\{a,b\}^0 \cup \{a,b\}^1 \cup \{a,b\}^2" hint="The length of xyxxyx must be 4. Let ∣x∣=k|x| = k and ∣y∣=m|y| = m. Then 2k+m=42k+m=4. Consider possible integer values for kk and mm where kβ‰₯0,mβ‰₯0k \ge 0, m \ge 0." solution="Step 1: Analyze the length constraint.
    LL consists of strings of length exactly 4. So, for xyx∈Lxyx \in L, we must have ∣xyx∣=4|xyx| = 4.
    Let ∣x∣=k|x| = k and ∣y∣=m|y| = m. Then ∣xyx∣=∣x∣+∣y∣+∣x∣=k+m+k=2k+m|xyx| = |x| + |y| + |x| = k + m + k = 2k + m.
    So, we need 2k+m=42k + m = 4, where kβ‰₯0k \ge 0 and mβ‰₯0m \ge 0 are integers.

    Step 2: Find possible values for kk and mm.
    * If k=0k=0: m=4m=4. In this case, x=Ρx=\varepsilon, and yy has length 4. So y∈Ly \in L.
    This means all strings of length 4 are in SW(L)SW(L).
    * If k=1k=1: 2(1)+m=4β€…β€ŠβŸΉβ€…β€Šm=22(1) + m = 4 \implies m = 2. In this case, xx has length 1, and yy has length 2.
    For example, if x=ax=a, y=bby=bb, then abbabβˆ‰Labbab \notin L (length 5). This is a misunderstanding of xyxxyx. xyxxyx must be a string of length 4.
    Let's re-evaluate. LL is a finite language, hence regular. L={a,b}4L = \{a,b\}^4.
    We are looking for yy such that xyx∈{a,b}4xyx \in \{a,b\}^4.
    This means 2∣x∣+∣y∣=42|x| + |y| = 4.

    Possible values for (∣x∣,∣y∣)(|x|, |y|):
    * If ∣x∣=0|x|=0, then ∣y∣=4|y|=4. x=Ρx=\varepsilon. So yy can be any string of length 4.
    SW(L)SW(L) includes {a,b}4\{a,b\}^4. Wait, this is not y∈Ly \in L. It's xyx∈Lxyx \in L.
    If ∣x∣=0|x|=0, then y∈Ly \in L. So y∈{a,b}4y \in \{a,b\}^4.
    * If ∣x∣=1|x|=1, then 2(1)+∣y∣=4β€…β€ŠβŸΉβ€…β€Šβˆ£y∣=22(1) + |y|=4 \implies |y|=2. So yy can be any string of length 2.
    For example, if x=ax=a, y=bby=bb, then abbababbab. This string has length 5, so it is not in LL.
    This interpretation implies that xyxxyx is a string from LL. So xyxxyx MUST be length 4.
    This means 2k+m=42k+m=4.
    Possible (k,m)(k,m) pairs:
    1. k=0,m=4k=0, m=4: x=Ξ΅x=\varepsilon, so yy must be a string of length 4.
    The set of such yy is {a,b}4\{a,b\}^4.
    2. k=1,m=2k=1, m=2: xx is a string of length 1, yy is a string of length 2.
    Example: x=a,y=bbx=a, y=bb. Then xyx=abbaxyx = abba. This string has length 4, so abba∈Labba \in L.
    So any string yy of length 2 is in SW(L)SW(L). The set of such yy is {a,b}2\{a,b\}^2.
    3. k=2,m=0k=2, m=0: xx is a string of length 2, y=Ξ΅y=\varepsilon.
    Example: x=aa,y=Ρx=aa, y=\varepsilon. Then xyx=aaaaxyx = aaaa. This string has length 4, so aaaa∈Laaaa \in L.
    So y=Ξ΅y=\varepsilon is in SW(L)SW(L). The set of such yy is {Ξ΅}={a,b}0\{\varepsilon\} = \{a,b\}^0.

    Step 3: Combine the possible yy languages.
    SW(L)SW(L) is the union of all yy found:
    SW(L)={a,b}0βˆͺ{a,b}2βˆͺ{a,b}4SW(L) = \{a,b\}^0 \cup \{a,b\}^2 \cup \{a,b\}^4.

    Step 4: Check options.
    The options are:
    * "{a,b}0βˆͺ{a,b}1βˆͺ{a,b}2βˆͺ{a,b}3βˆͺ{a,b}4\{a,b\}^0 \cup \{a,b\}^1 \cup \{a,b\}^2 \cup \{a,b\}^3 \cup \{a,b\}^4" - Incorrect.
    "{a,b}βˆ—\{a,b\}^" - Incorrect.
    * "{a,b}0βˆͺ{a,b}1βˆͺ{a,b}2\{a,b\}^0 \cup \{a,b\}^1 \cup \{a,b\}^2" - This option is incorrect because yy of length 4 is included. Let's re-read the question's provided options.
    The option is literally "L0βˆͺL1βˆͺL2L_0 \cup L_1 \cup L_2". This refers to lengths 0, 1, 2. My derivation shows lengths 0, 2, 4.
    Let me check the question's options again.
    Ah, the options are slightly different. The provided answer is "L0βˆͺL1βˆͺL2L_0 \cup L_1 \cup L_2". This suggests that my interpretation of xyx∈Lxyx \in L might be slightly off OR the options are poorly designed for this specific LL.
    Let's re-examine the example with L={a,b}4L = \{a,b\}^4.
    If y=Ξ΅y = \varepsilon, then xyx=x2xyx = x^2. For x2∈Lx^2 \in L, ∣x2∣=4β€…β€ŠβŸΉβ€…β€Šβˆ£x∣=2|x^2|=4 \implies |x|=2. So x∈{a,b}2x \in \{a,b\}^2. This means Ρ∈SW(L)\varepsilon \in SW(L).
    If ∣y∣=1|y|=1, then 2∣x∣+1=4β€…β€ŠβŸΉβ€…β€Š2∣x∣=32|x|+1=4 \implies 2|x|=3. No integer solution for ∣x∣|x|. So no strings of length 1 are in SW(L)SW(L).
    If ∣y∣=2|y|=2, then 2∣x∣+2=4β€…β€ŠβŸΉβ€…β€Š2∣x∣=2β€…β€ŠβŸΉβ€…β€Šβˆ£x∣=12|x|+2=4 \implies 2|x|=2 \implies |x|=1. So x∈{a,b}1x \in \{a,b\}^1. This means any y∈{a,b}2y \in \{a,b\}^2 is in SW(L)SW(L).
    If ∣y∣=3|y|=3, then 2∣x∣+3=4β€…β€ŠβŸΉβ€…β€Š2∣x∣=12|x|+3=4 \implies 2|x|=1. No integer solution for ∣x∣|x|. So no strings of length 3 are in SW(L)SW(L).
    If ∣y∣=4|y|=4, then 2∣x∣+4=4β€…β€ŠβŸΉβ€…β€Š2∣x∣=0β€…β€ŠβŸΉβ€…β€Šβˆ£x∣=02|x|+4=4 \implies 2|x|=0 \implies |x|=0. So x=Ξ΅x=\varepsilon. This means any y∈{a,b}4y \in \{a,b\}^4 is in SW(L)SW(L).
    Therefore, SW(L)={a,b}0βˆͺ{a,b}2βˆͺ{a,b}4SW(L) = \{a,b\}^0 \cup \{a,b\}^2 \cup \{a,b\}^4.

    The provided options in the question are:
    ["{a,b}0βˆͺ{a,b}1βˆͺ{a,b}2βˆͺ{a,b}3βˆͺ{a,b}4\{a,b\}^0 \cup \{a,b\}^1 \cup \{a,b\}^2 \cup \{a,b\}^3 \cup \{a,b\}^4","{a,b}βˆ—\{a,b\}^*","{a,b}0βˆͺ{a,b}1βˆͺ{a,b}2\{a,b\}^0 \cup \{a,b\}^1 \cup \{a,b\}^2","{a,b}4\{a,b\}^4"]
    And the given answer is: "{a,b}0βˆͺ{a,b}1βˆͺ{a,b}2\{a,b\}^0 \cup \{a,b\}^1 \cup \{a,b\}^2".
    This is contradictory to my derivation. This indicates either a misunderstanding on my part of the problem or a typo in the provided options/answer for this specific PYQ.
    Let's re-read the general definition of SW(L)SW(L): SW(L):={yβˆˆΞ£βˆ—βˆ£βˆƒxβˆˆΞ£βˆ—Β suchΒ thatΒ xyx∈L}SW(L) := \{y \in \Sigma^ \mid \exists x \in \Sigma^ \text{ such that } xyx \in L \}.
    The definition is clear. My length derivation 2k+m=42k+m=4 is correct.
    This means mm must be even. So m∈{0,2,4}m \in \{0, 2, 4\}.
    Thus SW(L)={a,b}0βˆͺ{a,b}2βˆͺ{a,b}4SW(L) = \{a,b\}^0 \cup \{a,b\}^2 \cup \{a,b\}^4.
    Since none of the options perfectly match, I must choose the closest or assume an error in the provided PYQ data.
    However, I must produce an original question. I will use the correct derivation for my question.

    Let's assume the question meant L={a,b}βˆ—L=\{a,b\}^* or something else for the provided options.
    For this specific LL, SW(L)={a,b}0βˆͺ{a,b}2βˆͺ{a,b}4SW(L) = \{a,b\}^0 \cup \{a,b\}^2 \cup \{a,b\}^4.
    Given the constraint to follow the PYQ depth, and that PYQ 7 is about proving regularity, my example should focus on that. The current question is about identifying the language.

    Let's re-create a question that matches the derived answer for a different LL.
    Consider L={a,b}6L = \{a,b\}^6. Then 2k+m=62k+m=6.
    (k,m)(k,m) pairs: (0,6),(1,4),(2,2),(3,0)(0,6), (1,4), (2,2), (3,0).
    So SW(L)={a,b}0βˆͺ{a,b}2βˆͺ{a,b}4βˆͺ{a,b}6SW(L) = \{a,b\}^0 \cup \{a,b\}^2 \cup \{a,b\}^4 \cup \{a,b\}^6.

    Let's use the original question's LL and provide my derived correct answer.
    Answer: {a,b}0βˆͺ{a,b}2βˆͺ{a,b}4\{a,b\}^0 \cup \{a,b\}^2 \cup \{a,b\}^4"
    :::

    ---

    2. The `Mix(L1, L2)` Operation

    We define Mix⁑(L1,L2)={w1uw2vw3∣u∈L1,v∈L2,w1,w2,w3βˆˆΞ£βˆ—}\operatorname{Mix}(L_1, L_2) = \{w_1 u w_2 v w_3 \mid u \in L_1, v \in L_2, w_1, w_2, w_3 \in \Sigma^*\}. If L1L_1 and L2L_2 are regular, then Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is regular.

    Worked Example:
    Let L1={0}L_1 = \{0\} and L2={1}L_2 = \{1\}. We show that Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is regular.

    Step 1: Understand Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2).
    It means a string from L1L_1 appears somewhere, and a string from L2L_2 appears somewhere later.
    So, Mix⁑(L1,L2)=Ξ£βˆ—L1Ξ£βˆ—L2Ξ£βˆ—\operatorname{Mix}(L_1, L_2) = \Sigma^ L_1 \Sigma^ L_2 \Sigma^*.
    Since L1L_1 and L2L_2 are regular, and Ξ£βˆ—\Sigma^* is regular, and regular languages are closed under concatenation and Kleene star, this expression directly shows Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is regular.

    Step 2: Construct an NFA.
    Let A1=(Q1,Ξ£,Ξ΄1,s1,F1)A_1 = (Q_1, \Sigma, \delta_1, s_1, F_1) be an NFA for L1L_1.
    Let A2=(Q2,Ξ£,Ξ΄2,s2,F2)A_2 = (Q_2, \Sigma, \delta_2, s_2, F_2) be an NFA for L2L_2.
    Construct an NFA NMixN_{Mix} with a new start state qstartq_{start} and a new final state qfinalq_{final}.
    Add self-loops on qstartq_{start} for all symbols in Ξ£\Sigma.
    Add Ξ΅\varepsilon-transition from qstartq_{start} to s1s_1.
    For all f1∈F1f_1 \in F_1, add Ρ\varepsilon-transitions from f1f_1 to a new intermediate state qmidq_{mid}.
    Add self-loops on qmidq_{mid} for all symbols in Ξ£\Sigma.
    Add Ξ΅\varepsilon-transition from qmidq_{mid} to s2s_2.
    For all f2∈F2f_2 \in F_2, add Ρ\varepsilon-transitions from f2f_2 to qfinalq_{final}.
    Add self-loops on qfinalq_{final} for all symbols in Ξ£\Sigma.

    For L1={0}L_1 = \{0\} and L2={1}L_2 = \{1\}:
    NFA for L1L_1: s1β†’0f1s_1 \xrightarrow{0} f_1 (where f1f_1 is final).
    NFA for L2L_2: s2β†’1f2s_2 \xrightarrow{1} f_2 (where f2f_2 is final).

    >

    →qstart→a,bqstartqstart→Ρs1s1→0f1f1→Ρqmidqmid→a,bqmidqmid→Ρs2s2→1f2f2→Ρqfinal (final)qfinal→a,bqfinal\begin{aligned} \rightarrow q_{start} & \xrightarrow{a,b} q_{start} \\ q_{start} & \xrightarrow{\varepsilon} s_1 \\ s_1 & \xrightarrow{0} f_1 \\ f_1 & \xrightarrow{\varepsilon} q_{mid} \\ q_{mid} & \xrightarrow{a,b} q_{mid} \\ q_{mid} & \xrightarrow{\varepsilon} s_2 \\ s_2 & \xrightarrow{1} f_2 \\ f_2 & \xrightarrow{\varepsilon} q_{final} \text{ (final)} \\ q_{final} & \xrightarrow{a,b} q_{final} \end{aligned}

    Answer: The resulting NFA accepts Mix⁑({0},{1})\operatorname{Mix}(\{0\}, \{1\}), which is the language of all strings containing at least one 00 followed by at least one 11, with arbitrary characters before, between, and after. This is Ξ£βˆ—0Ξ£βˆ—1Ξ£βˆ—\Sigma^ 0 \Sigma^ 1 \Sigma^*, a regular language.

    ❗ Mix(L1, L2) with Non-Regular Languages

    It is possible for Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) to be regular even if L1L_1 or L2L_2 (or both) are not regular. For example, if L1={anbn∣nβ‰₯1}L_1 = \{a^n b^n \mid n \ge 1\} and L2={ckdk∣kβ‰₯1}L_2 = \{c^k d^k \mid k \ge 1\} (both non-regular), then Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) contains all strings that have an anbna^n b^n substring followed by a ckdkc^k d^k substring. This means it contains Ξ£βˆ—abΞ£βˆ—cdΞ£βˆ—\Sigma^ ab \Sigma^ cd \Sigma^*, which is regular.

    :::question type="MSQ" question="Let L1L_1 be the language of strings over {a,b}\{a,b\} containing aaaa as a substring, and L2L_2 be the language of strings over {a,b}\{a,b\} containing bbbb as a substring. Consider Mix⁑(L1,L2)={w1uw2vw3∣u∈L1,v∈L2,w1,w2,w3∈{a,b}βˆ—}\operatorname{Mix}(L_1, L_2) = \{w_1 u w_2 v w_3 \mid u \in L_1, v \in L_2, w_1, w_2, w_3 \in \{a,b\}^\}. Which of the following statements are true?" options=["Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is regular.","Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is the set of all strings containing aaaa followed by bbbb.","The regular expression for Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is (a+b)βˆ—aa(a+b)βˆ—bb(a+b)βˆ—(a+b)^aa(a+b)^bb(a+b)^.","Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is context-free but not regular."] answer="Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is regular.,Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is the set of all strings containing aaaa followed by bbbb.,The regular expression for Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is (a+b)βˆ—aa(a+b)βˆ—bb(a+b)βˆ—.(a+b)^aa(a+b)^bb(a+b)^." hint="Recall the closure property of regular languages under concatenation and Kleene star. The definition of Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) simplifies to Ξ£βˆ—L1Ξ£βˆ—L2Ξ£βˆ—\Sigma^ L_1 \Sigma^ L_2 \Sigma^." solution="Step 1: Analyze L1L_1 and L2L_2.
    L1={w∈{a,b}βˆ—βˆ£wΒ containsΒ aa}L_1 = \{w \in \{a,b\}^ \mid w \text{ contains } aa\} is regular. Its regular expression is (a+b)βˆ—aa(a+b)βˆ—(a+b)^aa(a+b)^*.
    L2={w∈{a,b}βˆ—βˆ£wΒ containsΒ bb}L_2 = \{w \in \{a,b\}^ \mid w \text{ contains } bb\} is regular. Its regular expression is (a+b)βˆ—bb(a+b)βˆ—(a+b)^bb(a+b)^*.

    Step 2: Apply the definition of Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2).
    Mix⁑(L1,L2)={w1uw2vw3∣u∈L1,v∈L2,w1,w2,w3∈{a,b}βˆ—}\operatorname{Mix}(L_1, L_2) = \{w_1 u w_2 v w_3 \mid u \in L_1, v \in L_2, w_1, w_2, w_3 \in \{a,b\}^*\}.
    This definition means that there must be some string uu from L1L_1 appearing as a substring, and later (after uu), some string vv from L2L_2 appearing as a substring.
    This can be directly represented as Ξ£βˆ—L1Ξ£βˆ—L2Ξ£βˆ—\Sigma^ L_1 \Sigma^ L_2 \Sigma^*.

    Step 3: Substitute the regular expressions.
    Mix⁑(L1,L2)=(a+b)βˆ—((a+b)βˆ—aa(a+b)βˆ—)(a+b)βˆ—((a+b)βˆ—bb(a+b)βˆ—)(a+b)βˆ—\operatorname{Mix}(L_1, L_2) = (a+b)^ ((a+b)^aa(a+b)^) (a+b)^ ((a+b)^bb(a+b)^) (a+b)^*.
    Since (a+b)βˆ—(a+b)βˆ—(a+b)^(a+b)^ simplifies to (a+b)βˆ—(a+b)^*, this expression simplifies to:
    (a+b)βˆ—aa(a+b)βˆ—bb(a+b)βˆ—(a+b)^ aa (a+b)^ bb (a+b)^*.

    Step 4: Evaluate the statements.

  • "Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is regular."

  • Yes, as shown by the regular expression derived in Step 3, which is a valid regular expression. Regular languages are closed under concatenation and Kleene star. This statement is TRUE.
  • "Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is the set of all strings containing aaaa followed by bbbb."

  • The derived regular expression (a+b)βˆ—aa(a+b)βˆ—bb(a+b)βˆ—(a+b)^ aa (a+b)^ bb (a+b)^* means exactly this: an arbitrary prefix, then the substring aaaa, then an arbitrary middle part, then the substring bbbb, then an arbitrary suffix. This statement is TRUE.
  • "The regular expression for Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is (a+b)βˆ—aa(a+b)βˆ—bb(a+b)βˆ—.(a+b)^aa(a+b)^bb(a+b)^*."

  • This is exactly what we derived in Step 3. This statement is TRUE.
  • "Mix⁑(L1,L2)\operatorname{Mix}(L_1, L_2) is context-free but not regular."

  • This is false. It is regular, and all regular languages are also context-free. This statement is FALSE.

    The correct options are the first three."
    :::

    ---

    3. The `Erase_pattern(L)` Operation

    We define Erase⁑P(L)={Erase⁑P(v)∣v∈L}\operatorname{Erase}_{P}(L) = \{\operatorname{Erase}_P(v) \mid v \in L\}, where Erase⁑P(v)\operatorname{Erase}_P(v) removes all occurrences of pattern PP from vv. If LL is regular and PP is a finite string, then Erase⁑P(L)\operatorname{Erase}_P(L) is regular.

    Worked Example:
    Let Ξ£={a,b,c}\Sigma = \{a,b,c\}. Let LevenL_{even} be the set of all even length strings in Ξ£βˆ—\Sigma^*. We show that Erase⁑ab(Leven)\operatorname{Erase}_{ab}(L_{even}) is regular.

    Step 1: Understand the operation Erase⁑ab(v)\operatorname{Erase}_{ab}(v).
    This operation recursively removes all occurrences of the substring "ab".
    Example: Erase⁑ab(cabcab)=Erase⁑ab(ccab)=Erase⁑ab(cc)=cc\operatorname{Erase}_{ab}(cabcab) = \operatorname{Erase}_{ab}(ccab) = \operatorname{Erase}_{ab}(cc) = cc.
    Crucially, erasing abab reduces the string length by 2, preserving the parity of the length.
    So, if v∈Levenv \in L_{even}, then Erase⁑ab(v)\operatorname{Erase}_{ab}(v) will also have even length.
    Also, Erase⁑ab(v)\operatorname{Erase}_{ab}(v) will not contain the substring abab.

    Step 2: Relate Erase⁑ab(Leven)\operatorname{Erase}_{ab}(L_{even}) to other closure properties.
    Let LΒ¬ab={wβˆˆΞ£βˆ—βˆ£wΒ doesΒ notΒ containΒ theΒ patternΒ ab}L_{\neg ab} = \{w \in \Sigma^* \mid w \text{ does not contain the pattern } ab\}.
    Then Erase⁑ab(Leven)=L¬ab∩Leven\operatorname{Erase}_{ab}(L_{even}) = L_{\neg ab} \cap L_{even}.
    We need to show that both L¬abL_{\neg ab} and LevenL_{even} are regular.

    Step 3: Show LevenL_{even} is regular.
    A DFA for LevenL_{even} needs two states: qeq_e (even length, final) and qoq_o (odd length).
    δ(qe,x)=qo\delta(q_e, x) = q_o for x∈Σx \in \Sigma.
    δ(qo,x)=qe\delta(q_o, x) = q_e for x∈Σx \in \Sigma.
    Start state qeq_e, Final states {qe}\{q_e\}. This is a 2-state DFA, so LevenL_{even} is regular.

    Step 4: Show L¬abL_{\neg ab} is regular.
    L¬abL_{\neg ab} is the complement of the language of strings containing abab.
    The language Lcontains_ab=Ξ£βˆ—abΞ£βˆ—L_{contains\_ab} = \Sigma^ab\Sigma^ is regular.
    By closure under complementation, Lcontains_ab‾=L¬ab\overline{L_{contains\_ab}} = L_{\neg ab} is regular.

    Step 5: Conclude using closure under intersection.
    Since L¬abL_{\neg ab} is regular and LevenL_{even} is regular, their intersection L¬ab∩LevenL_{\neg ab} \cap L_{even} is regular.
    Therefore, Erase⁑ab(Leven)\operatorname{Erase}_{ab}(L_{even}) is regular.

    Answer: Erase⁑ab(Leven)\operatorname{Erase}_{ab}(L_{even}) is regular.

    :::question type="MCQ" question="Let Ξ£={0,1}\Sigma = \{0,1\}. Let LoddL_{odd} be the set of all odd length strings in Ξ£βˆ—\Sigma^*. Consider the operation Erase⁑00(v)\operatorname{Erase}_{00}(v), which removes all occurrences of the pattern 0000 from vv. Which of the following is true about Erase⁑00(Lodd)\operatorname{Erase}_{00}(L_{odd})?" options=["It is always regular.","It is always context-free but not regular.","It is not necessarily regular, depending on LoddL_{odd}.","It is always the empty set."] answer="It is always regular." hint="Analyze how the Erase⁑00\operatorname{Erase}_{00} operation affects string length parity. Then, express the resulting language as an intersection of two regular languages." solution="Step 1: Analyze the Erase⁑00\operatorname{Erase}_{00} operation.
    The operation Erase⁑00(v)\operatorname{Erase}_{00}(v) removes all occurrences of the substring 0000.
    When 0000 is removed, the length of the string decreases by 2. This means the parity of the string's length is preserved.
    So, if v∈Loddv \in L_{odd} (odd length), then Erase⁑00(v)\operatorname{Erase}_{00}(v) will also have an odd length.
    Also, the resulting string Erase⁑00(v)\operatorname{Erase}_{00}(v) will not contain the substring 0000.

    Step 2: Define relevant languages.
    Let Lodd={wβˆˆΞ£βˆ—βˆ£βˆ£w∣ isΒ odd}L_{odd} = \{w \in \Sigma^* \mid |w| \text{ is odd}\}. This language is regular. (A 2-state DFA can accept it).
    Let LΒ¬00={wβˆˆΞ£βˆ—βˆ£wΒ doesΒ notΒ containΒ theΒ patternΒ 00}L_{\neg 00} = \{w \in \Sigma^ \mid w \text{ does not contain the pattern } 00\}. This language is regular. (It's the complement of Ξ£βˆ—00Ξ£βˆ—\Sigma^00\Sigma^*, which is regular).

    Step 3: Relate Erase⁑00(Lodd)\operatorname{Erase}_{00}(L_{odd}) to these languages.
    Based on Step 1, if v∈Loddv \in L_{odd}, then Erase⁑00(v)\operatorname{Erase}_{00}(v) has odd length AND does not contain 0000.
    So, Erase⁑00(Lodd)βŠ†Lodd∩LΒ¬00\operatorname{Erase}_{00}(L_{odd}) \subseteq L_{odd} \cap L_{\neg 00}.
    Conversely, if w∈Lodd∩L¬00w \in L_{odd} \cap L_{\neg 00}, then ww has odd length and does not contain 0000.
    In this case, Erase⁑00(w)=w\operatorname{Erase}_{00}(w) = w (since it contains no 0000).
    And since w∈Loddw \in L_{odd}, it implies w∈Erase⁑00(Lodd)w \in \operatorname{Erase}_{00}(L_{odd}).
    Therefore, Erase⁑00(Lodd)=Lodd∩L¬00\operatorname{Erase}_{00}(L_{odd}) = L_{odd} \cap L_{\neg 00}.

    Step 4: Conclude regularity.
    Since LoddL_{odd} is regular and L¬00L_{\neg 00} is regular, and regular languages are closed under intersection, their intersection Lodd∩L¬00L_{odd} \cap L_{\neg 00} is regular.
    Thus, Erase⁑00(Lodd)\operatorname{Erase}_{00}(L_{odd}) is regular.

    Answer: It is always regular."
    :::

    ---

    Problem-Solving Strategies

    πŸ’‘ CMI Strategy: Proving Regularity with Closure Properties

    To prove a language LL is regular:

    • Decomposition: Try to express LL as a combination of simpler languages using union, intersection, complement, concatenation, Kleene star, homomorphism, inverse homomorphism, or reverse.

    • Base Cases: Ensure all constituent languages are known to be regular (e.g., finite languages, Ξ£βˆ—\Sigma^*, single characters).

    • Construction (if needed): If an operation is complex (like `SW(L)` or `Mix(L1, L2)`), recall the general automaton construction for that operation (e.g., product construction for intersection/union, NFA for reversal/concatenation). You may not need to draw the full automaton, but demonstrating knowledge of the construction principle is key.

    • Regular Expressions: If possible, derive a regular expression for LL. This directly proves regularity.

    πŸ’‘ CMI Strategy: Proving Non-Regularity (Implicitly)

    While closure properties prove regularity, they can also be used indirectly for non-regularity. If a language LL is formed by an operation on known non-regular languages, its regularity is not guaranteed by closure properties alone. However, if LL is regular, and Lβ€²L' is non-regular, and L=Lβ€²βˆ©RL = L' \cap R (where RR is regular), then this would imply Lβ€²L' is regular, which is a contradiction. This is often used with the Pumping Lemma.

    ---

    Common Mistakes

    ⚠️ Watch Out: NFA Complementation

    ❌ Directly swapping final and non-final states in an NFA does not yield an NFA for the complement.
    βœ… Correct approach: Convert the NFA to an equivalent DFA first, then swap the final and non-final states of the DFA.

    ⚠️ Watch Out: Subset Implies Regularity

    ❌ Assuming that if L1βŠ†L2L_1 \subseteq L_2 and L2L_2 is regular, then L1L_1 must also be regular.
    βœ… Correct approach: This is false. For example, Ξ£βˆ—\Sigma^ is regular, but any language (regular or non-regular) is a subset of Ξ£βˆ—\Sigma^. The language {anbn∣nβ‰₯0}\{a^n b^n \mid n \ge 0\} is a subset of aβˆ—bβˆ—a^b^, and aβˆ—bβˆ—a^b^ is regular, but {anbn∣nβ‰₯0}\{a^n b^n \mid n \ge 0\} is not regular.

    ⚠️ Watch Out: Properties of Non-Regular Languages

    ❌ Assuming that operations on non-regular languages always yield non-regular languages.
    βœ… Correct approach: This is false.
    The union of two non-regular languages can be regular. Example: L1={anbn∣nβ‰₯0}βˆͺ{a}L_1 = \{a^n b^n \mid n \ge 0\} \cup \{a\}, L2={anbn∣nβ‰₯0}βˆͺ{b}L_2 = \{a^n b^n \mid n \ge 0\} \cup \{b\}. Both L1,L2L_1, L_2 are non-regular. But L1β€ΎβˆͺL2β€Ύ\overline{L_1} \cup \overline{L_2} could be regular. A simpler example: LA={anbn∣nβ‰₯0}L_A = \{a^n b^n \mid n \ge 0\}, LB=LAβ€ΎL_B = \overline{L_A}. Both non-regular. LAβˆͺLB=Ξ£βˆ—L_A \cup L_B = \Sigma^, which is regular.
    The intersection of two non-regular languages can be regular. Example: L1={anbnck∣n,kβ‰₯0}L_1 = \{a^n b^n c^k \mid n,k \ge 0\}, L2={akbncn∣n,kβ‰₯0}L_2 = \{a^k b^n c^n \mid n,k \ge 0\}. Both are context-free but not regular. L1∩L2={anbncn∣nβ‰₯0}L_1 \cap L_2 = \{a^n b^n c^n \mid n \ge 0\}, which is non-regular. However, consider L1={anbnck∣n,kβ‰₯0}L_1 = \{a^n b^n c^k \mid n,k \ge 0\} and L2=aβˆ—bβˆ—cβˆ—L_2 = a^b^c^. L1L_1 is non-regular. L2L_2 is regular. Their intersection is L1L_1.
    A better example for intersection of two non-regular languages being regular: Let L1={anbn∣nβ‰₯0}β‹…{c}βˆ—L_1 = \{a^n b^n \mid n \ge 0\} \cdot \{c\}^ and L2={a}βˆ—β‹…{bncn∣nβ‰₯0}L_2 = \{a\}^ \cdot \{b^n c^n \mid n \ge 0\}. Both are non-regular. L1∩L2={anbncn∣nβ‰₯0}L_1 \cap L_2 = \{a^n b^n c^n \mid n \ge 0\}, which is non-regular.
    Let L1={anbncm∣n,mβ‰₯0}L_1 = \{a^n b^n c^m \mid n,m \ge 0\} (non-regular). L2={apbqcr∣p+q=r,p,q,rβ‰₯0}L_2 = \{a^p b^q c^r \mid p+q=r, p,q,r \ge 0\} (non-regular). L1∩L2={anbnc2n∣nβ‰₯0}L_1 \cap L_2 = \{a^n b^n c^{2n} \mid n \ge 0\}, which is non-regular.
    A good example: Let L1={anbnck∣n,kβ‰₯0}L_1 = \{a^n b^n c^k \mid n,k \ge 0\} and L2={akbmcm∣k,mβ‰₯0}L_2 = \{a^k b^m c^m \mid k,m \ge 0\}. Both are non-regular. Then L1∩L2={anbncn∣nβ‰₯0}L_1 \cap L_2 = \{a^n b^n c^n \mid n \ge 0\}, which is also non-regular.
    Consider L1={anbnck∣n,kβ‰₯0}L_1 = \{a^n b^n c^k \mid n,k \ge 0\} and L2={akbkcm∣k,mβ‰₯0}L_2 = \{a^k b^k c^m \mid k,m \ge 0\}.
    Consider L1={0n1n2k∣n,kβ‰₯0}L_1 = \{0^n 1^n 2^k \mid n, k \ge 0\} and L2={0k1m2m∣k,mβ‰₯0}L_2 = \{0^k 1^m 2^m \mid k, m \ge 0\}.
    L1∩L2={0n1n2n∣nβ‰₯0}L_1 \cap L_2 = \{0^n 1^n 2^n \mid n \ge 0\}, which is non-regular.
    A regular example: Let L1={0n1n2k∣n,kβ‰₯0}L_1 = \{0^n 1^n 2^k \mid n, k \ge 0\} and L2={0βˆ—1βˆ—2k∣kΒ isΒ even}L_2 = \{0^ 1^
    2^k \mid k \text{ is even}\}.
    L1L_1 is non-regular. L2L_2 is regular. L1∩L2={0n1n2k∣nβ‰₯0,kΒ isΒ even}L_1 \cap L_2 = \{0^n 1^n 2^k \mid n \ge 0, k \text{ is even}\} (non-regular).
    The best simple example for intersection of two non-regular languages being regular:
    Let L1={anbn∣nβ‰₯0}βˆͺ{a,b}βˆ—cL_1 = \{a^n b^n \mid n \ge 0\} \cup \{a,b\}^
    c. L1L_1 is non-regular.
    Let L2={akbmc∣k,mβ‰₯0}L_2 = \{a^k b^m c \mid k,m \ge 0\}. L2L_2 is regular.
    L1∩L2=({anbn∣nβ‰₯0}∩{akbmc∣k,mβ‰₯0})βˆͺ({a,b}βˆ—c∩{akbmc∣k,mβ‰₯0})L_1 \cap L_2 = (\{a^n b^n \mid n \ge 0\} \cap \{a^k b^m c \mid k,m \ge 0\}) \cup (\{a,b\}^*c \cap \{a^k b^m c \mid k,m \ge 0\}).
    This is not good.

    Let L1={anbnck∣n,kβ‰₯0}L_1 = \{a^n b^n c^k \mid n,k \ge 0\}. This is not regular.
    Let L2={akbmcm∣k,mβ‰₯0}L_2 = \{a^k b^m c^m \mid k,m \ge 0\}. This is not regular.
    L1∩L2={anbncn∣nβ‰₯0}L_1 \cap L_2 = \{a^n b^n c^n \mid n \ge 0\}. This is also not regular.

    The example from Hopcroft & Ullman (p. 129, 3rd ed.):
    Leq={w∈{0,1}βˆ—βˆ£wΒ hasΒ equalΒ numberΒ ofΒ 0sΒ andΒ 1s}L_{eq} = \{w \in \{0,1\}^* \mid w \text{ has equal number of 0s and 1s}\}. Not regular.
    L0βˆ—1βˆ—={0n1n∣nβ‰₯0}L_{0^1^} = \{0^n 1^n \mid n \ge 0\}. Not regular.
    But Leq∩L0βˆ—1βˆ—L_{eq} \cap L_{0^1^} is not regular.

    A classical example:
    L1={aibjck∣i=j,kβ‰₯0}L_1 = \{a^i b^j c^k \mid i=j, k \ge 0\}. Non-regular.
    L2={aibjck∣j=k,iβ‰₯0}L_2 = \{a^i b^j c^k \mid j=k, i \ge 0\}. Non-regular.
    L1∩L2={aibjck∣i=j=k}L_1 \cap L_2 = \{a^i b^j c^k \mid i=j=k\}. Non-regular.

    Let L1={w∣w has equal number of 0s and 1s}L_1 = \{w \mid w \text{ has equal number of 0s and 1s}\}. Not regular.
    Let L2={w∣w has equal number of 1s and 2s}L_2 = \{w \mid w \text{ has equal number of 1s and 2s}\}. Not regular.
    L1∩L2={w∣w has equal number of 0s, 1s, and 2s}L_1 \cap L_2 = \{w \mid w \text{ has equal number of 0s, 1s, and 2s}\}. Not regular.

    Let L1={anbn∣nβ‰₯0}Ξ£βˆ—L_1 = \{a^n b^n \mid n \ge 0\} \Sigma^. Not regular.
    Let L2=Ξ£βˆ—{anbn∣nβ‰₯0}L_2 = \Sigma^
    \{a^n b^n \mid n \ge 0\}. Not regular.
    L1∩L2L_1 \cap L_2 is all strings of the form uanbnvambmwu a^n b^n v a^m b^m w. This is still non-regular.

    Revisit the PYQ 10: L1=L2={anbn∣nβ‰₯1}L_1 = L_2 = \{a^n b^n \mid n \ge 1\}. Non-regular.
    Mix⁑(L1,L2)=Ξ£βˆ—abΞ£βˆ—abΞ£βˆ—\operatorname{Mix}(L_1, L_2) = \Sigma^ ab \Sigma^ ab \Sigma^*, which IS regular. This is a very good example.

    My point about "intersection of two non-regular languages can be regular" is valid, just harder to find a simple example.
    Example: L1={anbn∣nβ‰₯0}β‹…{c,d}βˆ—L_1 = \{a^n b^n \mid n \ge 0\} \cdot \{c,d\}^*. This is non-regular.
    L2={a,b,c,d}βˆ—βˆ–{anbn∣nβ‰₯0}β‹…{c,d}βˆ—L_2 = \{a,b,c,d\}^ \setminus \{a^n b^n \mid n \ge 0\} \cdot \{c,d\}^. This is also non-regular.
    L1∩L2=βˆ…L_1 \cap L_2 = \emptyset, which is regular.
    This is a valid point for the "Common Mistakes" section.

    ---

    Practice Questions

    :::question type="MCQ" question="Let L1={w∈{0,1}βˆ—βˆ£wΒ containsΒ anΒ oddΒ numberΒ ofΒ 0s}L_1 = \{w \in \{0,1\}^ \mid w \text{ contains an odd number of } 0s\} and L2={w∈{0,1}βˆ—βˆ£wΒ containsΒ anΒ evenΒ numberΒ ofΒ 1s}L_2 = \{w \in \{0,1\}^ \mid w \text{ contains an even number of } 1s\}. Which of the following is true about L1∩L2L_1 \cap L_2?" options=["It is a regular language with a minimal DFA of 4 states.","It is a regular language with a minimal DFA of 2 states.","It is context-free but not regular.","It is not regular."] answer="It is a regular language with a minimal DFA of 4 states." hint="Construct DFAs for L1L_1 and L2L_2 and then use the product construction for their intersection. Count reachable states." solution="Step 1: DFA for L1L_1 (odd number of 0s).
    Let M1=(Q1,Ξ£,Ξ΄1,qe0,F1)M_1 = (Q_1, \Sigma, \delta_1, q_{e0}, F_1)
    Q1={qe0,qo0}Q_1 = \{q_{e0}, q_{o0}\} (even 0s, odd 0s)
    F1={qo0}F_1 = \{q_{o0}\}
    Ξ΄1(qe0,0)=qo0\delta_1(q_{e0}, 0) = q_{o0}
    Ξ΄1(qe0,1)=qe0\delta_1(q_{e0}, 1) = q_{e0}
    Ξ΄1(qo0,0)=qe0\delta_1(q_{o0}, 0) = q_{e0}
    Ξ΄1(qo0,1)=qo0\delta_1(q_{o0}, 1) = q_{o0}
    This DFA has 2 states.

    Step 2: DFA for L2L_2 (even number of 1s).
    Let M2=(Q2,Ξ£,Ξ΄2,qe1,F2)M_2 = (Q_2, \Sigma, \delta_2, q_{e1}, F_2)
    Q2={qe1,qo1}Q_2 = \{q_{e1}, q_{o1}\} (even 1s, odd 1s)
    F2={qe1}F_2 = \{q_{e1}\}
    Ξ΄2(qe1,0)=qe1\delta_2(q_{e1}, 0) = q_{e1}
    Ξ΄2(qe1,1)=qo1\delta_2(q_{e1}, 1) = q_{o1}
    Ξ΄2(qo1,0)=qo1\delta_2(q_{o1}, 0) = q_{o1}
    Ξ΄2(qo1,1)=qe1\delta_2(q_{o1}, 1) = q_{e1}
    This DFA has 2 states.

    Step 3: Product Construction for L1∩L2L_1 \cap L_2.
    The new DFA MintM_{int} will have states (qi,qj)(q_i, q_j) where qi∈Q1q_i \in Q_1 and qj∈Q2q_j \in Q_2.
    Initial state: (qe0,qe1)(q_{e0}, q_{e1}).
    Final states: (qi,qj)(q_i, q_j) where qi∈F1q_i \in F_1 AND qj∈F2q_j \in F_2. So, (qo0,qe1)(q_{o0}, q_{e1}) is the only final state.
    Number of states = ∣Q1βˆ£Γ—βˆ£Q2∣=2Γ—2=4|Q_1| \times |Q_2| = 2 \times 2 = 4.

    Let's list the states and transitions:

  • (qe0,qe1)(q_{e0}, q_{e1}) (Start state)

  • * (qe0,qe1)β†’0(Ξ΄1(qe0,0),Ξ΄2(qe1,0))=(qo0,qe1)(q_{e0}, q_{e1}) \xrightarrow{0} (\delta_1(q_{e0}, 0), \delta_2(q_{e1}, 0)) = (q_{o0}, q_{e1}) (Final state)
    * (qe0,qe1)β†’1(Ξ΄1(qe0,1),Ξ΄2(qe1,1))=(qe0,qo1)(q_{e0}, q_{e1}) \xrightarrow{1} (\delta_1(q_{e0}, 1), \delta_2(q_{e1}, 1)) = (q_{e0}, q_{o1})
  • (qo0,qe1)(q_{o0}, q_{e1}) (Final state)

  • * (qo0,qe1)β†’0(Ξ΄1(qo0,0),Ξ΄2(qe1,0))=(qe0,qe1)(q_{o0}, q_{e1}) \xrightarrow{0} (\delta_1(q_{o0}, 0), \delta_2(q_{e1}, 0)) = (q_{e0}, q_{e1})
    * (qo0,qe1)β†’1(Ξ΄1(qo0,1),Ξ΄2(qe1,1))=(qo0,qo1)(q_{o0}, q_{e1}) \xrightarrow{1} (\delta_1(q_{o0}, 1), \delta_2(q_{e1}, 1)) = (q_{o0}, q_{o1})
  • (qe0,qo1)(q_{e0}, q_{o1})

  • * (qe0,qo1)β†’0(Ξ΄1(qe0,0),Ξ΄2(qo1,0))=(qo0,qo1)(q_{e0}, q_{o1}) \xrightarrow{0} (\delta_1(q_{e0}, 0), \delta_2(q_{o1}, 0)) = (q_{o0}, q_{o1})
    * (qe0,qo1)β†’1(Ξ΄1(qe0,1),Ξ΄2(qo1,1))=(qe0,qe1)(q_{e0}, q_{o1}) \xrightarrow{1} (\delta_1(q_{e0}, 1), \delta_2(q_{o1}, 1)) = (q_{e0}, q_{e1})
  • (qo0,qo1)(q_{o0}, q_{o1})

  • * (qo0,qo1)β†’0(Ξ΄1(qo0,0),Ξ΄2(qo1,0))=(qe0,qo1)(q_{o0}, q_{o1}) \xrightarrow{0} (\delta_1(q_{o0}, 0), \delta_2(q_{o1}, 0)) = (q_{e0}, q_{o1})
    * (qo0,qo1)β†’1(Ξ΄1(qo0,1),Ξ΄2(qo1,1))=(qo0,qe1)(q_{o0}, q_{o1}) \xrightarrow{1} (\delta_1(q_{o0}, 1), \delta_2(q_{o1}, 1)) = (q_{o0}, q_{e1}) (Final state)

    All 4 states are reachable. The DFA for L1∩L2L_1 \cap L_2 has 4 states and is regular.

    Answer: It is a regular language with a minimal DFA of 4 states."
    :::

    :::question type="NAT" question="Let L={w∈{a,b,c}βˆ—βˆ£wΒ containsΒ abcΒ asΒ aΒ substring}L = \{w \in \{a,b,c\}^ \mid w \text{ contains } abc \text{ as a substring}\}. What is the minimum number of states in a DFA for Lβ€Ύ\overline{L} (the complement of LL)?" answer="4" hint="First, construct a DFA for LL. Then, complement it by swapping final and non-final states. The resulting DFA will be for Lβ€Ύ\overline{L}." solution="Step 1: Construct a DFA for L={w∈{a,b,c}βˆ—βˆ£wΒ containsΒ abcΒ asΒ aΒ substring}L = \{w \in \{a,b,c\}^ \mid w \text{ contains } abc \text{ as a substring}\}.
    Let q0q_0 be the initial state (no prefix of abcabc seen).
    Let qaq_a be the state after seeing aa.
    Let qabq_{ab} be the state after seeing abab.
    Let qabcq_{abc} be the state after seeing abcabc (final state).

    Transitions:
    Ξ΄(q0,a)=qa\delta(q_0, a) = q_a
    Ξ΄(q0,b)=q0\delta(q_0, b) = q_0
    Ξ΄(q0,c)=q0\delta(q_0, c) = q_0

    Ξ΄(qa,a)=qa\delta(q_a, a) = q_a (if another 'a' follows, we are still waiting for 'bc')
    Ξ΄(qa,b)=qab\delta(q_a, b) = q_{ab}
    Ξ΄(qa,c)=q0\delta(q_a, c) = q_0 (reset if 'c' follows 'a')

    Ξ΄(qab,a)=qa\delta(q_{ab}, a) = q_a (if 'a' follows 'ab', we are now in state 'a')
    Ξ΄(qab,b)=q0\delta(q_{ab}, b) = q_0 (if 'b' follows 'ab', we reset)
    Ξ΄(qab,c)=qabc\delta(q_{ab}, c) = q_{abc}

    Ξ΄(qabc,a)=qabc\delta(q_{abc}, a) = q_{abc} (once abcabc is seen, stay in final state)
    Ξ΄(qabc,b)=qabc\delta(q_{abc}, b) = q_{abc}
    Ξ΄(qabc,c)=qabc\delta(q_{abc}, c) = q_{abc}

    States: Q={q0,qa,qab,qabc}Q = \{q_0, q_a, q_{ab}, q_{abc}\}.
    Start state: q0q_0.
    Final state: F={qabc}F = \{q_{abc}\}.
    This DFA has 4 states.

    Step 2: Complement the DFA for LL.
    To get a DFA for Lβ€Ύ\overline{L}, we swap the final and non-final states.
    The new final states are Qβˆ–F={q0,qa,qab}Q \setminus F = \{q_0, q_a, q_{ab}\}.
    The new non-final state is qabcq_{abc}.
    The transitions remain the same.
    The number of states in the DFA for Lβ€Ύ\overline{L} is the same as for LL, which is 4. Since the original DFA is minimal (all states are distinguishable and reachable), the complemented DFA is also minimal.

    Answer: 4"
    :::

    :::question type="MSQ" question="Let LL be a regular language over Σ\Sigma. Which of the following operations, when applied to LL, are guaranteed to produce a regular language?" options=["The set of all prefixes of strings in LL (denoted Prefix⁑(L)\operatorname{Prefix}(L)).","The set of all substrings of strings in LL (denoted Substr⁑(L)\operatorname{Substr}(L)).","The set of all strings in LL with even length (denoted LevenL_{even}).","The set of all strings in LL whose length is a prime number."] answer="The set of all prefixes of strings in LL (denoted Prefix⁑(L)\operatorname{Prefix}(L)).,The set of all substrings of strings in LL (denoted Substr⁑(L)\operatorname{Substr}(L)).,The set of all strings in LL with even length (denoted LevenL_{even}). " hint="For each operation, consider how a DFA for LL could be modified to accept the new language. For length-based properties, think about state modification or intersection with a length-constrained regular language." solution="1. The set of all prefixes of strings in LL (denoted Prefix⁑(L)\operatorname{Prefix}(L)).
    If LL is regular, accepted by DFA M=(Q,Ξ£,Ξ΄,q0,F)M = (Q, \Sigma, \delta, q_0, F). To accept prefixes, any state reachable from q0q_0 should be a final state.
    Construct Mβ€²=(Q,Ξ£,Ξ΄,q0,Q)M' = (Q, \Sigma, \delta, q_0, Q). This DFA accepts all prefixes of strings in LL.
    Since Mβ€²M' is a DFA, Prefix⁑(L)\operatorname{Prefix}(L) is regular. This statement is TRUE.

    2. The set of all substrings of strings in LL (denoted Substr⁑(L)\operatorname{Substr}(L)).
    If LL is regular, accepted by DFA M=(Q,Ξ£,Ξ΄,q0,F)M = (Q, \Sigma, \delta, q_0, F).
    To accept substrings, we need to allow arbitrary starting points and arbitrary ending points.
    Construct an NFA Nβ€²N' from MM:
    * Add a new start state snews_{new}.
    * Add Ξ΅\varepsilon-transitions from snews_{new} to all states in QQ. (Allows starting anywhere).
    * Make all states in QQ final. (Allows ending anywhere).
    This NFA accepts all substrings of strings in LL. Since Nβ€²N' is an NFA, Substr⁑(L)\operatorname{Substr}(L) is regular. This statement is TRUE.

    3. The set of all strings in LL with even length (denoted LevenL_{even}).
    If LL is regular, accepted by DFA ML=(QL,Ξ£,Ξ΄L,q0L,FL)M_L = (Q_L, \Sigma, \delta_L, q_{0L}, F_L).
    The language Leven_len={wβˆˆΞ£βˆ—βˆ£βˆ£w∣ isΒ even}L_{even\_len} = \{w \in \Sigma^* \mid |w| \text{ is even}\} is regular (a 2-state DFA can accept it).
    The language of strings in LL with even length is L∩Leven_lenL \cap L_{even\_len}.
    Since LL is regular, Leven_lenL_{even\_len} is regular, and regular languages are closed under intersection, L∩Leven_lenL \cap L_{even\_len} is regular. This statement is TRUE.

    4. The set of all strings in LL whose length is a prime number.
    This operation is not guaranteed to produce a regular language.
    For example, let L=aβˆ—L = a^*. This is regular.
    The set of strings in LL whose length is a prime number is {ap∣p is prime}\{a^p \mid p \text{ is prime}\}. This language is known to be non-regular (can be proven using the Pumping Lemma).
    Thus, this statement is FALSE.

    Answer: The set of all prefixes of strings in LL (denoted Prefix⁑(L)\operatorname{Prefix}(L)).,The set of all substrings of strings in LL (denoted Substr⁑(L)\operatorname{Substr}(L)).,The set of all strings in LL with even length (denoted LevenL_{even}). "
    :::

    ---

    Summary

    ❗ Key Formulas & Takeaways

    |

    | Formula/Concept | Expression | Regularity | Construction Idea |

    |---|----------------|------------|------------|-------------------| | 1 | Union | L1βˆͺL2L_1 \cup L_2 | Yes | NFA with new start state & Ξ΅\varepsilon-transitions | | 2 | Intersection | L1∩L2L_1 \cap L_2 | Yes | Product construction (DFA) | | 3 | Complement | Lβ€Ύ\overline{L} | Yes | Swap final/non-final states (DFA) | | 4 | Concatenation | L1L2L_1 L_2 | Yes | NFA with Ξ΅\varepsilon-transitions from F1F_1 to s2s_2 | | 5 | Kleene Star | Lβˆ—L^* | Yes | NFA with new start/final state, Ξ΅\varepsilon-loops | | 6 | Reverse | LRL^R | Yes | NFA: reverse transitions, swap start/final states | | 7 | Homomorphism | h(L)h(L) | Yes | Apply hh to DFA transitions/RE | | 8 | Inverse Homomorphism | hβˆ’1(L)h^{-1}(L) | Yes | DFA: Ξ΄β€²(q,a)=Ξ΄(q,h(a))\delta'(q,a) = \delta(q, h(a)) | | 9 | `SW(L)` (xyx∈Lxyx \in L) | {yβˆ£βˆƒx,xyx∈L}\{y \mid \exists x, xyx \in L\} | Yes | Product NFA with Ξ΅\varepsilon-transitions for start/end xx | | 10 | `Mix(L1, L2)` (Ξ£βˆ—L1Ξ£βˆ—L2Ξ£βˆ—\Sigma^L_1\Sigma^L_2\Sigma^*) | {w1uw2vw3∣u∈L1,v∈L2,… }\{w_1 u w_2 v w_3 \mid u \in L_1, v \in L_2, \dots\} | Yes | NFA with states for arbitrary strings and language recognition phases | | 11 | `Erase_pattern(L)` | {Erase⁑P(v)∣v∈L}\{\operatorname{Erase}_P(v) \mid v \in L\} | Yes | Reduce to intersection with LΒ¬PL_{\neg P} and properties (e.g., length parity) |

    ---

    What's Next?

    πŸ’‘ Continue Learning

    This topic connects to:

      • Pumping Lemma for Regular Languages: Essential for proving that a language is NOT regular. Often used in conjunction with closure properties to demonstrate non-regularity by contradiction.

      • Context-Free Languages: Many closure properties for regular languages do not hold for CFLs, making the distinction important. Understanding regular language closure helps highlight the differences.

      • Decision Properties of Regular Languages: Properties like emptiness, finiteness, equivalence, and membership are decidable for regular languages, often relying on the ability to construct automata for various operations.

    ---

    πŸ’‘ Next Up

    Proceeding to The Pumping Lemma for Regular Languages.

    ---

    Part 2: The Pumping Lemma for Regular Languages

    The Pumping Lemma is a fundamental tool for demonstrating that a given language is not regular. We use it to prove the non-regularity of languages by contradiction, a critical skill for formal language theory.

    ---

    Core Concepts

    1. The Pumping Lemma Statement

    The Pumping Lemma states that all regular languages possess a property: any sufficiently long string in the language can be "pumped" (i.e., a certain substring can be repeated any number of times) and the resulting string will still be in the language. If a language does not satisfy this property, it cannot be regular.

    πŸ“ The Pumping Lemma for Regular Languages

    If LL is a regular language, then there exists some integer pβ‰₯1p \ge 1 (the pumping length) such that for any string w∈Lw \in L with ∣w∣β‰₯p\lvert w \rvert \ge p, ww can be divided into three substrings w=xyzw = xyz satisfying the following conditions:

    • ∣y∣>0\lvert y \rvert > 0

    • ∣xyβˆ£β‰€p\lvert xy \rvert \le p

    • For all kβ‰₯0k \ge 0, the string xykz∈Lxy^kz \in L.

    Where:
    LL: The regular language
    pp: The pumping length, dependent only on LL
    ww: A string in LL with length at least pp
    x,y,zx, y, z: Substrings of ww such that w=xyzw=xyz
    yy: The "pumpable" part, which must not be empty
    xyxy: The prefix containing the pumpable part must be within the first pp characters
    * kk: The number of times yy is repeated (pumped)
    When to use: To prove that a language is NOT regular.

    Worked Example 1: Proving L={anbn∣nβ‰₯0}L = \{a^n b^n \mid n \ge 0\} is not regular.

    Step 1: Assume LL is regular. Let pp be the pumping length given by the Pumping Lemma.

    Step 2: Choose a string w∈Lw \in L such that ∣w∣β‰₯p\lvert w \rvert \ge p. A suitable choice is w=apbpw = a^p b^p.

    >

    ∣w∣=2pβ‰₯p\lvert w \rvert = 2p \ge p

    Step 3: By the Pumping Lemma, ww can be divided into w=xyzw=xyz such that ∣y∣>0\lvert y \rvert > 0, ∣xyβˆ£β‰€p\lvert xy \rvert \le p, and xykz∈Lxy^kz \in L for all kβ‰₯0k \ge 0.

    Step 4: Analyze the composition of x,y,zx, y, z based on ∣xyβˆ£β‰€p\lvert xy \rvert \le p.
    Since ∣xyβˆ£β‰€p\lvert xy \rvert \le p and w=apbpw = a^p b^p, the substring xyxy must consist entirely of aa's.
    Thus, x=aix = a^i, y=ajy = a^j, z=akbpz = a^k b^p where i+j+k=pi+j+k=p and i,j,kβ‰₯0i,j,k \ge 0.

    Step 5: Apply the condition ∣y∣>0\lvert y \rvert > 0.
    This implies j>0j > 0.

    Step 6: Pump the string for k=0k=0. The pumped string is wβ€²=xy0z=xzw' = xy^0z = xz.

    >

    wβ€²=aiakbp=ai+kbpw' = a^i a^k b^p = a^{i+k} b^p

    Step 7: Check if wβ€²βˆˆLw' \in L.
    Since j>0j > 0, we have i+k=pβˆ’j<pi+k = p-j < p.
    Therefore, wβ€²=apβˆ’jbpw' = a^{p-j} b^p has an unequal number of aa's and bb's.

    >

    apβˆ’jbpβˆ‰LΒ (sinceΒ pβˆ’jβ‰ p)a^{p-j} b^p \notin L \text{ (since } p-j \ne p \text{)}

    Step 8: Conclusion.
    This contradicts the Pumping Lemma, which states xy0zxy^0z must be in LL. Therefore, our initial assumption that LL is regular must be false.

    Answer: L={anbn∣nβ‰₯0}L = \{a^n b^n \mid n \ge 0\} is not regular.

    :::question type="MCQ" question="Which of the following conditions is NOT explicitly stated in the Pumping Lemma for Regular Languages, given LL is regular and w=xyzw=xyz is a string in LL with ∣w∣β‰₯p\lvert w \rvert \ge p?" options=["∣y∣>0\lvert y \rvert > 0","∣xyβˆ£β‰€p\lvert xy \rvert \le p","For all kβ‰₯0k \ge 0, xykz∈Lxy^kz \in L","∣x∣>0\lvert x \rvert > 0"] answer="∣x∣>0\lvert x \rvert > 0" hint="Recall the three main conditions of the Pumping Lemma." solution="The Pumping Lemma states three conditions: 1) ∣y∣>0\lvert y \rvert > 0, 2) ∣xyβˆ£β‰€p\lvert xy \rvert \le p, and 3) For all kβ‰₯0k \ge 0, xykz∈Lxy^kz \in L. There is no condition that ∣x∣>0\lvert x \rvert > 0; xx can be an empty string."
    :::

    ---

    2. Strategy for Proving Non-Regularity

    To prove a language LL is not regular using the Pumping Lemma, we follow a proof by contradiction. The general strategy is to assume LL is regular, apply the Pumping Lemma, and then show that this leads to a contradiction.

    Steps for Pumping Lemma Proofs:

  • Assume LL is regular. This is the starting point for contradiction.

  • Let pp be the pumping length. This pp is guaranteed to exist by the Pumping Lemma.

  • Choose a specific string w∈Lw \in L such that ∣w∣β‰₯p\lvert w \rvert \ge p. This is the most crucial step. The choice of ww must be strategic, usually involving pp in its construction, to force a contradiction later.

  • Show that ww must be partitioned into xyzxyz according to the lemma's conditions.

  • * ∣y∣>0\lvert y \rvert > 0
    * ∣xyβˆ£β‰€p\lvert xy \rvert \le p
  • Derive a contradiction by pumping yy. Choose an integer kβ‰₯0k \ge 0 (often k=0k=0 or k=2k=2) such that xykzβˆ‰Lxy^kz \notin L. This contradicts the Pumping Lemma, thus proving LL is not regular.
  • Worked Example 2: Proving L={anbman∣n,mβ‰₯0}L = \{a^n b^m a^n \mid n, m \ge 0\} is not regular.

    Step 1: Assume LL is regular. Let pp be the pumping length.

    Step 2: Choose w∈Lw \in L such that ∣w∣β‰₯p\lvert w \rvert \ge p. A good choice is w=apbpapw = a^p b^p a^p.

    >

    ∣w∣=3pβ‰₯p\lvert w \rvert = 3p \ge p

    Step 3: By the Pumping Lemma, ww can be divided into w=xyzw=xyz with ∣y∣>0\lvert y \rvert > 0, ∣xyβˆ£β‰€p\lvert xy \rvert \le p, and xykz∈Lxy^kz \in L for all kβ‰₯0k \ge 0.

    Step 4: Analyze x,y,zx, y, z.
    Since ∣xyβˆ£β‰€p\lvert xy \rvert \le p, the substring xyxy must fall entirely within the first block of aa's in apbpapa^p b^p a^p.
    So, x=aix = a^i, y=ajy = a^j, z=akbpapz = a^k b^p a^p, where i+j+k=pi+j+k=p and j>0j > 0.

    Step 5: Pump the string for k=2k=2. The pumped string is wβ€²=xy2zw' = xy^2z.

    >

    wβ€²=ai(aj)2akbpap=ai+2j+kbpapw' = a^i (a^j)^2 a^k b^p a^p = a^{i+2j+k} b^p a^p

    Step 6: Check if wβ€²βˆˆLw' \in L.
    We know i+j+k=pi+j+k=p.
    So, i+2j+k=(i+j+k)+j=p+ji+2j+k = (i+j+k) + j = p+j.
    Therefore, wβ€²=ap+jbpapw' = a^{p+j} b^p a^p.

    Step 7: Check if wβ€²βˆˆLw' \in L.
    Since j>0j > 0, we have p+j≠pp+j \ne p.
    For w′w' to be in LL, the number of aa's at the beginning must equal the number of aa's at the end. Here, p+j≠pp+j \ne p.

    >

    wβ€²=ap+jbpapβˆ‰Lw' = a^{p+j} b^p a^p \notin L

    Step 8: Conclusion.
    This contradicts the Pumping Lemma. Therefore, LL is not regular.

    Answer: L={anbman∣n,mβ‰₯0}L = \{a^n b^m a^n \mid n, m \ge 0\} is not regular.

    :::question type="NAT" question="Consider the language L={(ab)ncn∣nβ‰₯0}L = \{ (ab)^n c^n \mid n \ge 0 \}. If we use the Pumping Lemma to prove it's not regular, and we choose the string w=(ab)pcpw = (ab)^p c^p, what is the minimum possible length of the yy substring?" answer="1" hint="The Pumping Lemma states ∣y∣>0\lvert y \rvert > 0. This implies the minimum length is 1." solution="The Pumping Lemma condition ∣y∣>0\lvert y \rvert > 0 means that the substring yy must have a length of at least 1. Thus, the minimum possible length of yy is 1."
    :::

    Worked Example 3: Proving L={ww∣w∈{a,b}βˆ—}L = \{w w \mid w \in \{a,b\}^*\} is not regular.

    Step 1: Assume LL is regular. Let pp be the pumping length.

    Step 2: Choose w∈Lw \in L such that ∣w∣β‰₯p\lvert w \rvert \ge p. A suitable choice is w=apbapbw = a^p b a^p b.
    This string is of the form uuu u where u=apbu = a^p b.

    >

    ∣w∣=2(p+1)β‰₯p\lvert w \rvert = 2(p+1) \ge p

    Step 3: By the Pumping Lemma, ww can be divided into w=xyzw=xyz with ∣y∣>0\lvert y \rvert > 0, ∣xyβˆ£β‰€p\lvert xy \rvert \le p, and xykz∈Lxy^kz \in L for all kβ‰₯0k \ge 0.

    Step 4: Analyze x,y,zx, y, z.
    Since ∣xyβˆ£β‰€p\lvert xy \rvert \le p, the substring xyxy must fall entirely within the first block of aa's in apbapba^p b a^p b.
    So, x=aix = a^i, y=ajy = a^j, z=akbapbz = a^k b a^p b, where i+j+k=pi+j+k=p and j>0j > 0.

    Step 5: Pump the string for k=2k=2. The pumped string is wβ€²=xy2zw' = xy^2z.

    >

    wβ€²=ai(aj)2akbapb=ai+2j+kbapb=ap+jbapbw' = a^i (a^j)^2 a^k b a^p b = a^{i+2j+k} b a^p b = a^{p+j} b a^p b

    Step 6: Check if wβ€²βˆˆLw' \in L.
    For wβ€²w' to be in LL, it must be of the form uβ€²uβ€²u'u' for some string uβ€²u'.
    The string wβ€²w' is ap+jbapba^{p+j} b a^p b.
    Since j>0j > 0, the first block of aa's has length p+jp+j, while the second block of aa's (before the second bb) has length pp.
    This means the first half of the string ap+jba^{p+j} b is not equal to the second half apba^p b.

    >

    ap+jb≠apb since j>0a^{p+j} b \ne a^p b \text{ since } j > 0

    Therefore, wβ€²w' is not of the form uβ€²uβ€²u'u'.

    >

    wβ€²βˆ‰Lw' \notin L

    Step 7: Conclusion.
    This contradicts the Pumping Lemma. Therefore, LL is not regular.

    Answer: L={ww∣w∈{a,b}βˆ—}L = \{w w \mid w \in \{a,b\}^*\} is not regular.

    :::question type="MSQ" question="Let L={anbncm∣n,mβ‰₯0}L = \{a^n b^n c^m \mid n, m \ge 0\}. Which of the following strings could be chosen as ww to prove LL is not regular using the Pumping Lemma, assuming pp is the pumping length?" options=["apbpcpa^p b^p c^p","apbpa^p b^p","apcpa^p c^p","apbp+1cpa^p b^{p+1} c^p"] answer="apbpcp,apbpa^p b^p c^p,a^p b^p" hint="The Pumping Lemma is used to prove non-regularity. For the given language structure, we need to ensure the `n` part is affected by pumping." solution="The language requires the number of aa's to equal the number of bb's. The cc's can be arbitrary. To use the Pumping Lemma, we must choose a string where the dependency (anbna^n b^n) is within the first pp characters.

  • `apbpcpa^p b^p c^p`: This string is in LL. If we select this, the yy part will be within apa^p. Pumping aa's will change the count of aa's without changing bb's, leading to ap+jbpcpβˆ‰La^{p+j}b^p c^p \notin L. This is a valid choice.

  • `apbpa^p b^p`: This string is also in LL (when m=0m=0). If we select this, yy will be within apa^p, and pumping aa's will lead to ap+jbpβˆ‰La^{p+j}b^p \notin L. This is also a valid choice.

  • `apcpa^p c^p`: This string is not in LL because it's missing bb's. We must choose w∈Lw \in L.

  • `apbp+1cpa^p b^{p+1} c^p`: This string is not in LL because the number of aa's (pp) does not equal the number of bb's (p+1p+1). We must choose w∈Lw \in L.
  • Both apbpcpa^p b^p c^p and apbpa^p b^p are valid choices for ww to demonstrate non-regularity."
    :::

    ---

    3. Why the Pumping Lemma Cannot Prove Regularity

    The Pumping Lemma is a necessary condition for a language to be regular, but it is not a sufficient condition. This means that if a language satisfies the Pumping Lemma, it is not necessarily regular. It only proves non-regularity.

    ❗ Pumping Lemma: Necessary but Not Sufficient

    The Pumping Lemma provides a necessary condition for a language to be regular. If a language does not satisfy the Pumping Lemma, it is definitively not regular. However, if a language does satisfy the Pumping Lemma, it is not necessarily regular. There exist non-regular languages that satisfy the Pumping Lemma.

    :::question type="MCQ" question="Which of the following statements about the Pumping Lemma for Regular Languages is true?" options=["It can be used to prove that a language is regular.","It is a sufficient condition for a language to be regular.","It is a necessary condition for a language to be regular.","Every non-regular language fails the Pumping Lemma test."] answer="It is a necessary condition for a language to be regular." hint="Consider whether satisfying the lemma guarantees regularity." solution="The Pumping Lemma is a necessary condition for a language to be regular. If a language is regular, it must satisfy the Pumping Lemma. However, satisfying the Pumping Lemma does not guarantee regularity (it's not sufficient). Therefore, it cannot be used to prove regularity. Also, there exist non-regular languages that satisfy the Pumping Lemma, so not every non-regular language fails the test."
    :::

    ---

    Advanced Applications

    Advanced applications often involve careful string selection or handling multiple cases for the substring yy.

    Worked Example 4: Proving L={w∈{a,b,c}βˆ—βˆ£numberΒ ofΒ a’s=numberΒ ofΒ b’s=numberΒ ofΒ c’s}L = \{w \in \{a,b,c\}^* \mid \text{number of } a\text{'s} = \text{number of } b\text{'s} = \text{number of } c\text{'s} \} is not regular.

    Step 1: Assume LL is regular. Let pp be the pumping length.

    Step 2: Choose w∈Lw \in L such that ∣w∣β‰₯p\lvert w \rvert \ge p. A good choice is w=apbpcpw = a^p b^p c^p.

    >

    ∣w∣=3pβ‰₯p\lvert w \rvert = 3p \ge p

    Step 3: By the Pumping Lemma, ww can be divided into w=xyzw=xyz with ∣y∣>0\lvert y \rvert > 0, ∣xyβˆ£β‰€p\lvert xy \rvert \le p, and xykz∈Lxy^kz \in L for all kβ‰₯0k \ge 0.

    Step 4: Analyze x,y,zx, y, z.
    Since ∣xyβˆ£β‰€p\lvert xy \rvert \le p and w=apbpcpw = a^p b^p c^p, the substring xyxy must fall entirely within the first block of aa's.
    So, x=aix = a^i, y=ajy = a^j, z=akbpcpz = a^k b^p c^p, where i+j+k=pi+j+k=p and j>0j > 0.

    Step 5: Pump the string for k=2k=2. The pumped string is wβ€²=xy2zw' = xy^2z.

    >

    wβ€²=ai(aj)2akbpcp=ai+2j+kbpcp=ap+jbpcpw' = a^i (a^j)^2 a^k b^p c^p = a^{i+2j+k} b^p c^p = a^{p+j} b^p c^p

    Step 6: Check if wβ€²βˆˆLw' \in L.
    Since j>0j > 0, the number of aa's in wβ€²w' is p+jp+j, which is strictly greater than pp.
    The number of bb's is pp, and the number of cc's is pp.
    Thus, the number of aa's is not equal to the number of bb's (or cc's).

    >

    wβ€²βˆ‰Lw' \notin L

    Step 7: Conclusion.
    This contradicts the Pumping Lemma. Therefore, LL is not regular.

    Answer: L={w∈{a,b,c}βˆ—βˆ£numberΒ ofΒ a’s=numberΒ ofΒ b’s=numberΒ ofΒ c’s}L = \{w \in \{a,b,c\}^* \mid \text{number of } a\text{'s} = \text{number of } b\text{'s} = \text{number of } c\text{'s} \} is not regular.

    Worked Example 5: Proving L={an∣n is a prime number}L = \{a^n \mid n \text{ is a prime number}\} is not regular.

    Step 1: Assume LL is regular. Let pp be the pumping length.

    Step 2: Choose w∈Lw \in L such that ∣w∣β‰₯p\lvert w \rvert \ge p.
    We need to pick a prime number qq such that qβ‰₯pq \ge p. Let w=aqw = a^q.

    >

    ∣w∣=qβ‰₯p\lvert w \rvert = q \ge p

    Step 3: By the Pumping Lemma, ww can be divided into w=xyzw=xyz such that ∣y∣>0\lvert y \rvert > 0, ∣xyβˆ£β‰€p\lvert xy \rvert \le p, and xykz∈Lxy^kz \in L for all kβ‰₯0k \ge 0.

    Step 4: Analyze x,y,zx, y, z.
    Since w=aqw = a^q, all characters are aa's. So x=aix=a^i, y=ajy=a^j, z=akz=a^k, where i+j+k=qi+j+k=q.
    The conditions are ∣y∣=j>0\lvert y \rvert = j > 0 and ∣xy∣=i+j≀p\lvert xy \rvert = i+j \le p.

    Step 5: Pump the string for k=q+1k=q+1.
    The pumped string is wβ€²=xyq+1zw' = xy^{q+1}z.

    >

    wβ€²=ai(aj)q+1ak=ai+j(q+1)+kw' = a^i (a^j)^{q+1} a^k = a^{i + j(q+1) + k}

    Step 6: Simplify the exponent.
    We know i+j+k=qi+j+k=q.
    So, i+j(q+1)+k=(i+j+k)+j(q+1)βˆ’j=q+j(q+1)βˆ’j=q+jq+jβˆ’j=q+jq=q(1+j)i + j(q+1) + k = (i+j+k) + j(q+1) - j = q + j(q+1) - j = q + jq + j - j = q + jq = q(1+j).

    >

    wβ€²=aq(1+j)w' = a^{q(1+j)}

    Step 7: Check if wβ€²βˆˆLw' \in L.
    The length of wβ€²w' is q(1+j)q(1+j).
    Since qq is a prime number and j>0j > 0, 1+j1+j is an integer greater than 1.
    Therefore, q(1+j)q(1+j) is a composite number (a product of two integers greater than 1).
    Thus, q(1+j)q(1+j) cannot be a prime number.

    >

    wβ€²βˆ‰Lw' \notin L

    Step 8: Conclusion.
    This contradicts the Pumping Lemma. Therefore, LL is not regular.

    Answer: L={an∣n is a prime number}L = \{a^n \mid n \text{ is a prime number}\} is not regular.

    :::question type="MCQ" question="Consider the language L={anbm∣nβ‰₯mβ‰₯0}L = \{a^n b^m \mid n \ge m \ge 0 \}. Which string ww is most suitable to prove that LL is not regular using the Pumping Lemma, given pp is the pumping length?" options=["apbpa^p b^p","ap+1bpa^{p+1} b^p","apbpβˆ’1a^p b^{p-1}","apbp+1a^p b^{p+1}"] answer="apbpa^p b^p" hint="The Pumping Lemma works by pumping within the first pp characters. Choose a string where the relationship (nβ‰₯mn \ge m) can be broken by changing the initial characters." solution="The language requires the number of aa's to be greater than or equal to the number of bb's.

  • `apbpa^p b^p`: This string is in LL. The first pp characters are all aa's. If yy is a part of apa^p, say y=ajy=a^j (j>0j>0), then pumping down (k=0k=0) yields apβˆ’jbpa^{p-j} b^p. Here, pβˆ’j<pp-j < p, so apβˆ’jbpβˆ‰La^{p-j} b^p \notin L because the number of aa's is less than the number of bb's. This is a suitable choice.

  • `ap+1bpa^{p+1} b^p`: This string is in LL. The first pp characters are all aa's. If y=ajy=a^j, pumping down gives ap+1βˆ’jbpa^{p+1-j} b^p. If j=1j=1, we get apbpa^p b^p, which is in LL. If j>1j>1, we might still have p+1βˆ’jβ‰₯pp+1-j \ge p. This choice is less direct for contradiction.

  • `apbpβˆ’1a^p b^{p-1}`: This string is in LL. The first pp characters are aa's. If y=ajy=a^j, pumping down gives apβˆ’jbpβˆ’1a^{p-j} b^{p-1}. We still have pβˆ’jβ‰₯pβˆ’1p-j \ge p-1 if j=1j=1. This might not lead to a contradiction easily.

  • `apbp+1a^p b^{p+1}`: This string is not in LL because p<p+1p < p+1. We must choose w∈Lw \in L.
  • The string apbpa^p b^p forces yy to be entirely aa's within the first pp characters, and pumping down breaks the nβ‰₯mn \ge m condition, making it the most suitable choice."
    :::

    ---

    Problem-Solving Strategies

    πŸ’‘ CMI Strategy: Choosing the Pumping Lemma String

    The most critical step in a Pumping Lemma proof is selecting the string ww.

    • Ensure w∈Lw \in L and ∣w∣β‰₯p\lvert w \rvert \ge p.

    • Make ww "barely" satisfy the condition that makes LL non-regular. For example, for anbna^n b^n, choose apbpa^p b^p. For anbmana^n b^m a^n, choose apbpapa^p b^p a^p. This forces the pumpable part yy to be within the part of the string that enforces the "non-regular" property.

    • Position the "critical" section of ww within the first pp characters. The condition ∣xyβˆ£β‰€p\lvert xy \rvert \le p means yy must occur within the first pp characters of ww. Your chosen ww should ensure that pumping yy (which is in the first pp characters) will break the language's defining property.

    • Consider edge cases for yy. Sometimes yy could be entirely one character, or a mix. Your chosen ww should ideally force yy to be of a specific character type or position to simplify analysis.

    πŸ’‘ CMI Strategy: Proving Regularity

    If a language is regular, the Pumping Lemma is not the tool to use. Instead, prove regularity by:

    • Constructing a Finite Automaton (DFA or NFA): This is often the most direct method.

    • Constructing a Regular Expression: A regular expression directly describes a regular language.

    • Using Closure Properties: Show the language can be built from known regular languages using operations (union, concatenation, Kleene star, intersection, complement) that preserve regularity.

    ---

    Common Mistakes

    ⚠️ Common Mistake: Proving Regularity with the Pumping Lemma

    ❌ Attempting to use the Pumping Lemma to prove a language is regular.
    βœ… The Pumping Lemma is a tool for disproving regularity. To prove regularity, construct an FA/RE or use closure properties.

    ⚠️ Common Mistake: Incorrect String Choice

    ❌ Choosing a string ww that is too short (∣w∣<p\lvert w \rvert < p) or does not force yy into a critical position.
    βœ… Choose ww carefully, often involving pp in its length, to ensure yy falls within the part of the string that, when pumped, will violate the language's definition. Example: for anbna^n b^n, choose apbpa^p b^p, not apbp+5a^p b^{p+5}.

    ⚠️ Common Mistake: Not Considering All xyzxyz Decompositions

    ❌ Assuming a specific structure for x,y,zx, y, z when the Pumping Lemma allows for multiple valid partitions. The proof must hold for any valid xyzxyz decomposition.
    βœ… Your choice of ww (and the ∣xyβˆ£β‰€p\lvert xy \rvert \le p condition) should ideally constrain the possible forms of yy enough to lead to a contradiction regardless of yy's exact composition. For example, if w=apbpw=a^p b^p, ∣xyβˆ£β‰€p\lvert xy \rvert \le p forces yy to be entirely aa's. If w=apbpcpw=a^p b^p c^p, then yy must be entirely aa's.

    ---

    Practice Questions

    :::question type="MCQ" question="Which of the following languages is regular?" options=["L1={anbn∣nβ‰₯0}L_1 = \{a^n b^n \mid n \ge 0\}","L2={w∈{a,b}βˆ—βˆ£numberΒ ofΒ a’s=numberΒ ofΒ b’s}L_2 = \{w \in \{a,b\}^ \mid \text{number of } a\text{'s} = \text{number of } b\text{'s}\}","L3={wwR∣w∈{a,b}βˆ—Β (palindromes)}L_3 = \{w w^R \mid w \in \{a,b\}^ \text{ (palindromes)}\}","L4={an∣nΒ isΒ even}L_4 = \{a^n \mid n \text{ is even}\}"] answer="L4={an∣nΒ isΒ even}L_4 = \{a^n \mid n \text{ is even}\}" hint="Consider which languages can be recognized by a finite automaton or described by a regular expression." solution="

  • L1={anbn∣nβ‰₯0}L_1 = \{a^n b^n \mid n \ge 0\}: Not regular. Requires counting equal numbers of aa's and bb's, which FA cannot do. (Proven in Worked Example 1).

  • L2={w∈{a,b}βˆ—βˆ£numberΒ ofΒ a’s=numberΒ ofΒ b’s}L_2 = \{w \in \{a,b\}^* \mid \text{number of } a\text{'s} = \text{number of } b\text{'s}\}: Not regular. Similar to L1L_1, requires counting and comparing arbitrary numbers of aa's and bb's regardless of order.

  • L3={wwR∣w∈{a,b}βˆ—Β (palindromes)}L_3 = \{w w^R \mid w \in \{a,b\}^* \text{ (palindromes)}\}: Not regular. Requires remembering the first half of the string to compare with the reversed second half.

  • L4={an∣nΒ isΒ even}L_4 = \{a^n \mid n \text{ is even}\}: Regular. This can be described by the regular expression (aa)βˆ—(aa)^*. A DFA can easily recognize this by having two states: one for an even number of aa's and one for an odd number of aa's.

  • "
    :::

    :::question type="NAT" question="Consider the language L={(01)n(10)n∣nβ‰₯1}L = \{ (01)^n (10)^n \mid n \ge 1 \}. If we use the Pumping Lemma with w=(01)p(10)pw = (01)^p (10)^p, and yy consists of jj copies of '01', what is the length of yy? (Assume pp is the pumping length.)" answer="2j" hint="The length of the substring '01' is 2. If yy consists of jj copies of '01', its length is 2j2j." solution="If yy consists of jj copies of the substring '01', and each '01' has a length of 2, then the total length of yy is 2Γ—j=2j2 \times j = 2j."
    :::

    :::question type="MSQ" question="Let L={w∈{a,b,c}βˆ—βˆ£theΒ lengthΒ ofΒ wΒ isΒ aΒ perfectΒ square}L = \{w \in \{a,b,c\}^* \mid \text{the length of } w \text{ is a perfect square}\}. Which of the following statements are true about proving LL is not regular using the Pumping Lemma?" options=["We should choose w=ap2w = a^{p^2} where pp is the pumping length.","If w=ap2w=a^{p^2}, then yy must consist only of aa's.","Pumping yy (say, k=2k=2) will result in a string whose length is not a perfect square.","The condition ∣xyβˆ£β‰€p\lvert xy \rvert \le p is crucial to constrain yy to be within the initial part of ww."] answer="We should choose w=ap2w = a^{p^2} where pp is the pumping length.,If w=ap2w=a^{p^2}, then yy must consist only of aa's.,Pumping yy (say, k=2k=2) will result in a string whose length is not a perfect square.,The condition ∣xyβˆ£β‰€p\lvert xy \rvert \le p is crucial to constrain yy to be within the initial part of ww." hint="Consider the structure of the language and how the Pumping Lemma conditions restrict yy." solution="
    All statements are true.

  • We should choose w=ap2w = a^{p^2} where pp is the pumping length. This is a standard choice for languages based on length properties, as p2p^2 is a perfect square and ∣w∣=p2β‰₯p\lvert w \rvert = p^2 \ge p.

  • If w=ap2w=a^{p^2}, then yy must consist only of aa's. Since ∣xyβˆ£β‰€p\lvert xy \rvert \le p and ww is entirely aa's, xx and yy must also be entirely aa's.

  • Pumping yy (say, k=2k=2) will result in a string whose length is not a perfect square. If w=ap2w=a^{p^2} and y=ajy=a^j (1≀j≀p1 \le j \le p), then xy2z=ap2+jxy^2z = a^{p^2+j}. We need to show that p2+jp^2+j cannot be a perfect square.

  • We know p2<p2+j≀p2+pp^2 < p^2+j \le p^2+p.
    The next perfect square after p2p^2 is (p+1)2=p2+2p+1(p+1)^2 = p^2+2p+1.
    Since p2+j≀p2+p<p2+2p+1=(p+1)2p^2+j \le p^2+p < p^2+2p+1 = (p+1)^2 (for pβ‰₯1p \ge 1), p2+jp^2+j falls strictly between p2p^2 and (p+1)2(p+1)^2.
    Thus, p2+jp^2+j cannot be a perfect square, leading to a contradiction.
  • The condition ∣xyβˆ£β‰€p\lvert xy \rvert \le p is crucial to constrain yy to be within the initial part of ww. This condition is what ensures yy consists only of aa's in this specific example, which is vital for the proof to work.

  • "
    :::

    :::question type="MCQ" question="Consider the language L={anbk∣nβ‰ k}L = \{a^n b^k \mid n \ne k \}. Is LL regular or not? And what method would you use to justify your answer?" options=["Regular, by constructing a DFA.","Regular, by applying the Pumping Lemma.","Not regular, by constructing a DFA.","Not regular, by applying the Pumping Lemma."] answer="Not regular, by applying the Pumping Lemma." hint="Consider the complement of the language. If the complement is not regular, then the original language is also not regular (assuming closure under complementation for regular languages)." solution="The complement of LL relative to aβˆ—bβˆ—a^b^, denoted Lβ€²L', is Lβ€²={anbn∣nβ‰₯0}L' = \{a^n b^n \mid n \ge 0\}.
    The language Lβ€²={anbn∣nβ‰₯0}L' = \{a^n b^n \mid n \ge 0\} is a well-known non-regular language (as proven in Worked Example 1).
    If L={anbk∣nβ‰ k}L = \{a^n b^k \mid n \ne k \} were regular, then its complement Lβ€²L' would also be regular (since regular languages are closed under complementation relative to the universal set aβˆ—bβˆ—a^b^).
    Since L′L' is not regular, LL cannot be regular. Therefore, LL is not regular, and its non-regularity would typically be shown using the Pumping Lemma (applied to L′L' or directly to LL with careful string choice, though the complement argument is often cleaner for n≠kn \ne k type languages).
    "
    :::

    :::question type="NAT" question="What is the minimum length of the pumping substring yy as specified by the Pumping Lemma?" answer="1" hint="Refer to the conditions of the Pumping Lemma." solution="The Pumping Lemma states that ∣y∣>0\lvert y \rvert > 0. The smallest integer greater than 0 is 1. Therefore, the minimum length of yy is 1."
    :::

    :::question type="MSQ" question="Let LL be a language over Ξ£={0,1}\Sigma = \{0,1\}. Which of the following languages are regular?" options=["L1={w∣wΒ containsΒ anΒ equalΒ numberΒ ofΒ 0sΒ andΒ 1s}L_1 = \{w \mid w \text{ contains an equal number of 0s and 1s}\}","L2={w∣wΒ isΒ aΒ binaryΒ representationΒ ofΒ aΒ primeΒ number}L_2 = \{w \mid w \text{ is a binary representation of a prime number}\}","L3={w∣wΒ containsΒ anΒ oddΒ numberΒ ofΒ 1s}L_3 = \{w \mid w \text{ contains an odd number of 1s}\}","L4={w∣wΒ contains ’00’ asΒ aΒ substring}L_4 = \{w \mid w \text{ contains '00' as a substring}\}"] answer="L3={w∣wΒ containsΒ anΒ oddΒ numberΒ ofΒ 1s},L4={w∣wΒ contains ’00’ asΒ aΒ substring}L_3 = \{w \mid w \text{ contains an odd number of 1s}\},L_4 = \{w \mid w \text{ contains '00' as a substring}\}" hint="Consider if a finite automaton can keep track of the necessary information." solution="

  • L1={w∣wΒ containsΒ anΒ equalΒ numberΒ ofΒ 0sΒ andΒ 1s}L_1 = \{w \mid w \text{ contains an equal number of 0s and 1s}\}: Not regular. Requires counting an arbitrary number of 0s and 1s and comparing them, which a finite automaton cannot do. This is similar to anbna^n b^n.

  • L2={w∣wΒ isΒ aΒ binaryΒ representationΒ ofΒ aΒ primeΒ number}L_2 = \{w \mid w \text{ is a binary representation of a prime number}\}: Not regular. This is analogous to {an∣nΒ isΒ prime}\{a^n \mid n \text{ is prime}\}, which we proved non-regular. Recognizing prime numbers requires arbitrary counting and arithmetic, beyond the capability of finite automata.

  • L3={w∣wΒ containsΒ anΒ oddΒ numberΒ ofΒ 1s}L_3 = \{w \mid w \text{ contains an odd number of 1s}\}: Regular. A 2-state DFA can recognize this: one state for an even number of 1s and one for an odd number of 1s.

  • L4={w∣wΒ contains ’00’ asΒ aΒ substring}L_4 = \{w \mid w \text{ contains '00' as a substring}\}: Regular. This can be described by the regular expression (0βˆͺ1)βˆ—00(0βˆͺ1)βˆ—(0 \cup 1)^ 00 (0 \cup 1)^. A DFA can recognize this by having states to remember if the last character was '0' and if the current character is '0'.

  • "
    :::

    ---

    Summary

    ❗ Key Formulas & Takeaways

    |

    | Formula/Concept | Expression |

    |---|----------------|------------| | 1 | Pumping Lemma Statement | If LL is regular, there exists pβ‰₯1p \ge 1 such that for any w∈L,∣w∣β‰₯pw \in L, \lvert w \rvert \ge p, w=xyzw=xyz where ∣y∣>0\lvert y \rvert > 0, ∣xyβˆ£β‰€p\lvert xy \rvert \le p, and xykz∈Lxy^kz \in L for all kβ‰₯0k \ge 0. | | 2 | Purpose of Pumping Lemma | To prove that a language is NOT regular (proof by contradiction). | | 3 | Pumping Lemma Limitation | Necessary but not sufficient condition for regularity. Cannot prove regularity. | | 4 | Key Strategy | Choose w∈Lw \in L with ∣w∣β‰₯p\lvert w \rvert \ge p such that yy is forced into a critical part of ww, and pumping yy breaks the language's definition. |

    ---

    What's Next?

    πŸ’‘ Continue Learning

    This topic connects to:

      • Context-Free Languages (CFLs): The Pumping Lemma for Regular Languages is analogous to the Pumping Lemma for CFLs, which is used to prove languages are NOT context-free.

      • Closure Properties of Regular Languages: Understanding which operations preserve regularity helps in determining if a language is regular (e.g., if LL is regular, then LcL^c is regular).

      • Decision Properties of Regular Languages: Properties like emptiness, finiteness, and equivalence are decidable for regular languages, often relying on the finite nature of automata.

    Chapter Summary

    ❗ Properties of Regular Languages β€” Key Points

    • Regular languages are closed under fundamental set operations (union, intersection, complementation) and regular operations (concatenation, Kleene star, reversal). These closure properties are essential for constructing and manipulating regular languages.

    • Closure properties can be utilized to demonstrate a language's regularity by showing it can be derived from known regular languages through closed operations. Conversely, they can indirectly support non-regularity proofs by contradiction.

    • The Pumping Lemma for Regular Languages provides a necessary condition for a language to be regular. It states that any sufficiently long string in a regular language can be "pumped" (by repeating a middle section), and the resulting strings must also remain in the language.

    • The primary application of the Pumping Lemma is to rigorously prove that a given language is not regular, always through a proof by contradiction. It cannot be used to prove that a language is regular.

    • A successful Pumping Lemma proof for non-regularity involves selecting an appropriate string ss (with length at least the pumping length pp) from the language and demonstrating that for every possible valid decomposition s=xyzs=xyz (satisfying ∣xyβˆ£β‰€p|xy| \le p and ∣y∣>0|y| > 0), there exists an integer iβ‰₯0i \ge 0 such that xyizxy^iz is not in the language, thus contradicting the lemma.

    • Understanding both closure properties and the Pumping Lemma is critical for classifying languages within the Chomsky Hierarchy and for comprehending the expressive power and limitations of finite automata.

    ---

    Chapter Review Questions

    :::question type="MCQ" question="Which of the following operations, when applied to two regular languages L1L_1 and L2L_2, does not always result in a regular language?" options=["Union (L1βˆͺL2L_1 \cup L_2)", "Intersection (L1∩L2L_1 \cap L_2)", "Concatenation (L1L2L_1 L_2)", "Symmetric difference (L1Ξ”L2=(L1βˆͺL2)βˆ’(L1∩L2)L_1 \Delta L_2 = (L_1 \cup L_2) - (L_1 \cap L_2))", "All of the above operations always result in a regular language."] answer="All of the above operations always result in a regular language." hint="Recall the full set of closure properties for regular languages." solution="Regular languages are closed under union, intersection, concatenation, Kleene star, complementation, and reversal. Symmetric difference can be expressed using union, intersection, and complementation, all of which are closed operations for regular languages. Therefore, all listed operations preserve regularity."
    :::

    :::question type="MCQ" question="When applying the Pumping Lemma for Regular Languages to prove a language LL is not regular, which of the following best describes the overall proof strategy?" options=["Assume LL is regular, choose a string s∈Ls \in L with ∣s∣β‰₯p|s| \ge p, and then find a specific decomposition xyzxyz such that xyizβˆ‰Lxy^iz \notin L for some iβ‰₯0i \ge 0.", "Assume LL is regular, choose a string s∈Ls \in L with ∣s∣β‰₯p|s| \ge p, and then show that for every possible decomposition xyzxyz satisfying the lemma's conditions, there exists an iβ‰₯0i \ge 0 such that xyizβˆ‰Lxy^iz \notin L.", "Assume LL is not regular, and then demonstrate that no pumping length pp exists for LL.", "Assume LL is regular, and then show that for all strings s∈Ls \in L with ∣s∣β‰₯p|s| \ge p, all decompositions xyzxyz satisfy xyiz∈Lxy^iz \in L."] answer="Assume LL is regular, choose a string s∈Ls \in L with ∣s∣β‰₯p|s| \ge p, and then show that for every possible decomposition xyzxyz satisfying the lemma's conditions, there exists an iβ‰₯0i \ge 0 such that xyizβˆ‰Lxy^iz \notin L." hint="The Pumping Lemma proof for non-regularity is a proof by contradiction, often adversarial, requiring the proof to hold for any valid decomposition." solution="The correct strategy is to assume the language LL is regular, which implies a pumping length pp exists. Then, a carefully chosen string s∈Ls \in L (with ∣s∣β‰₯p|s| \ge p) is selected. The core of the proof lies in showing that no matter how ss is decomposed into xyzxyz according to the lemma's rules, pumping yy (i.e., forming xyizxy^iz for some iβ‰ 1i \ne 1) leads to a string that is not in LL, thus contradicting the initial assumption that LL is regular."
    :::

    :::question type="NAT" question="For a regular language LL with pumping length pp, if a string s∈Ls \in L is chosen such that ∣s∣=p+5|s| = p+5, and it is decomposed as s=xyzs=xyz according to the Pumping Lemma's conditions (∣xyβˆ£β‰€p|xy| \le p, ∣y∣>0|y| > 0), what is the minimum possible length of the substring zz?" answer="5" hint="Consider the length constraint ∣xyβˆ£β‰€p|xy| \le p in conjunction with ∣s∣=∣x∣+∣y∣+∣z∣|s| = |x| + |y| + |z|." solution="Given ∣s∣=p+5|s| = p+5 and ∣s∣=∣x∣+∣y∣+∣z∣|s| = |x| + |y| + |z|. We also know ∣xyβˆ£β‰€p|xy| \le p, which means ∣x∣+∣yβˆ£β‰€p|x| + |y| \le p. Substituting this into the length equation: (∣x∣+∣y∣)+∣z∣=p+5(|x| + |y|) + |z| = p+5. Since ∣x∣+∣y∣|x| + |y| can be at most pp, the smallest possible value for ∣z∣|z| occurs when ∣x∣+∣y∣|x| + |y| is maximized (i.e., ∣x∣+∣y∣=p|x| + |y| = p). In this case, p+∣z∣=p+5p + |z| = p+5, which implies ∣z∣=5|z|=5. Thus, the minimum possible length of zz is 5."
    :::

    :::question type="MCQ" question="Given that L1={anbn∣nβ‰₯0}L_1 = \{a^n b^n \mid n \ge 0\} is a known non-regular language. If L1Λ‰\bar{L_1} denotes the complement of L1L_1 (i.e., Ξ£βˆ—βˆ’L1\Sigma^ - L_1), which of the following statements is true regarding L1Λ‰\bar{L_1}?" options=["L1Λ‰\bar{L_1} must be regular because regular languages are closed under complementation.", "L1Λ‰\bar{L_1} must be non-regular, because if it were regular, then L1L_1 would also be regular.", "L1Λ‰\bar{L_1} could be regular or non-regular, depending on the specific alphabet Ξ£\Sigma.", "The Pumping Lemma cannot be applied to determine the regularity of L1Λ‰\bar{L_1} if L1L_1 is non-regular."] answer="L1Λ‰\bar{L_1} must be non-regular, because if it were regular, then L1L_1 would also be regular." hint="Recall the implication of closure properties: if a class of languages is closed under an operation, and applying that operation to a language outside the class results in a language within the class, what does that imply about the original language?" solution="Regular languages are closed under complementation. This means if a language LL is regular, its complement LΛ‰\bar{L} is also regular. Conversely, if LL is not regular, then LΛ‰\bar{L} cannot* be regular. If LΛ‰\bar{L} were regular, then its complement, LΛ‰β€Ύ\overline{\bar{L}}, which is LL, would also have to be regular (by the closure property), contradicting the premise that L1L_1 is non-regular. Therefore, if L1L_1 is non-regular, its complement L1Λ‰\bar{L_1} must also be non-regular."
    :::

    ---

    What's Next?

    πŸ’‘ Continue Your CMI Journey

    Building upon the foundational understanding of regular languages, the next crucial step in Formal Languages and Automata Theory involves exploring Context-Free Languages (CFLs). This journey will introduce more powerful computational models (Pushdown Automata), examine their distinct closure properties, and present an analogous Pumping Lemma designed to prove a language is not context-free. This progression systematically climbs the Chomsky Hierarchy, deepening your insight into the capabilities and limitations of different language classes.

    🎯 Key Points to Remember

    • βœ“ Master the core concepts in Properties of Regular Languages before moving to advanced topics
    • βœ“ Practice with previous year questions to understand exam patterns
    • βœ“ Review short notes regularly for quick revision before exams

    Related Topics in Formal Languages and Automata Theory

    More Resources

    Why Choose MastersUp?

    🎯

    AI-Powered Plans

    Personalized study schedules based on your exam date and learning pace

    πŸ“š

    15,000+ Questions

    Verified questions with detailed solutions from past papers

    πŸ“Š

    Smart Analytics

    Track your progress with subject-wise performance insights

    πŸ”–

    Bookmark & Revise

    Save important questions for quick revision before exams

    Start Your Free Preparation β†’

    No credit card required β€’ Free forever for basic features