Part 1/4
D = (Q, Σ, δ,
Transition Function:
D = (Q, Σ, δ,
Transition Function:
| 1 | 0 | |
|---|---|---|
Table A
| 0 | 1 | |
|---|---|---|
Table B
| 0 | 1 | |
|---|---|---|
| 0 | 1 | |
|---|---|---|
- Stars indicate accepting states
- First row is the start state

public class DFASimulator {
private static final int kNumStates = 4; // 4 states based on the table
private static final int kNumSymbols = 2; // 2 symbols (0 and 1) based on the table
private static final int[][] kTransitionTable = {
{1, 0},
{3, 2},
{3, 0},
{3, 3}
};
private static final boolean[] kAcceptTable = {
true,
false,
false,
true
};
public static boolean simulateDFA(String input) {
int state = 0;
char[] inputArray = input.toCharArray();
for (int i = 0; i < inputArray.length; i++) {
char ch = inputArray[i];
if (ch != '0' && ch != '1') {
throw new IllegalArgumentException("Invalid input symbol: " + ch);
}
state = kTransitionTable[state][ch - '0'];
}
return kAcceptTable[state];
}
public static void main(String[] args) {
String testInput = "1011"; // Example input
boolean isAccepted = simulateDFA(testInput);
System.out.println("The input " + testInput + " is " +
(isAccepted ? "accepted" : "rejected") + " by the DFA.");
}
}
Part 2/4
L = { w ∈ {a,b}* | w contains aa as a substring }
L’ = { w ∈ {a,b}* | w does not contain aa as a substring }
L = { w ∈ {a,*,/} | w represents a (multi-line) Java-style comment }
L’ = { w ∈ {a,*,/} | w doesn’t represent a (multi-line) Java-style comment }
(Not A Break)
Part 3/4
An NFA is a
Structurally similar to a DFA, but represents a fundamental shift in how we'll think about computation
Deterministic: at every point, exactly one choice
Nondeterministic: machine may have multiple possible moves
has two transitions defined on 1!
Input: 01011
D = (Q, Σ, δ,
| State | 0 | 1 |
|---|---|---|
| { |
{ |
|
| { |
{ |
|
| { |
{ |
|
| { |
{ |
If an NFA needs to make a transition when none exists, that path dies and does not accept
As with DFAs:
L(N) = { w ∈ Σ
What is the language of the NFA above?
Input: b a a b b
Suppose we run on input 10110. Which are true?
Part 4/4
L = { w ∈ {0,1}
L = { w ∈ {0,1}
L = { w ∈ {0,1}
L = { w ∈ {0,1}
L = { w ∈ {a,b,c}
L = { w ∈ {a,b,c}
L = { w ∈ {a,b,c}
L = { w ∈ {a,b,c}