Skip to main content
⚡ Calmops

Language Recognition and Acceptance

Introduction

Language recognition is the process of determining whether a given string belongs to a language. This is a fundamental problem in computer science with applications in:

  • Lexical analysis in compilers
  • Pattern matching
  • Input validation
  • Protocol verification
  • Formal verification

In this article, we’ll explore how automata recognize languages and the concepts of acceptance and rejection.

Finite Automata

Definition of Finite Automaton

A finite automaton is a mathematical model consisting of:

  1. States: A finite set of states
  2. Alphabet: A finite set of input symbols
  3. Transitions: Rules for moving between states
  4. Start state: The initial state
  5. Accept states: States that indicate acceptance

Formal Definition:

M = (Q, Σ, δ, q₀, F)
Q = set of states
Σ = alphabet
δ = transition function
q₀ = start state
F = set of accept states

Deterministic Finite Automaton (DFA)

A DFA has exactly one transition for each state-symbol pair.

Transition Function:

δ: Q × Σ → Q
δ(q, a) = q' (unique next state)

Example:

Language: {a*b*}

States: q0, q1, q2
Alphabet: {a, b}
Start: q0
Accept: q0, q1, q2

Transitions:
δ(q0, a) = q0
δ(q0, b) = q1
δ(q1, b) = q1
δ(q1, a) = q2 (error state)
δ(q2, *) = q2 (error state)

Non-Deterministic Finite Automaton (NFA)

An NFA can have zero, one, or multiple transitions for each state-symbol pair.

Transition Function:

δ: Q × Σ → P(Q)
δ(q, a) = {q₁, q₂, ...} (set of possible next states)

Example:

Language: {a*b, a*bb}

States: q0, q1, q2, q3
Alphabet: {a, b}
Start: q0
Accept: q2, q3

Transitions:
δ(q0, a) = {q0}
δ(q0, b) = {q1, q2}
δ(q1, b) = {q3}

Epsilon Transitions

NFAs can have epsilon (ε) transitions, which don’t consume input.

Example:

Language: {a, b}*

States: q0, q1, q2
Alphabet: {a, b}
Start: q0
Accept: q2

Transitions:
δ(q0, a) = {q1}
δ(q0, b) = {q1}
δ(q1, ε) = {q0, q2}

Acceptance and Rejection

Definition of Acceptance

A string is accepted by an automaton if:

  1. Starting from the start state
  2. Reading the string symbol by symbol
  3. Following transitions
  4. The automaton ends in an accept state

Notation:

M accepts w if δ*(q₀, w) ∈ F

Definition of Rejection

A string is rejected if:

  1. The automaton ends in a non-accept state, or
  2. No valid transition exists (for DFA)

Language Accepted by Automaton

The language accepted by an automaton M is:

L(M) = {w | M accepts w}

DFA Recognition Process

Step-by-Step Recognition

Algorithm:

1. Start at q₀
2. For each symbol in input:
   a. Find transition δ(current_state, symbol)
   b. Move to next state
3. After reading all symbols:
   a. If in accept state: ACCEPT
   b. Otherwise: REJECT

Example: Recognizing {ab}

DFA:

States: q0, q1, q2
Alphabet: {a, b}
Start: q0
Accept: q0, q1

Transitions:
δ(q0, a) = q0
δ(q0, b) = q1
δ(q1, b) = q1
δ(q1, a) = q2 (error)
δ(q2, *) = q2 (error)

Recognition of “aabb”:

Input: a a b b
State: q0 → q0 → q0 → q1 → q1
Accept: YES (ends in q1, which is accept state)

Recognition of “abab”:

Input: a b a b
State: q0 → q0 → q1 → q2 → q2
Accept: NO (ends in q2, which is not accept state)

NFA Recognition Process

Subset Construction

To recognize strings with an NFA, we track all possible states.

Algorithm:

1. Start with {q₀}
2. For each symbol in input:
   a. Compute all possible next states
   b. Include ε-closure
3. After reading all symbols:
   a. If any state in set is accept state: ACCEPT
   b. Otherwise: REJECT

Example: Recognizing {ab, abb}

NFA:

States: q0, q1, q2, q3
Alphabet: {a, b}
Start: q0
Accept: q2, q3

Transitions:
δ(q0, a) = {q0}
δ(q0, b) = {q1, q2}
δ(q1, b) = {q3}

Recognition of “ab”:

Input: a b
States: {q0} → {q0} → {q1, q2}
Accept: YES (q2 is accept state)

Recognition of “abb”:

Input: a b b
States: {q0} → {q0} → {q1, q2} → {q3}
Accept: YES (q3 is accept state)

Recognition of “aab”:

Input: a a b
States: {q0} → {q0} → {q0} → {q1, q2}
Accept: YES (q2 is accept state)

DFA vs. NFA

Equivalence

Every NFA can be converted to an equivalent DFA.

Subset Construction Algorithm:

1. Start with DFA state {q₀}
2. For each DFA state S and symbol a:
   a. Compute δ_NFA(q, a) for all q in S
   b. Union all results
   c. Include ε-closure
   d. This is the new DFA state
3. Accept states are DFA states containing NFA accept states

Example: Converting NFA to DFA

NFA:

States: q0, q1, q2
Alphabet: {a, b}
Start: q0
Accept: q2

Transitions:
δ(q0, a) = {q0, q1}
δ(q0, b) = {q0}
δ(q1, b) = {q2}

DFA:

States: {q0}, {q0,q1}, {q0,q2}, {q0,q1,q2}
Alphabet: {a, b}
Start: {q0}
Accept: {q0,q2}, {q0,q1,q2}

Transitions:
δ({q0}, a) = {q0, q1}
δ({q0}, b) = {q0}
δ({q0,q1}, a) = {q0, q1}
δ({q0,q1}, b) = {q0, q2}
δ({q0,q2}, a) = {q0, q1}
δ({q0,q2}, b) = {q0}
δ({q0,q1,q2}, a) = {q0, q1}
δ({q0,q1,q2}, b) = {q0, q2}

Complexity Comparison

Aspect DFA NFA
States O(2^n) O(n)
Transitions O(n) O(n)
Recognition O(n) O(n²)
Construction Complex Simple

Minimization

DFA Minimization

Minimization reduces the number of states in a DFA while preserving the language.

Algorithm:

1. Remove unreachable states
2. Merge equivalent states
3. Repeat until no more merges possible

Equivalence: Two states are equivalent if:

  • Both are accept or both are non-accept
  • For all symbols, transitions lead to equivalent states

Example: Minimizing a DFA

Original DFA:

States: q0, q1, q2, q3, q4
Transitions:
δ(q0, a) = q1
δ(q0, b) = q2
δ(q1, a) = q3
δ(q1, b) = q4
δ(q2, a) = q3
δ(q2, b) = q4
δ(q3, a) = q3
δ(q3, b) = q3
δ(q4, a) = q4
δ(q4, b) = q4
Accept: q3, q4

Minimized DFA:

States: q0, q1, q2, q3
Transitions:
δ(q0, a) = q1
δ(q0, b) = q2
δ(q1, a) = q3
δ(q1, b) = q3
δ(q2, a) = q3
δ(q2, b) = q3
δ(q3, a) = q3
δ(q3, b) = q3
Accept: q3

Glossary

  • Finite automaton: Machine with finite states
  • Deterministic: Unique next state for each input
  • Non-deterministic: Multiple possible next states
  • Acceptance: String ends in accept state
  • Rejection: String ends in non-accept state
  • Language: Set of accepted strings
  • Transition: Rule for moving between states
  • Accept state: State indicating acceptance
  • Epsilon transition: Transition without consuming input
  • Minimization: Reducing number of states

Practice Problems

Problem 1: DFA Recognition

Given DFA:

States: q0, q1, q2
Alphabet: {a, b}
Start: q0
Accept: q2

Transitions:
δ(q0, a) = q1
δ(q0, b) = q0
δ(q1, a) = q1
δ(q1, b) = q2
δ(q2, a) = q2
δ(q2, b) = q2

Determine if “aab” is accepted.

Solution:

Input: a a b
State: q0 → q1 → q1 → q2
Accept: YES (ends in q2)

Problem 2: NFA Recognition

Given NFA:

States: q0, q1, q2
Alphabet: {a, b}
Start: q0
Accept: q2

Transitions:
δ(q0, a) = {q0, q1}
δ(q0, b) = {q0}
δ(q1, b) = {q2}

Determine if “aab” is accepted.

Solution:

Input: a a b
States: {q0} → {q0,q1} → {q0,q1} → {q0,q2}
Accept: YES (q2 is in final set)

Problem 3: DFA Design

Design a DFA for language {ab}.

Solution:

States: q0, q1, q2
Alphabet: {a, b}
Start: q0
Accept: q0, q1

Transitions:
δ(q0, a) = q0
δ(q0, b) = q1
δ(q1, b) = q1
δ(q1, a) = q2 (error)
δ(q2, *) = q2

Problem 4: NFA to DFA

Convert the NFA from Problem 2 to a DFA.

Solution:

DFA States: {q0}, {q0,q1}, {q0,q2}, {q0,q1,q2}
Start: {q0}
Accept: {q0,q2}, {q0,q1,q2}

Transitions:
δ({q0}, a) = {q0, q1}
δ({q0}, b) = {q0}
δ({q0,q1}, a) = {q0, q1}
δ({q0,q1}, b) = {q0, q2}
δ({q0,q2}, a) = {q0, q1}
δ({q0,q2}, b) = {q0}
δ({q0,q1,q2}, a) = {q0, q1}
δ({q0,q1,q2}, b) = {q0, q2}

Online Platforms

Interactive Tools

  • “Introduction to Automata Theory, Languages, and Computation” by Hopcroft, Motwani, Ullman
  • “Theory of Computation” by Sipser
  • “Elements of the Theory of Computation” by Lewis & Papadimitriou
  • “Formal Languages and Their Relation to Automata” by Hopcroft & Ullman
  • “Computability and Complexity” by Papadimitriou

Academic Journals

Software Tools

Conclusion

Language recognition is a fundamental concept in computer science:

  • DFAs provide efficient recognition with O(n) time
  • NFAs are easier to construct but require conversion
  • Minimization reduces complexity
  • Acceptance is determined by reaching accept states

Understanding language recognition is essential for compiler design, pattern matching, and formal language theory.

In the next article, we’ll explore computability and decidability, which extend these concepts to more powerful models of computation.


Next Article: Computability and Decidability

Previous Article: Chomsky Hierarchy

Comments