Unit 1: Finite Automata and Regular Languages
1. Mathematical Foundations: Alphabets, Strings, and Languages
The theory of computation investigates the fundamental capabilities and limitations of abstract computing devices. Before formalizing abstract machines, we must establish rigorous mathematical definitions for symbols, sequences, and computational problems.
1.1 Core Mathematical Definitions
- Symbol: An indivisible, atomic character, token, or digit (e.g., ).
- Alphabet (): A finite, non-empty set of symbols.
- Binary Alphabet:
- Lowercase English Alphabet:
- Decimal Alphabet:
- String (Word, ): A finite sequence of symbols chosen from an alphabet .
- Example: If , then is a string over .
- Length of a String (): The number of symbol positions in .
- If , then .
- The number of occurrences of a specific symbol in is denoted . Here, .
- Empty String ( or ): The unique string containing zero symbols. Its length is zero:
For any string , the empty string acts as the identity element under concatenation:
- Powers of an Alphabet (): The set of all strings of exact length formed from symbols of .
- If , then , , and .
- Kleene Star (): The set of all possible finite-length strings over , including the empty string:
is an countably infinite set for any non-empty alphabet . - Positive Closure (): The set of all non-empty strings over :
- Language (): A mathematical language over an alphabet is any subset of :
- Finite Language:
- Infinite Language:
- Empty Language: (contains zero strings; note that ).
1.2 Operations on Languages
Given two languages :
- Union:
- Intersection:
- Concatenation:
- Complementation:
- Reversal: , where and .
- Kleene Star of a Language: , where and .
2. Overview and Structural Components of Finite Automata
A Finite Automaton (FA) is the simplest formal computational model. It possesses a strictly bounded, finite internal memory represented by discrete states. An FA inspects a sequence of input symbols sequentially from left to right, transitioning between internal states. Because its memory cannot scale with input length, a finite automaton cannot perform arbitrary unbounded counting.
2.1 Hardware Abstraction Components
- Input Tape: A linear tape divided into cells, each storing a single symbol . The string terminates with an end-of-input marker.
- Read Head: Inspects one cell at a time and advances strictly from left to right (unidirectional, read-only). It cannot write to the tape or move backward.
- Finite Control: A set of internal states and transition logic that reads the current symbol under the head, looks up the transition function, and updates the automaton's internal state.
3. Deterministic Finite Automata (DFA)
A Deterministic Finite Automaton (DFA) is a machine in which every state has exactly one deterministic transition for each symbol of the alphabet.
3.1 Formal 5-Tuple Definition
Formally, a DFA is defined as a 5-tuple:
Where:
- : A finite, non-empty set of internal states.
- : A finite input alphabet.
- : The transition function mapping a state and an input symbol to exactly one next state:
- : The initial (start) state, where .
- : The set of final (accepting) states, where .
3.2 Extended Transition Function ()
To describe how a DFA processes entire strings rather than individual symbols, we define the extended transition function recursively:
- Basis: For the empty string :
- Induction: For any string where and :
3.3 Language Acceptance
A string is accepted by a DFA if and only if processing from the start state ends in an accepting state:
The language recognized by is:
CODE+-----------------------------------------------------------------------------------+ | DFA State Transition Diagram: Strings Ending in "01" | | | | +--------- 1 ---------+ | | | | | | v 0 1 | | | --> (( q0 )) -----> ( q1 ) -----> ((( q2 ))) | | ^ ^ | | | | | +--- 0 -----+ | | | | | | | +-------------- 1 ------------+ | | | | Alphabet: {0, 1} | Start: q0 | Accepting: {q2} | +-----------------------------------------------------------------------------------+
4. Non-Deterministic Finite Automata (NFA and -NFA)
In a Non-Deterministic Finite Automaton (NFA), the machine can transition to zero, one, or multiple next states for a given state and input symbol. Conceptually, an NFA explores all possible execution paths simultaneously in parallel (or guesses the correct path non-deterministically).
4.1 Formal Definition of an NFA
An NFA is defined as a 5-tuple:
Where:
- is the transition function mapping a state and a symbol to a subset of states (an element of the powerset ):
- Acceptance condition: A string is accepted if at least one computation path terminates in an accepting state:
4.2 NFA with -Transitions (-NFA)
An -NFA allows transitions between states spontaneously without consuming any input symbol:
-Closure Definition
For any state , the -closure of , denoted , is the set of all states reachable from by following zero or more -transitions:
- (reflexive basis).
- If and , then .
For a set of states :
5. Equivalence of DFA and NFA: The Subset Construction
A foundational theorem in automata theory (proven by Michael O. Rabin and Dana Scott, 1959) establishes that NFAs, -NFAs, and DFAs have identical computational expressive power. Every language accepted by an NFA can be accepted by an equivalent DFA.
5.1 The Subset Construction (Powerset Construction) Algorithm
Given an NFA , we construct an equivalent DFA :
- States of DFA (): Each state in the DFA represents a subset of states of the NFA:
If the NFA has states, the DFA has at most states. - Start State ():
- Transition Function (): For any DFA state and input symbol :
- Accepting States (): Any DFA state that contains at least one accepting state of the original NFA is an accepting state in the DFA:
5.2 Worst-Case State Complexity
For the language of strings over where the -th symbol from the end is a '1':
- An NFA requires only states.
- The minimal equivalent DFA strictly requires states.
This proves that non-determinism provides exponential succinctness in state representation, even though computational language power is identical.
6. Regular Languages and Closure Properties
A language is defined to be Regular if and only if there exists a finite automaton (DFA, NFA, or -NFA) such that .
6.1 Closure Properties of Regular Languages
Regular languages form a Boolean algebra closed under the following fundamental operations:
| Operation | Definition | Construction Method |
|---|---|---|
| Union () | Strings in or | Product Automaton (Cartesian Product) or -transitions joining start states. |
| Intersection () | Strings in both and | Cross-Product DFA construction where . |
| Concatenation () | Strings formed by where | Connect final states of to start state of via -transitions. |
| Complement () | In a complete DFA, swap accepting and non-accepting states: . | |
| Kleene Star () | Zero or more concatenations | Add new start/accept state with -transitions to/from existing states. |
| Reversal () | Reversed strings | Reverse all directed transition edges; swap start state and accepting states. |
| Difference () | Combine complement and intersection constructions. |
7. Finite Automata with Output: Mealy and Moore Machines
Standard DFAs and NFAs act as Language Recognizers (yielding a binary accept/reject decision). In practical hardware design (sequential circuits, parity checkers, traffic light controllers), finite state machines must generate an output sequence associated with states or transitions.
7.1 Moore Machines
In a Moore Machine, the output depends exclusively on the current state:
Where:
- : Finite output alphabet.
- : State transition function.
- : Output function mapping each state to an output symbol.
- Output Length: For an input string of length , a Moore machine produces an output sequence of length , because it emits an output symbol for the initial state before processing any input.
7.2 Mealy Machines
In a Mealy Machine, the output depends both on the current state and the current input symbol:
Where:
- : Output function mapping a state-symbol transition to an output symbol.
- Output Length: For an input string of length , a Mealy machine produces an output sequence of length .
7.3 Equivalence and Conversion Between Moore and Mealy Machines
Moore and Mealy machines are computationally equivalent: any language translation performed by a Moore machine can be performed by a Mealy machine, and vice-versa.
- Converting Moore to Mealy: Retain states and transitions; set the output of each transition edge entering state to the output assigned to state in the Moore machine:
- Converting Mealy to Moore: If a state in a Mealy machine receives transitions emitting different outputs, is split into multiple duplicate states , each dedicated to emitting a single specific output .
8. Minimization of Finite Automata
Given a regular language , there are infinitely many distinct DFAs that recognize . However, by the Myhill-Nerode Theorem, there exists a unique minimal DFA (up to state renaming/isomorphism) having the fewest possible states.
Minimizing a DFA reduces hardware circuit complexity and memory footprint in lexical analyzers (e.g., Lex/Flex).
8.1 State Equivalence Criteria
Two states are said to be equivalent () if for all possible input strings , both states lead either to an accepting state or both lead to a non-accepting state:
If there exists even one string such that while , the states are distinguishable ().
8.2 The Table-Filling Algorithm (Myhill-Nerode Minimization)
- Pre-processing (Eliminate Unreachable States): Perform a graph traversal (BFS/DFS) starting from . Discard all unreachable states.
- Step 1 (Base Case - Distinguish Accepting from Non-Accepting):
Create a triangular table of all unordered state pairs . Mark pair if one state is in and the other is not in :
- Step 2 (Inductive Marking):
Repeat until no new marks can be placed:
For every unmarked pair and every symbol :
Compute and .
If the pair is already marked, mark . - Step 3 (State Partitioning and Merging):
Any state pairs remaining unmarked at the end of the algorithm are equivalent (). Merge equivalent pairs into unified composite states to construct the minimal DFA.