Theory of Computation & Computer Graphics β Introduction to Finite Automata, NEC licence examination syllabus (Nepal Engineering Council).
Finite Automata and Finite State Machine
The simplest useful model of computation β a machine with no memory beyond knowing which state it is in.
π Where this lives: Finite automata are running in every text editor's find function, every network protocol implementation, and every lexical analyser in every compiler. When you type a regular expression into a search box, the engine compiles it into a finite automaton and runs your text through it one character at a time. The reason it is fast is exactly the property this topic describes: the machine holds no memory of what it has read, only which state it is in, so processing each character takes constant time regardless of how much text preceded it. Search "finite automata lexical analysis regular expression engine".
Definition and the two varieties
A FINITE AUTOMATON IS A MACHINE WITH A FINITE NUMBER OF STATES
THAT READS AN INPUT STRING ONE SYMBOL AT A TIME AND CHANGES STATE
ACCORDING TO WHAT IT READS.
THE DEFINING LIMITATION, from which everything follows:
ITS ONLY MEMORY IS ITS CURRENT STATE. It cannot count
beyond the number of states it has, cannot store the input,
and cannot look back at what it has already read.
ββ THE FORMAL DEFINITION βββββββββββββββββββββββββββββββββββ
A DETERMINISTIC FINITE AUTOMATON (DFA) is a 5-tuple
M = (Q, Ξ£, Ξ΄, qβ, F)
Q a FINITE set of STATES
Ξ£ a finite INPUT ALPHABET
Ξ΄ the TRANSITION FUNCTION, Ξ΄ : Q Γ Ξ£ β Q
qβ the START STATE, qβ β Q
F the set of ACCEPTING (final) STATES, F β Q
"DETERMINISTIC" IS ENTIRELY CONTAINED IN THE TYPE OF Ξ΄: for
EVERY state and EVERY symbol there is EXACTLY ONE next state.
No choice, no ambiguity, and no missing transition.
ACCEPTANCE: the automaton starts in qβ, consumes the whole
input, and ACCEPTS if and when it finishes it is in a state
belonging to F. The set of all strings it accepts is the
LANGUAGE OF M, written L(M).
ββ NON-DETERMINISTIC FINITE AUTOMATON (NFA) ββββββββββββββββ
Same 5-tuple, with one change:
Ξ΄ : Q Γ Ξ£ β P(Q) (the POWER SET of Q)
So a transition leads to a SET of possible states β possibly
empty, possibly several. An NFA may also have Ξ΅-TRANSITIONS,
changing state without consuming any input.
ACCEPTANCE FOR AN NFA: the string is accepted IF THERE EXISTS
AT LEAST ONE PATH through the machine that consumes the whole
input and ends in an accepting state.
THE USEFUL MENTAL MODEL: the NFA explores ALL possible paths
SIMULTANEOUSLY and accepts if ANY of them succeeds. It is a
machine that guesses correctly whenever a correct guess
exists.
THE CENTRAL RESULT, developed fully in the next topic:
DFAs AND NFAs RECOGNISE EXACTLY THE SAME CLASS OF
LANGUAGES. Non-determinism adds CONVENIENCE, not POWER.
ββ REPRESENTATIONS βββββββββββββββββββββββββββββββββββββββββ
TRANSITION DIAGRAM β states as circles, transitions as
labelled arrows, the start state marked by an incoming
arrow, accepting states drawn as DOUBLE CIRCLES.
TRANSITION TABLE β rows are states, columns are symbols,
entries are the next state.
THE 5-TUPLE β the formal definition itself.
A WORKED EXAMPLE: a DFA accepting binary strings with an EVEN
number of 1s.
Q = {qβ, qβ}, Ξ£ = {0,1}, F = {qβ}
Ξ΄(qβ,0)=qβ Ξ΄(qβ,1)=qβ
Ξ΄(qβ,0)=qβ Ξ΄(qβ,1)=qβ
THE STATE ENCODES THE ONLY THING THAT MATTERS: the parity of
the 1s seen so far. It does not remember how many, or where β
ONLY WHETHER THE COUNT IS ODD OR EVEN, which is exactly one
bit of memory. THAT IS THE DESIGN PRINCIPLE FOR EVERY DFA:
identify the minimal information about the prefix that
determines the future behaviour, and make that the state.
Finite state machines with output, and the limits
ββ ACCEPTORS VERSUS TRANSDUCERS ββββββββββββββββββββββββββββ
The automata above are ACCEPTORS: they answer yes or no. A
FINITE STATE MACHINE WITH OUTPUT β a TRANSDUCER β produces an
output string as it runs. Two standard forms:
MOORE MACHINE β OUTPUT DEPENDS ON THE STATE ALONE.
M = (Q, Ξ£, Ξ, Ξ΄, Ξ», qβ) with Ξ» : Q β Ξ
Each state has an output associated with it, emitted on
entry.
FOR AN INPUT OF LENGTH n, A MOORE MACHINE PRODUCES n+1
OUTPUT SYMBOLS, because the start state emits one before any
input is read.
MEALY MACHINE β OUTPUT DEPENDS ON THE STATE AND THE INPUT.
Ξ» : Q Γ Ξ£ β Ξ
Output is emitted on the TRANSITION.
FOR AN INPUT OF LENGTH n IT PRODUCES n OUTPUT SYMBOLS.
THE COMPARISON:
MOORE MEALY
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
output depends
on STATE only state AND input
output written on the state on the transition
outputs for
input length n n + 1 n
states needed generally MORE generally FEWER
reacts to input one clock later IMMEDIATELY
timing/glitches output is stable output can glitch
(synchronous with when input changes
the state)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
THEY ARE EQUIVALENT IN POWER: any Moore machine can be
converted to a Mealy machine and vice versa. The choice is
an ENGINEERING one β Mealy for fewer states and faster
response, Moore for stable, glitch-free outputs, which is
why Moore is often preferred in synchronous digital design.
ββ WHAT FINITE AUTOMATA CAN AND CANNOT DO ββββββββββββββββββ
THEY RECOGNISE EXACTLY THE REGULAR LANGUAGES β the class also
described by regular expressions and by regular grammars.
THEY CAN RECOGNISE:
Β· strings containing a given substring
Β· strings ending in a given pattern
Β· strings whose length is divisible by k
Β· strings with an even number of some symbol
Β· any language describable by a regular expression
IN GENERAL: ANYTHING REQUIRING ONLY A BOUNDED AMOUNT OF
MEMORY.
THEY CANNOT RECOGNISE:
Β· { aβΏbβΏ : n β₯ 0 } β equal numbers of a's then b's
Β· balanced parentheses
Β· palindromes
Β· { aβΏbβΏcβΏ }
IN GENERAL: ANYTHING REQUIRING UNBOUNDED COUNTING OR
MEMORY OF ARBITRARY LENGTH.
THE INTUITION FOR WHY aβΏbβΏ IS IMPOSSIBLE, which is the
argument formalised by the pumping lemma later in this
section:
A DFA has some finite number of states, say k. To accept
aβΏbβΏ it must "remember" how many a's it has read so as to
require the same number of b's. But there are infinitely
many possible counts and only k states, so BY THE PIGEONHOLE
PRINCIPLE two different counts must lead to the same state β
and once in that state the machine cannot distinguish them,
so it will accept a string with mismatched counts.
THE MEMORY IS FINITE AND THE REQUIREMENT IS NOT.
ββ WHERE THEY ARE USED βββββββββββββββββββββββββββββββββββββ
Β· LEXICAL ANALYSIS in compilers β recognising identifiers,
numbers and keywords
Β· pattern matching and regular expression engines
Β· PROTOCOL SPECIFICATION β TCP's connection state machine is
a finite automaton
Β· digital circuit design β sequential circuits ARE finite
state machines
Β· control systems: traffic lights, lifts, vending machines
Β· text processing, spell checking, and tokenising
Β· game AI and user interface state
THE COMMON THREAD: WHEREVER BEHAVIOUR DEPENDS ON A BOUNDED
AMOUNT OF HISTORY, A FINITE AUTOMATON IS THE RIGHT MODEL β
and being able to recognise that situation is the practical
value of the theory.
The design principle for constructing any DFA: identify the minimal information about the prefix read so far that determines all future behaviour, and make that the state. For "even number of 1s" that information is a single parity bit β not the count, not the positions β which is why two states suffice.
π Go further: TCP's connection handling is specified as a finite state machine, and the specification diagram β CLOSED, LISTEN, SYN-SENT, SYN-RECEIVED, ESTABLISHED, FIN-WAIT-1 and the rest β is a transition diagram of exactly the kind in this topic. Every TCP implementation in every operating system is a rendering of that automaton, which is why independently written implementations interoperate: they are all realising the same formal machine. The state is genuinely all the memory a connection endpoint has about the handshake's progress, and TIME-WAIT exists precisely because a state machine with no memory of the past needs an explicit state to represent "waiting long enough to be sure". Search "TCP state transition diagram RFC 793 finite state machine".
π‘ Exam angle: give the 5-tuple definition and state that determinism lies in Ξ΄ mapping to a single state rather than a set. Contrast the DFA and NFA transition functions and the acceptance conditions, noting that they are equivalent in power. Be able to construct a DFA for a described language and explain what each state remembers. Know both representations β diagram and table. The Moore versus Mealy comparison is frequently asked: give the output dependency, the n+1 versus n output counts, and the state-count and timing trade-off. Finally, state that finite automata recognise exactly the regular languages and explain by pigeonhole why aβΏbβΏ is beyond them.
Syllabus points
FA definition (5-tuple); transition diagram & table
DFA and NFA (NDFA)
Mealy and Moore machines
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.