Back to the 2024 paper

Module 1: Introduction & Regular Languages

20242m

Which of these represents a regular language?

(i) {anbn∣n≥0}\{ a^n b^n \mid n \ge 0 \}
(ii) Strings with equal number of aa’s and bb’s
(iii) {an∣n is prime}\{ a^n \mid n \text{ is prime} \}
(iv) {w∣w starts with ’a’ and ends with ’b’}\{ w \mid w \text{ starts with 'a' and ends with 'b'} \}

Worked SolutionAI Assisted

Answer

Correct Option: (iv) {w∣w starts with ’a’ and ends with ’b’}\{ w \mid w \text{ starts with 'a' and ends with 'b'} \}

Explanation

Test each:

  • (i) {anbn}\{a^n b^n\} → Not regular (needs stack, CFL).
  • (ii) Equal number of aa's and bb's → {w∣#a=#b}\{ w \mid \#_a = \#_b \} not regular (needs counting). Pumping fails.
  • (iii) {an∣n prime}\{a^n \mid n \text{ prime}\} → Not regular (non-periodic), also not CFL.
  • (iv) Starts with a and ends with b → Regular.

DFA for (iv): 3 states

  • q0q_0 start (no symbol yet, non-accepting)
  • q1q_1 = last symbol a? Actually needs start a, so q0→aq1q_0 \xrightarrow{a} q_1, q0→bqdeadq_0 \xrightarrow{b} q_{dead}.
  • q1q_1 = seen start a, last is a (non-accepting)
  • q2q_2 = seen start a, last is b (accepting)
    Transitions: q1→aq1q_1 \xrightarrow{a} q_1, q1→bq2q_1 \xrightarrow{b} q_2, q2→aq1q_2 \xrightarrow{a} q_1, q2→bq2q_2 \xrightarrow{b} q_2.

Regular expression: a(a+b)∗ba(a+b)^*b (plus handle length 1? Actually abab inclusive). More precisely aΣ∗ba\Sigma^*b.

Hence regular.

Final Answer

Only (iv) is regular.

Similar questions

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.