CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 2 · Regular Expressions & Regular Languages

Lesson 2.4.4 · Item 43 of 91

Drill: regular or not?

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. Why does |xy| ≤ p matter when proving aⁿbⁿ non-regular?
    Stuck? Peek at 2.4.3 Pumping lemma for regular languages
    • L regular ⇒ ∃p ∀w ∈ L, |w| ≥ p, ∃ xyz: |xy| ≤ p, |y| ≥ 1, ∀i ≥ 0: xyⁱz ∈ L. p = #states.
    • Game: they pick p and split; you pick w and i. Beat every split.
    • Standard picks: aᵖbᵖ; a^{p²}; aᵖbaᵖb (ww); prime q ≥ p+2 with i = q+1.
    • Necessary, not sufficient. Finite languages pass vacuously.

    Read lesson 2.4.3

  2. Is a regular language closed under reversal?
    Stuck? Peek at 2.4.1 Closure properties of regular languages
    • Closed: ∪ ∩ − complement, concat, *, ⁺, reversal, homomorphism, inverse homomorphism, quotient (by any language), prefix, suffix, substring, substitution, finite ∪/∩.
    • Not guaranteed: infinite ∪/∩, subset, superset.
    • Prove non-regular: L ∩ R non-regular (R regular) ⇒ L non-regular.

    Read lesson 2.4.1

  3. Minimal DFA states for binary numbers divisible by 6?
    Stuck? Peek at 1.1.3 DFA design patterns
    Language (|w| = k pattern)Minimal states
    starts with wk + 2
    contains w / ends with wk + 1
    |x| ≡ r mod nn
    |x| = k, |x| ≤ kk + 2
    |x| ≥ kk + 1
    #a mod m and/or #b mod nm·n (typical)
    binary value ≡ 0 mod k, k oddk
    binary ÷ 2ʲj + 1
    k-th symbol from start fixedk + 2

    Divisibility update: r ← (base·r + digit) mod k.

    Read lesson 1.1.3

The Hook

In the exam you don’t write pumping proofs. You see a list of 4 languages and must tick the regular ones in about a minute. The skill is intuition about memory: can a machine with a fixed number of states keep track of what is needed? This lesson gives you rules of thumb, then the traps where intuition lies.

Predict First

Regular or not: L = { w x wᴿ | w, x ∈ {a,b}⁺ }? (wᴿ is w reversed.)

Core Concept

Prediction check

Regular! Choose w to be just the first symbol: if a string starts and ends with the same symbol and has length ≥ 3, take w = that symbol and x = the middle. Conversely any such string starts and ends with the same symbol. So L = a(a+b)⁺a + b(a+b)⁺b. The famous trap: “wᴿ” looks like it needs memory, but x can absorb everything.

abbbaw = ax = bbbwᴿ = a
wxwᴿ with x ∈ Σ⁺: shrink w to one symbol and let x absorb the rest.

Rule 1 — bounded facts are regular

Counts modulo a constant, the last k symbols, whether a pattern has appeared, a count capped at a constant (“at least 3 a’s”, “at most 5”): all regular.

remainder
#a mod 3, length mod 7
flags
has aa appeared?
last k symbols
ends with 011
capped count
at least 3 a’s
bounded difference
|#a − #b| ≤ 2 on every prefix
Bounded facts → regular.

Rule 2 — unbounded comparison is not regular

Comparing two counts (#a = #b, n ≥ m, n = 2m), matching a string with its copy or reverse (ww, wwᴿ with |w| unrestricted), squares, primes, powers of 2: not regular.

equal counts
#a = #b, aⁿbⁿ
copies
ww, wwᴿ
growing gaps
squares, primes, 2ⁿ
sums
aⁿbᵐcⁿ⁺ᵐ
Unbounded comparisons → not regular.

Rule 3 — watch for bounds and finite sets

  • { aⁿbⁿ : n ≤ 100 } is finite ⇒ regular.
  • { aⁿbᵐ : n, m ≥ 0 } — no relation ⇒ a*b*, regular.
  • { aⁿbᵐ : n + m is even } — only parity ⇒ regular.
  • { aⁿbᵐ : n ≡ m (mod 3) } ⇒ regular (track (n − m) mod 3).
languageverdictwhy
aⁿbⁿ, n ≤ 1000regularfinite
aⁿbᵐregularno relation: a*b*
aⁿbᵐ, n + m evenregularparity only
aⁿbᵐ, n ≡ m (mod 3)regular(n − m) mod 3
Bounds and remainders keep things regular.

Rule 4 — unary languages

Over a one-letter alphabet, L is regular iff the set of lengths is eventually periodic (from some point on, repeats with a fixed period). a^{2n}, a^{3n+1}, lengths ≥ 7: regular. Squares, primes, powers of 2, Fibonacci lengths: not regular.

lengths in a^{3n+2}
012345678910111213141516
lengths in a^{n²}
012345678910111213141516
Unary: regular exactly when the highlighted lengths become periodic. 3n + 2 repeats every 3; the gaps between squares keep growing.

Rule 5 — the x-absorbs-it trap

  • { wxwᴿ : w, x ∈ Σ⁺ } regular (first = last symbol, length ≥ 3).
  • { wxw : w, x ∈ Σ⁺ } regular by the same idea (first symbol reappears at the end).
  • { wwᴿx : … } and { xwwᴿ } with w ∈ Σ⁺: careful — these require an even palindrome somewhere and are NOT regular in general unless x can absorb; {wwᴿ : w ∈ Σ*} itself is not regular.
  • { ww : w ∈ {a}* } = (aa)* — regular (unary!).
languageverdict
{ wxwᴿ : w, x ∈ Σ⁺ }regular
{ wxw : w, x ∈ Σ⁺ }regular
{ wwᴿ : w ∈ Σ* }not regular
{ ww : w ∈ {a}* }regular = (aa)*
The free-middle and one-letter traps.

Rule 6 — the comparison that a DFA can still do

“#ab = #ba as substrings” is regular: in any binary string, the number of “ab” and “ba” occurrences differ by at most 1, and they are equal exactly when the first and last symbols are the same (or the string is short). Intuition can fail; when a weird comparison appears, look for such hidden structure.

abbabaabbaabba
#ab = #ba = 2 here; they differ by at most 1 in any string, and are equal exactly when the first and last symbols match. Regular.

Putting it together

Phase 2 language hierarchy
The two shells you know so far: finite inside regular. Drag to rotate; Phase 3 adds new shells outside.
  • Ask what fact must be carried: bounded → regular; an exact comparison of unbounded counts → not regular.
  • Finite languages and eventually periodic unary sets are regular.
  • A free middle x often absorbs the hard part (wxwᴿ, wxw).

Visual

         REGULAR                                  NOT REGULAR
 a*b*                                     aⁿbⁿ
 aⁿbᵐ, n+m even                           aⁿbᵐ, n ≥ m
 #a ≡ #b (mod 3)                          #a = #b
 aⁿbⁿ, n ≤ 1000  (finite)                 aⁿbⁿcⁿ
 w x wᴿ  (w,x ∈ Σ⁺)                       w wᴿ
 ww over {a}  = (aa)*                     ww over {a,b}
 a^{2n+1}                                 a^{n²}, a^{2ⁿ}, a^{prime}
 #ab = #ba                                aⁿ bᵐ cⁿ⁺ᵐ

Worked Examples

Easy

Regular? L = { aⁿbᵐ : n ≥ 3, m ≤ 2 }.

Show the full solution

Yes: aaaa*(ε + b + bb). Bounds are constants.

Medium

Regular? L = { aⁿbᵐ : n ≠ m }.

Show the full solution

No. If it were, its complement intersected with a*b* would be regular: complement ∩ a*b* = { aⁿbⁿ } — not regular. Contradiction ⇒ L not regular.

GATE-level

Which are regular? (i) { aᵐbⁿ : m, n ≥ 1, m·n is even } (ii) { aⁿbⁿ⁺¹ } ∪ { aⁿbⁿ } (iii) { w ∈ {a,b}* : every prefix has at most 2 more a’s than b’s and at most 2 more b’s than a’s } (iv) { 0ⁿ : n is a multiple of 3 or of 5 }

Show the full solution

(i) m·n even ⇔ m even or n even: parity only ⇒ regular. (ii) still ties counts (m = n or n + 1) ⇒ not regular. (iii) the difference #a − #b stays in {−2,…,2} ⇒ bounded ⇒ regular (5 states + dead). (iv) eventually periodic (period 15) ⇒ regular. Answer: (i), (iii), (iv).

GATE Traps

  • wxwᴿ with x ∈ Σ⁺ is regular; wwᴿ is not.
  • Bounded differences (|#a − #b| ≤ k on all prefixes) are regular.
  • { ww : w ∈ a* } = (aa)* is regular — unary changes everything.
  • A finite language is always regular, however “complicated” its definition.
  • Comparisons modulo a constant are regular; exact comparisons are not.

Memory Hook

Ask one question: “Could a goldfish with a fixed-size notebook do it?” Remainders, flags, last few symbols — yes. A running tally that can grow forever — no.

Connect the Dots

Phase 2 complete: regular languages have five equivalent descriptions, strong closure, algorithms for every question, and a clear boundary. Beyond that boundary are aⁿbⁿ, balanced brackets, palindromes. Phase 3 gives the machine its first unbounded memory — a stack — and meets the grammars that describe these languages.

Self-Test

  1. MSQ

    Which are regular?

    1. { aⁿbᵐ : n, m ≥ 0 }
    2. { aⁿbⁿ : n ≥ 0 }
    3. { aⁿbᵐ : n ≡ m (mod 2) }
    4. { aⁿbⁿ : 0 ≤ n ≤ 10 }
  2. MCQ

    { w x wᴿ : w, x ∈ {0,1}⁺ } is:

    1. not regular
    2. regular
    3. finite
    4. empty
  3. MSQ

    Over {a}, which are regular?

    1. { a^{n²} }
    2. { a^{3n+2} }
    3. { aⁿ : n ≥ 100 }
    4. { a^{2ⁿ} }
  4. MCQ

    { w ∈ {a,b}* : |w|ₐ = 2|w|_b } is:

    1. regular
    2. not regular
    3. finite
    4. equal to Σ*
  5. MCQ

    { w ∈ {a,b}* : #(ab) = #(ba) } (occurrences as substrings) is:

    1. regular
    2. not regular
    3. finite
    4. empty

Rule Card

  • Bounded fact (mod, flag, last k, capped count, bounded difference) ⇒ regular.
  • Exact comparison of two unbounded counts, ww, wwᴿ, squares, primes, 2ⁿ ⇒ not regular.
  • Finite ⇒ regular. Unary: regular ⇔ lengths eventually periodic.
  • wxwᴿ, wxw (x ∈ Σ⁺) regular. #ab = #ba regular. ww over one letter regular.

Concept Ledger

  • regular-or-not intuition
  • eventually periodic (unary)
  • bounded difference
  • absorbing middle (wxwᴿ)

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. It forces y to consist only of a’s.
  2. Yes.
  3. 4.

Self-test answers

  1. ACD — No relation, parity relation, finite.
    • B: Unbounded comparison.
  2. B — First symbol = last symbol, length ≥ 3.
    • A: x absorbs everything.
    • C: Infinite.
    • D: Non-empty.
  3. BC — Eventually periodic length sets.
    • A: Gaps grow.
    • D: Gaps grow.
  4. B — Intersect with a*b*: { a²ⁿbⁿ } — not regular.
    • A: Exact comparison.
    • C: Infinite.
    • D: ab not in it.
  5. A — Equivalent to: |w| ≤ 1 or first symbol = last symbol.
    • B: Looks like a comparison, but the counts differ by at most 1.
    • C: Infinite.
    • D: ε is in it.

Flashcards

  1. Is { w x wᴿ : w, x ∈ Σ⁺ } regular?
    Reveal answerYes — same first and last symbol, length ≥ 3.
  2. Is { aⁿbᵐ : n ≡ m mod 3 } regular?
    Reveal answerYes.
  3. When is a unary language regular?
    Reveal answerWhen its set of lengths is eventually periodic.
  4. Is { w : #ab = #ba } regular?
    Reveal answerYes.
  5. Is { aⁿbᵐ : n ≠ m } regular?
    Reveal answerNo (complement ∩ a*b* = aⁿbⁿ).

Exam shortcuts

  • Regular-or-not in 10 seconds: (1) finite? → regular. (2) only remainders/flags/last-k/caps? → regular. (3) two unbounded quantities compared exactly? → not regular. (4) a free middle x? → it probably absorbs the hard part → regular.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.