Regular expression for strings ending in ab

December 4, 2026 · Team EasyExamNotes · 1 min read (est.) · 0 comments

Share on WhatsApp

← RGPV CS-501 Theory of Computation December 2025 Solved Question Paper

Question

Give a regular expression over {a,b} for all strings ending in ab.

Asked in: CS-501 | December 2025 | 3(b)

Answer

The required expression is (a+b)*ab, equivalently (a|b)*ab. The star allows any finite prefix, including ε, while the final concatenation forces the last two symbols to be a followed by b.

Proof

Every word generated by the expression has the form uab with u∈{a,b}*. Hence it ends in ab. Conversely every word ending in ab can be split into a prefix u and the suffix ab, so it is generated by the expression. Both inclusions establish equality.

Accepted Rejected
ab, aab, bab, abab ε, a, ba, abb

An equivalent DFA tracks the longest suffix that is a prefix of ab: q₀ (none), q₁ (a), q₂ (ab). Only q₂ accepts. On a all states go to q₁; on b, q₀ goes to q₀, q₁ to q₂ and q₂ to q₀. This verifies the expression independently.

Regular expression for strings ending in ab diagram
Regular expression for strings ending in ab — original illustration

← RGPV CS-501 Theory of Computation December 2025 Solved Question Paper

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion