CleverSphere

Writing a regular expression for a language

Every regular language has many equivalent expressions. The trainer compares the languages, not the way they are written.

Rules

  • (a|b)* stands for all words
  • Ends with: (a|b)*w, starts with: w(a|b)*, contains: (a|b)*w(a|b)*
  • Check the ε case separately

Your turn

Three problems on this topic. The software checks your answer exactly.

  1. 1 · Write a regular expression
  2. 2
  3. 3

Give a regular expression over {a, b} for: All words ending in aba.

Regular expression

| means or, * any number of times, + at least once, ε the empty word. Any equivalent expression counts.

Worked example

Give a regular expression over {a, b} for: All words ending in bab.

Worked solution

  1. 1For example: (a|b)*bab
  2. 2Any equivalent expression counts: the software compares the languages.

Typical mistake: Don’t forget the empty word: check whether ε is in the language and whether your expression produces it.

Common questions

How does the software know my expression is right?

It builds minimal automata for both languages and compares them. That is exact, not a sample.

Related

More topics