Let L1 and L2 be two languages over alphabet Σ={x,y} as given below: L1=Set of…

2026

Let L1 and L2 be two languages over alphabet Σ={x,y} as given below:

L1=Set of all strings whose last two symbols are same.

L2={s1 x s2 ∣ s1, s2 ∈ {x,y} , ∣ s1 ∣ = 2 , ∣s2∣ ≥ 3}

Construct a minimum state deterministic finite automaton — DFA — for both L1 and L2. Also write the regular expression.

Show answer & explanation

Part (a): Language L₁

Regular Expression

(x+y)(xx+yy)

DFA Construction

To accept strings whose last two symbols are same, we need to remember the last two symbols.

Let the DFA be M = (Q, Σ, δ, q₀, F)

  • Q = {q₀, q₁, q₂, q₃, q₄}

  • Σ = {x, y}

  • Start state = q₀

  • Final states F = {q₃, q₄}

Transition Table

Present State

Input x

Input y

q₀

q₁

q₂

q₁

q₃

q₂

q₂

q₁

q₄

q₃

q₃

q₂

q₄

q₁

q₄

Explanation

  • q₃ corresponds to last two symbols = xx

  • q₄ corresponds to last two symbols = yy

  • Hence both are accepting states

Part (b): Language L₂

Interpretation

Strings where:

  • First two symbols are anything

  • Third symbol must be x

  • After that at least three symbols

Regular Expression

(x+y)(x+y)x(x+y)(x+y)(x+y)(x+y)

DFA Construction

Let the DFA be M = (Q, Σ, δ, q₀, F)

  • Q = {q₀, q₁, q₂, q₃, q₄, q₅, q₆, qd}

  • Σ = {x, y}

  • Start state = q₀

  • Final state F = {q₆}

Transition Table

Present State

Input x

Input y

q₀

q₁

q₁

q₁

q₂

q₂

q₂

q₃

qd

q₃

q₄

q₄

q₄

q₅

q₅

q₅

q₆

q₆

q₆

q₆

q₆

qd

qd

qd

Explanation

  • After reading two symbols, the third symbol must be x

  • If not, the machine goes to dead state qd

  • After that, at least three more symbols are required

  • Hence q₆ is the only accepting state

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Hpsc Pgt Computer Science