Top Banner Ad

BCS402 — Unit 2: Regular Expressions and Languages

Table of Contents (17 sections)

BCS402 · Theory of Automata and Formal Languages · Unit 2

Regular Expressions and Languages

Unit Scope & Exam Weightage: This unit covers regular expressions, transition graphs, Kleene's theorem, Arden's theorem and the algebraic method, closure properties of regular languages, Pigeonhole principle, Pumping Lemma and its applications, decision properties, and the equivalence finite automata ↔ regular languages. AKTU asks 2-mark RE-writing and 7-mark Arden/pumping-lemma proofs.


Importance-Wise Roadmap (BCS402 Unit 2)

Priority Exact Syllabus Topic PYQ Evidence Marks Pattern Tag
1 Regular expression construction 2023-24, 2024-25, 2025-26 2m × 3 + predicted 7m Guaranteed
2 Arden's theorem / algebraic method 2024-25, 2025-26 (predicted clusters) 7m × 4 Derivation steps
3 Closure properties of regular languages 2023-24 7m Proof constructions
4 Pumping lemma & non-regularity 2023-24, 2024-25, 2025-26 (predicted) 7m Standard proof
5 Pigeonhole principle 2025-26 2m Quick marks
6 Kleene's theorem, decision properties Not directly asked Predicted Theory backup

Regular-language examiner guidance: For Arden's theorem questions, number the state equations, substitute one equation into another, and state the condition ε∉A\varepsilon\notin A before applying X=AX+B⇒X=A∗BX=AX+B\Rightarrow X=A^*B. For pumping-lemma proofs always choose w=apb2pw=a^pb^{2p}, split with ∣xy∣≤p|xy|\le p, and pump to a contradiction.


1. Regular Expressions — Syntax and Constructions

Regular expression (RE): a symbolic description of a regular language built from symbols of Σ\Sigma using the operators union (+ or ∪), concatenation and Kleene star (*). ∅\varnothing denotes the empty language and ε\varepsilon the language containing only the empty string.

Operator Meaning Precedence
* (star) zero or more repetitions highest
concatenation one string followed by another middle
+ / ∪ (union) either language lowest

1.1 Solved PYQs

PYQ (2024-25, 2 marks): "Write the regular expression for the language containing strings over {0,1} ending with 01." All strings over the alphabet, then the required suffix:

R=(0+1)∗01R=(0+1)^*01

Check: 01, 101, 00101 match; 10 does not.

PYQ (2025-26, 2 marks): "Find the shortest string not in the language of the regular expression a∗(ba)∗a^*(ba)^*." Generated strings: ε,a,aa,ba,aba,aaba,baba,…\varepsilon,a,aa,ba,aba,aaba,baba,\dots — every generated string either is all as or ends in a, and a b is always immediately followed by an a. The single symbol b cannot be generated; nor can ab. Length-1 candidates are a (in L) and b (not in L). Shortest string not in L = b (length 1).

PYQ (2023-24, 2 marks): "Give regular expressions that represent the language L of all binary strings having two consecutive 0s and two consecutive 1s over Σ={0,1}." Both substrings must occur, in either order:

R=(0+1)∗(00(0+1)∗11  +  11(0+1)∗00)(0+1)∗R=(0+1)^*\big(00(0+1)^*11\;+\;11(0+1)^*00\big)(0+1)^*

The factor in parentheses guarantees 00 then 11 or 11 then 00; arbitrary prefixes/suffixes complete the string. Examples: 0011 ✔, 110100 ✔, 0101 ✘.

Predicted (bank PRED, 2025-26, 7 marks): "Write the regular expression for (i) all strings of 0s and 1s; (ii) strings starting with 10101." (i) (0+1)∗(0+1)^*. (ii) 10101(0+1)∗10101(0+1)^* — the fixed prefix consumes exactly 10101, then any suffix is allowed.

1.2 Transition Graphs and Kleene's Theorem

A transition graph is a directed labelled graph for an automaton: vertices are states, edge (q,a)→p(q,a)\to p means δ(q,a)=p\delta(q,a)=p; start state has an incoming unlabelled arrow, finals are double circles.

Kleene's theorem: A language is regular iff it is accepted by some finite automaton iff it is described by some regular expression. The three formalisms — DFA, NFA (with ε), RE — have exactly the same expressive power.

Conversions: RE → ε-NFA by induction on operators (union branches, concatenation links, star loops); FA → RE by the state-elimination method (generalised transition graph) or Arden's equations.


2. Arden's Theorem and the Algebraic Method

Arden's theorem: If AA and BB are regular expressions over Σ\Sigma and ε∉L(A)\varepsilon\notin L(A), then the equation X=AX+BX = AX + B has the unique solution X=A∗BX = A^*B. If ε∈L(A)\varepsilon\in L(A), the solution is not unique and the method must first eliminate ε-cycles.

2.1 Worked Example A (Predicted 2024-25, 7 marks)

Predicted question: states A (start), B (final); transitions A --a→ A, A --b→ B, B --a→ B.

Write one equation per state; the final-state equation includes ε\varepsilon because the machine may stop there:

  1. A=aA+bBA = aA + bB
  2. B=aB+εB = aB + \varepsilon

From (2), by Arden: B=a∗ε=a∗B = a^*\varepsilon = a^*. Substitute into (1): A=aA+ba∗A = aA + ba^*. Apply Arden again: A=a∗ba∗A = a^*ba^*.

Regular expression = a∗ba∗a^*ba^*. Check: b, ab, bba? bba has two b's — not generated; correct, since after the first b only as occur.

2.2 Worked Example B (Predicted 2024-25, 7 marks)

Predicted: "Prove that (a+b)∗a(a+b)∗(a+b)^*a(a+b)^* is a regular language using Arden's theorem." Build a DFA: q0q_0 start (no a seen), on a→q1q_1 (final), on b→q0q_0; q1q_1 loops on both a and b (once an a has been seen the string stays accepted).

  1. q0=bq0+εq_0 = bq_0 + \varepsilon
  2. q1=aq0+(a+b)q1q_1 = aq_0 + (a+b)q_1

From (1): q0=b∗q_0 = b^*. Substitute: q1=ab∗+(a+b)q1q_1 = ab^* + (a+b)q_1. By Arden: q1=(a+b)∗ab∗q_1 = (a+b)^*ab^*, which equals (a+b)∗a(a+b)∗(a+b)^*a(a+b)^* because any trailing b* can be absorbed into the final (a+b)∗(a+b)^*. Hence the language is regular. ✔

2.3 Worked Example C (Predicted FA → RE, 7 marks)

For a DFA with q0q_0 start, q0→aq0q_0\xrightarrow{a}q_0, q0→bq1q_0\xrightarrow{b}q_1, q1→aq1q_1\xrightarrow{a}q_1, q1→bq0q_1\xrightarrow{b}q_0, q1q_1 final:

q0=aq0+bq1,q1=bq0+aq1+εq_0 = aq_0 + bq_1,\qquad q_1 = bq_0 + aq_1 + \varepsilon q1=a∗(bq0+ε)q_1 = a^*(bq_0+\varepsilon) q0=aq0+ba∗(bq0+ε)=(a+ba∗b)q0+ba∗q_0 = aq_0 + ba^*(bq_0+\varepsilon) = (a+ba^*b)q_0 + ba^* q0=(a+ba∗b)∗ba∗q_0 = (a+ba^*b)^*ba^*

RE for accepted strings =q1=a∗(b(a+ba∗b)∗ba∗+ε)= q_1 = a^*\big(b(a+ba^*b)^*ba^*+\varepsilon\big), i.e. strings ending in b with an even number of bs plus ε. This illustrates the full algebraic elimination pattern.


3. Closure Properties of Regular Languages

PYQ (2023-24, 7 marks): "Discuss closure properties (i.e. union, concatenation, complement, intersection and difference) of regular language."

Regular languages are closed under all these operations. For each, construct an automaton from the constituent DFAs M1=(Q1,Σ,δ1,q1,F1)M_1=(Q_1,\Sigma,\delta_1,q_1,F_1) and M2=(Q2,Σ,δ2,q2,F2)M_2=(Q_2,\Sigma,\delta_2,q_2,F_2):

Operation Construction Resulting language
Union L1∪L2L_1\cup L_2 Product automaton Q1×Q2Q_1\times Q_2; final if state's first component ∈F1F_1 or second ∈F2F_2 Either accepted
Intersection L1∩L2L_1\cap L_2 Product automaton; final if both components final Both accepted
Difference L1∖L2L_1\setminus L_2 Product; final if first ∈F1F_1 and second ∉F2F_2 Accepted by M1M_1 only
Complement L1‾\overline{L_1} Complete DFA; swap final and non-final states Everything not in L1L_1
Concatenation L1L2L_1L_2 ε-NFA: start of M1M_1; ε-edges from every state of F1F_1 to start of M2M_2 Split string into uvuv
Kleene star L1∗L_1^* ε-NFA: new start final, ε from new start to q1q_1 and from F1F_1 back to q1q_1 Zero or more copies
Reversal LRL^R Reverse every transition, make old start the only final String reversed

Proof template for union (7 marks): define M=(Q1×Q2,Σ,δ,(q1,q2),F)M=(Q_1\times Q_2,\Sigma,\delta,(q_1,q_2),F) with δ((p,q),a)=(δ1(p,a),δ2(q,a))\delta((p,q),a)=(\delta_1(p,a),\delta_2(q,a)) and F={(p,q)∣p∈F1 or q∈F2}F=\{(p,q)\mid p\in F_1\text{ or }q\in F_2\}. Induct on the input: after reading ww, MM is in (δ1(q1,w),δ2(q2,w))(\delta_1(q_1,w),\delta_2(q_2,w)), so MM accepts iff one of the machines accepts. The finite product state set proves regularity. Intersection/difference change only FF; complement requires M1M_1 to be deterministic and complete.


4. Pigeonhole Principle and Pumping Lemma

Pigeonhole principle (PYQ 2025-26, 2 marks): If n+1n+1 or more items are placed into nn boxes, at least one box contains two or more items. In automata theory, a DFA with kk states reading a string of length >k>k must visit some state twice (repetition ⇒ a loop).

4.1 Pumping Lemma for Regular Languages

If LL is infinite and regular, there exists a pumping length pp (number of DFA states) such that every w∈Lw\in L with ∣w∣≥p|w|\ge p can be written w=xyzw=xyz satisfying:

  1. ∣xy∣≤p|xy|\le p,
  2. ∣y∣≥1|y|\ge 1,
  3. xyiz∈Lxy^iz\in L for all i≥0i\ge 0.

Reason: the first p+1p+1 symbols force a repeated state; the block yy between the two visits is a loop that can be repeated or removed.

4.2 Solved: L={anb2n∣n≥1}L=\{a^nb^{2n}\mid n\ge1\} Is Not Regular

Predicted (bank PRED, asked 2023-24, 2024-25, 2025-26, 7 marks): "Using the pumping lemma, show that L={anb2n∣n≥1}L=\{a^nb^{2n}\mid n\ge1\} is not a regular language."

Proof (by contradiction):

  1. Assume LL is regular with pumping length pp.
  2. Choose w=apb2p∈Lw=a^pb^{2p}\in L; clearly ∣w∣=3p≥p|w|=3p\ge p.
  3. Because ∣xy∣≤p|xy|\le p, the prefix xyxy consists solely of as. Write y=aky=a^k with k≥1k\ge1.
  4. Pump with i=2i=2: xy2z=ap+kb2pxy^2z = a^{p+k}b^{2p}. For membership we need 2(p+k)=2p2(p+k)=2p, i.e. k=0k=0.
  5. But k≥1k\ge1 — contradiction. Hence LL is not regular. ∎

Alternative pick: w=apb2pw=a^pb^{2p} also breaks for i=0i=0 (ap−kb2pa^{p-k}b^{2p}, requiring 2(p−k)=2p⇒k=02(p-k)=2p\Rightarrow k=0). Always choose a string whose counting relationship is destroyed by adding symbols to only one side.

4.3 Decision Properties (syllabus topic)

Problem Decidable? Method
Is w∈L(M)w\in L(M)? Yes Simulate MM on ww
Is L(M)=∅L(M)=\varnothing? Yes Search reachable states from start to any final
Is L(M)L(M) finite? Yes Detect a reachable cycle that can reach a final state
Are L(M1)=L(M2)L(M_1)=L(M_2)? Yes Test emptiness of symmetric difference
Is L(M)⊆L(M2)L(M)\subseteq L(M_2)? Yes Test L(M1)∩L(M2)‾=∅L(M_1)\cap\overline{L(M_2)}=\varnothing

5. Exam-Ready Question Set and Practice

Model answer map

Question (source) Core answer
RE ending with 01 (2024-25, 2m) (0+1)∗01(0+1)^*01
RE with 00 and 11 (2023-24, 2m) (0+1)∗(00(0+1)∗11+11(0+1)∗00)(0+1)∗(0+1)^*(00(0+1)^*11+11(0+1)^*00)(0+1)^*
Shortest string outside a∗(ba)∗a^*(ba)^* (2025-26, 2m) b
Closure properties (2023-24, 7m) product/ε-NFA constructions table
Pigeonhole (2025-26, 2m) n+1n+1 items in nn boxes
Arden examples (predicted, 7m) numbered equations → A∗BA^*B → simplify
Pumping lemma anb2na^nb^{2n} (predicted, 7m) five-step contradiction

Practice questions (label: practice, not real PYQs)

  1. Practice: Write an RE for binary strings with an even number of 0s. (Hint: 1∗(01∗01∗)∗1^*(01^*01^*)^*.)
  2. Practice: Use Arden's theorem to convert a DFA where q0→0q0q_0\xrightarrow{0}q_0, q0→1q1q_0\xrightarrow{1}q_1, q1→0,1q1q_1\xrightarrow{0,1}q_1, q1q_1 final.
  3. Practice: Prove closure under reversal by describing the construction on transitions.
  4. Practice: Show via pigeonhole why a DFA with 3 states cannot remember a count up to 5.
  5. Practice: Use the pumping lemma to show {0i1i∣i≥0}\{0^i1^i \mid i\ge0\} is not regular.

6. Last-Night Survival Checklist (Unit 2 only)

  1. Operator precedence: * > concatenation > +; write fixed-prefix/suffix questions as prefix + Σ* + suffix.
  2. Arden's rule: X=AX+B⇒X=A∗BX=AX+B\Rightarrow X=A^*B only when ε∉A\varepsilon\notin A; number equations and substitute.
  3. Closure table: union OR, intersection AND, difference AND-NOT, complement swap finals, concatenation ε-bridge, star loop.
  4. Pumping lemma five steps: assume regular → choose ww → constrain xyxy to first block → pump → contradiction.
  5. Pigeonhole = repeated state = loop; this one sentence justifies the pumping lemma.

Final RE reminder: A regular expression answer is verified by listing one string that matches and one that does not. In pumping-lemma answers, explicitly state why yy contains only as — that single line is often the deciding step for full marks.