Theory of Computation ยท Unit 2 ยท 8 hrs
Introduction to Finite Automata
Exam-focused notes for Introduction to Finite Automata (Theory of Computation, CSC262): what the TU syllabus asks and how it has actually been tested, with 11 solved past questions from this unit.
Introduction to Finite Automata in short
This unit introduces the finite automaton, the simplest machine model in the theory of computation, in its deterministic, non-deterministic, and epsilon-transition forms, proves that all three accept exactly the same class of languages, and closes with the two standard finite state machines that produce output.
What this unit covers
- Introduction to Finite Automata
- Introduction of Finite State Machine
- Deterministic Finite Automata (DFA)
- Notations for DFA
- Language of DFA
- Extended Transition Function of DFA
- Non-Deterministic Finite Automaton (NFA)
- Notations for NFA
- Language of NFA
- Extended Transition
- Equivalence of DFA and NFA
- Subset-Construction
- Method for reduction of NFA to DFA
- Theorems for equivalence of Language accepted by DFA and NFA
- Finite Automaton with Epsilon Transition (ฮต - NFA)
- Notations for ฮต - NFA
- Epsilon Closure of a State
- Extended Transition Function of ฮต โ NFA
- Removing Epsilon Transition using the concept of Epsilon Closure
- Equivalence of NFA and ฮต โNFA
- Equivalence of DFA and ฮต โ NFA
- Finite State Machines with output: Moore machine and Mealy Machines
Epsilon Closure of a State
2081 ยท 5 marks
Define ฮต\varepsilonฮต-closure of a state. Differentiate between Moore and Mealy machine. [5]
Show solved answerHide answer
ฮต-closure of a State and Difference Between Moore and Mealy Machine
Part 1: ฮต-closure of a State
Definition:
ฮต-closure of a state is the set of all states that can be reached from a particular state without reading any input symbol, i.e., by reading only ฮต (epsilon) transitions.
Formally, for a state q, the ฮต-closure(q) includes:
- The state
qitself - All states reachable from
qby following one or more ฮต-transitions
Example:
If state A has ฮต-transitions to B, and B has an ฮต-transition to C, then:
ฮต-closure(A) = {A, B, C}
Key Points:
- Every state is always in its own ฮต-closure.
- ฮต-closure is used when converting ฮต-NFA to DFA, where the start state of the DFA is taken as ฮต-closure of the start state of the ฮต-NFA.
Part 2: Difference Between Moore Machine and Mealy Machine
Both are finite state machines (FSMs) that produce output, but they differ in how output is generated.
| Basis | Mealy Machine | Moore Machine |
|---|---|---|
| Output depends on | Both present state and present input | Only the present state |
| Number of states | Generally fewer states | Generally more states |
| Number of outputs | For n inputs, there are n outputs | For n inputs, there are n+1 outputs |
| Output function | Function of transitions; changes when input logic on present state changes | Function of current state; changes at clock edges when state changes occur |
| Reaction speed | Reacts faster to inputs (same number of clock cycles) | Reacts slower to inputs (generally one clock cycle later) |
| Final states | No final states in Mealy machine | Final states are present in Moore machine |
| Output placement | Output is placed on transitions | Output is placed on states |
Summary
- ฮต-closure captures all states reachable via epsilon moves alone, and is fundamental to converting ฮต-NFA to DFA.
- Mealy machine produces output based on both state and input (faster, fewer states), while Moore machine produces output based only on the current state (slower, more states).
2079 ยท 5 marks
Explain the ฮต\varepsilonฮต-closure of states on an ฮต\varepsilonฮต-NFA with suitable examples. [5]
Deterministic Finite Automata
2081 ยท 5 marks
Design the DFA that accepts binary string ending with '00' and show its extended transition function for the string 111000. [5]
Show solved answerHide answer
DFA Accepting Binary Strings Ending with '00'
Given
- Alphabet: $\Sigma = {0, 1}$
- Language: $L = {w \in \Sigma^* \mid w \text{ ends with } 00}$
- Test string for extended transition function: $111000$
No numeric data missing; the problem is fully solvable.
Solution
Part 1: DFA Design
We track the relevant suffix (last two symbols). Three states suffice:
| State | Meaning |
|---|---|
| $q_0$ | Start; string is empty or does not end in a useful $0$ |
| $q_1$ | String currently ends with exactly one $0$ |
| $q_2$ | String ends with $00$ (Accepting) |
Formal 5-tuple: $$M = ({q_0, q_1, q_2},\ {0,1},\ \delta,\ q_0,\ {q_2})$$
Transition Table:
| State | 0 | 1 |
|---|---|---|
| $\to q_0$ | $q_1$ | $q_0$ |
| $q_1$ | $q_2$ | $q_0$ |
| $*q_2$ | $q_2$ | $q_0$ |
Transition Function:
- $\delta(q_0, 0) = q_1,\quad \delta(q_0, 1) = q_0$
- $\delta(q_1, 0) = q_2,\quad \delta(q_1, 1) = q_0$
- $\delta(q_2, 0) = q_2,\quad \delta(q_2, 1) = q_0$
State Diagram (description):
1 1
(loop) (self on q2 via 1 back to q0)
โโโโโโ
โ โ
โ( q0 )โโ0โโโถ( q1 )โโ0โโโถ(( q2 ))โโ0โโโถ (self loop 0)
โฒ โ โ
โโโโโโ1โโโโโโโ โ
โฒโโโโโโโโโโโโโโ1โโโโโโโโโโโโ
- $q_0$: on $1$ self-loop; on $0 \to q_1$
- $q_1$: on $0 \to q_2$; on $1 \to q_0$
- $q_2$ (accepting): on $0$ self-loop; on $1 \to q_0$
Part 2: Extended Transition Function $\delta^*(q_0, 111000)$
Definition: $$\delta^(q, \varepsilon) = q, \qquad \delta^(q, wa) = \delta(\delta^*(q, w), a)$$
| Step | Expression | Computation | Result |
|---|---|---|---|
| 0 | $\delta^*(q_0, \varepsilon)$ | base case | $q_0$ |
| 1 | $\delta^*(q_0, 1)$ | $\delta(q_0, 1)$ | $q_0$ |
| 2 | $\delta^*(q_0, 11)$ | $\delta(q_0, 1)$ | $q_0$ |
| 3 | $\delta^*(q_0, 111)$ | $\delta(q_0, 1)$ | $q_0$ |
| 4 | $\delta^*(q_0, 1110)$ | $\delta(q_0, 0)$ | $q_1$ |
| 5 | $\delta^*(q_0, 11100)$ | $\delta(q_1, 0)$ | $q_2$ |
| 6 | $\delta^*(q_0, 111000)$ | $\delta(q_2, 0)$ | $q_2$ |
Result
$$\delta^*(q_0,\ 111000) = q_2$$
Since $q_2$ is the accepting state, the string $111000$ (which ends in $00$) is accepted. The DFA design is verified correct.
2080 ยท 5 marks
Design a DFA that accepts single line and multi-line comments of the C-Language. [5]
2076 ยท 5 marks
Give the formal definition of DFA. Construct a DFA accepting all strings of {0, 1} with even number of 0's and even number of 1's. [5]
Method for reduction of NFA to DFA
2080 ยท 10 marks
What is NFA? How is it different from DFA? How is NFA to DFA conversion done? Convert the following NFA into DFA.[10]
Show solved answerHide answer
NFA to DFA: Definition, Differences, Conversion, and Worked Example
Given
The question asks for definitions and a conversion. The specific NFA to be converted was not provided in the question text (the diagram or table is missing), so the worked example below uses this standard NFA:
| State | a | b |
|---|---|---|
| โqโ | {qโ, qโ} | {qโ} |
| qโ | โ | {qโ} |
| *qโ | โ | โ |
Start state: $q_0$; Final state: $q_2$; Alphabet $\Sigma = {a, b}$; no ฮต-transitions.
Since the original NFA is missing, the theory below is given in full and the conversion is worked on this assumed NFA. In the exam, apply the same subset-construction steps to the NFA printed on your paper.
Solution
1. What is an NFA?
A Non-deterministic Finite Automaton (NFA) is a finite automaton where, for a given state and input symbol, there may be zero, one, or more next states, and ฮต-moves (transitions without consuming input) are permitted.
Formally, $M = (Q, \Sigma, \delta, q_0, F)$ where:
| Symbol | Meaning |
|---|---|
| $Q$ | Finite set of states |
| $\Sigma$ | Input alphabet |
| $\delta$ | $Q \times (\Sigma \cup {\varepsilon}) \to 2^{Q}$ |
| $q_0$ | Start state |
| $F$ | Set of final states |
A string is accepted if at least one computation path ends in a final state.
2. Difference Between NFA and DFA
| Feature | DFA | NFA |
|---|---|---|
| Transitions per (state, symbol) | Exactly one | Zero, one, or more |
| ฮต-moves | Not allowed | Allowed |
| Transition function | $\delta: Q \times \Sigma \to Q$ | $\delta: Q \times (\Sigma \cup {\varepsilon}) \to 2^{Q}$ |
| Acceptance | Unique path | Any accepting path |
| States needed | Usually more | Usually fewer |
| Ease of design | Harder | Easier |
| Language class | Regular | Regular (same power) |
Every DFA is an NFA; every NFA has an equivalent DFA.
3. NFA to DFA Conversion (Subset Construction)
- Step 1: DFA start state = $\varepsilon\text{-closure}(q_0)$.
- Step 2: For each DFA state $T$ and symbol $a$: compute $\varepsilon\text{-closure}(\text{move}(T,a))$ = a new DFA state.
- Step 3: Repeat until no new states appear.
- Step 4: A DFA state is final if it contains any NFA final state.
- Step 5: Missing transitions lead to a dead state $\emptyset$.
4. Worked Example (using the assumed NFA above)
Start state: $\varepsilon\text{-closure}(q_0) = {q_0} = A$
State $A = {q_0}$:
- On $a$: ${q_0, q_1} = B$
- On $b$: ${q_0} = A$
State $B = {q_0, q_1}$:
- On $a$: ${q_0, q_1} \cup \emptyset = {q_0, q_1} = B$
- On $b$: ${q_0} \cup {q_2} = {q_0, q_2} = C$
State $C = {q_0, q_2}$:
- On $a$: ${q_0, q_1} \cup \emptyset = {q_0, q_1} = B$
- On $b$: ${q_0} \cup \emptyset = {q_0} = A$
No new states. Final DFA Transition Table:
| DFA State | NFA States | On $a$ | On $b$ | Final? |
|---|---|---|---|---|
| โA | ${q_0}$ | B | A | No |
| B | ${q_0, q_1}$ | B | C | No |
| C | ${q_0, q_2}$ | B | A | Yes (contains $q_2$) |
Start state = $A$; Final state = $C$ (since it contains the NFA final state $q_2$). This DFA accepts all strings over ${a,b}$ ending in "$ab$".
Note on Missing Data
The actual NFA diagram or table intended by the exam was not included in the question, so the worked conversion above uses the assumed NFA. The theory portions (definition, differences, algorithm) are complete and correct regardless.
Check: the transition computations are consistent ($A\to B/A$, $B\to B/C$, $C\to B/A$), and the final state is $C$, the only subset containing $q_2$.
2078 ยท 10 marks
Give the formal definition of DFA and NFA. How NFA can be converted into equivalent DFA? Explain with suitable example.[10]
2076 ยท 5 marks
Construct a NFA accepting language of {0, 1} with each string ending with 01 and convert it into equivalent DFA. [5]
Show solved answerHide answer
NFA Accepting Strings Ending with 01, and its Equivalent DFA
Part 1: Constructing the NFA
Language: L = { w | w โ {0,1}* and w ends with 01 }
Example strings: 01, 001, 101, 0001, 1101, ...
NFA States and Design
We need 3 states:
| State | Role |
|---|---|
| q0 | Start state (reading any symbol, staying in loop) |
| q1 | Just read '0' (possible start of ending "01") |
| q2 | Just read '01' -- Final/Accept state |
NFA Transition Diagram
0,1 0 1
โโโโโโโโ โโโโโโโโ โโโโโโโโ
โ โผ โ โผ โ โผ
(q0) โโ0โโโบ (q1) โโ1โโโบ ((q2))
โฒ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
More precisely:
- q0 loops on both 0 and 1 (to consume any prefix)
- q0 on input 0 also goes to q1 (non-deterministic choice)
- q1 on input 1 goes to q2 (accept)
- q2 has no outgoing transitions
NFA Transition Table
| State | Input 0 | Input 1 |
|---|---|---|
| โq0 | {q0, q1} | {q0} |
| q1 | {} | {q2} |
| *q2 | {} | {} |
โ = start state, * = final state
Part 2: Converting NFA to Equivalent DFA (Subset Construction)
Each DFA state represents a subset of NFA states.
Step 1: Start State
DFA start state = {q0}
Step 2: Compute Transitions for Each DFA State
For {q0}:
- On 0: ฮด(q0, 0) = {q0, q1} โ new state {q0, q1}
- On 1: ฮด(q0, 1) = {q0} โ state {q0}
For {q0, q1}:
- On 0: ฮด(q0,0) โช ฮด(q1,0) = {q0,q1} โช {} = {q0, q1}
- On 1: ฮด(q0,1) โช ฮด(q1,1) = {q0} โช {q2} = {q0, q2} โ new state
For {q0, q2}:
- On 0: ฮด(q0,0) โช ฮด(q2,0) = {q0,q1} โช {} = {q0, q1}
- On 1: ฮด(q0,1) โช ฮด(q2,1) = {q0} โช {} = {q0}
Step 3: DFA Transition Table
| DFA State | On 0 | On 1 | Final? |
|---|---|---|---|
| โ A = {q0} | B = {q0,q1} | A = {q0} | No |
| B = {q0,q1} | B = {q0,q1} | C = {q0,q2} | No |
| *C = {q0,q2} | B = {q0,q1} | A = {q0} | Yes (contains q2) |
C is a final state because it contains q2 (the NFA's final state).
Step 4: DFA Transition Diagram
0 0
โโโโโโโโโโโโ โโโโโโโโโโโ
โ โผ โ โผ
(A) โโ0โโโบ (B) โโ1โโโบ ((C))
โฒ 1 โ โ
โโโโโโโโโโโโ 0 โ 1
โฒโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโ
Simplified transitions:
1 0 1
(A) โโโบ (A) (A) โโโบ (B) โโโบ (C)
(B) โโโบ (B)
(C) โโโบ (B)
(C) โโ1โโโบ (A)
Summary
- 3 DFA states are sufficient: A, B, C
- C = {q0, q2} is the only final state
- The DFA correctly accepts all strings over {0,1} that end with 01
Equivalence of DFA and NFA
2079 ยท 10 marks
Show that, for any NFA $N=(Q,\Sigma,\delta,q_0,F)$ accepting language $L=\Sigma^*$, there is a DFA $D=(Q',\Sigma',q_0',\delta',F')$ accepting the same language $L$.[10]
Extended Transition
2080.1 ยท 10 marks
Describe the extended transition function of NFA. Construct a NFA, using transition table and transition diagram, over {0, 1} that accept the string having substring 01 and ends with 1. Show the acceptance of 0111.[10]
Finite State Machines with output
2080.1 ยท 5 marks
Design a Mealy machine over {a, b} that generates output 'A' if the input string ends with aa else output 'B' if the string ends with bb. [5]
Make Unit 2 stick
Practice CSC262 with flashcards & quizzes