Finite Automata and Regular Expressions Notes for Gate Cs
Finite Automata and Regular Expressions notes for GATE CS: 43 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice question
Finite Automata and Regular Expressions notes
Chapter Roadmap: Finite Automata and Regular Expressions
1
NFA-to-DFA Conversion and State Complexity
Foundation: Subset construction, epsilon-closure, and the 2^n bound.
2
DFA Minimization and Language Equivalence
High Yield: Hopcroft's algorithm, distinguishability, and finding the minimal DFA.
3
Regular Expressions and Divisibility Languages
Core Skill: Algebraic manipulation, string counting, and modulo arithmetic automata.
4
Conversion: Finite Automata and Regular Expressions
Bridge: Arden's Theorem, state elimination method, and Thompson's construction.
5
DFA Design and Recognition of String Patterns
Application: Building automata for substrings, suffixes, and specific structural constraints.
The Core Idea: Why Convert NFA to DFA?
The Design vs. Execution Trade-off
Feature
NFA (Non-deterministic)
DFA (Deterministic)
Design Difficulty
Low (intuitive, flexible)
High (requires foresight)
Simulation Speed
Slow (requires backtracking)
Fast (exactly one transition)
Transitions per symbol
Zero, one, or multiple
Exactly one
Epsilon transitions
Allowed
Not allowed
The Bridge: The Subset Construction Algorithm systematically converts any NFA into an equivalent DFA, guaranteeing that both machines accept the exact same language.
Understanding Epsilon-Closure
Definition
The epsilon-closure of a state q, denoted as ϵ-closure(q), is the set of all states reachable from q using zero or more ϵ (epsilon) transitions.
Rules for Calculation
The state q is always in its own epsilon-closure.
If state p is in the epsilon-closure, and there is an ϵ-transition from p to r, then r is also added.
Repeat step 2 until no new states can be added.
Example
If ϵ-closure(q0)={q0,q1} and ϵ-closure(q1)={q1,q2}, then the combined epsilon-closure starting from q0 is {q0,q1,q2}.
40 more cards in this chapter
Try a question
Answer it here to see how it works. Nothing is recorded until you sign in.
Question 1
Level 1: Warm-up
Assertion (A): The regular expression for binary strings divisible by $3$ is $(0 + 1(01^0)^1)^*$.
Reason (R): In the DFA for this language, the start state $q_0$ has a self-loop on input $0$.
Which of the following is correct?
Question 2
Level 1: Warm-up
When designing a minimal DFA for strings over {0,1} that end with the pattern $010$, a student incorrectly assumes that the pattern has no overlapping prefixes and suffixes, and thus designs a DFA where every failure transition goes directly to the start state q0. How many failure transitions in this incorrect DFA go to q0 when they should actually go to an intermediate state?
Question 3
Level 1: Warm-up
Consider the following two statements:
Assertion (A): An NFA with 5 states can have an equivalent DFA with 32 states after subset construction.
Reason (R): The maximum number of states in the equivalent DFA is n2, where n is the number of states in the NFA.
Which of the following is correct?
Question 4
Level 1: Warm-up
Consider the following statements:
Assertion (A): If a minimal DFA for a regular language L has k states, the minimal DFA for the complement of L also has exactly k states.
Reason (R): Complementation modifies the transition function of the DFA, which necessitates re-evaluating the distinguishability of all state pairs.
Which of the following is correct?
Question 5
Level 1: Warm-up
Consider the following statements:
Assertion (A): If a minimal DFA for a regular language L has k states, the minimal DFA for the complement of L also has exactly k states.
Reason (R): Complementation of a language requires reversing the direction of all transitions in the DFA and swapping the final and non-final states.
Which of the following is correct?
Question 6
Level 1: Warm-up
What is the minimum number of strings of length less than or equal to $2$ over $\{0, 1\}$ that are NOT in the language $0^ + 1^$?
Question 7
Level 1: Warm-up
Consider the following statements about solving state equations using Arden's Theorem:
Statement I: The equation for the start state includes ϵ to account for the empty string.
Statement II: The equations for non-start states include ϵ as a base case.
Statement III: The final regular expression is derived by solving the equation for the final state(s) after finding the start state's regex.
Which of the above statements are TRUE?
Question 8
Level 1: Warm-up
A DFA is designed to accept strings over {0,1} ending with the pattern $010$. The states are defined by the state invariant rule, where each state remembers the longest suffix of the input that is a prefix of $010$. Let the states be q0,q1,q2,q3 corresponding to suffix lengths 0,1,2,3. If the DFA is in q2 and receives a "1", it transitions to qk. If the DFA is in q3 and receives a "0", it transitions to qm. Which of the following correctly ranks k and m?
Question 9
Level 1: Warm-up
Consider the target pattern $0101$. If the DFA is in the state representing the suffix $010$ and receives the input $1$, the new string ends in $0101$. How many distinct suffixes of this new string are also valid prefixes of the target pattern $0101$?
Question 10
Level 1: Warm-up
When designing a minimal DFA for strings over {0,1} that end with a specific pattern of length n, the method requires creating a linear chain of states representing progressive prefix matches. What is the maximum possible number of states in this chain for a pattern of length n?
Free preview ends here
Login to view the complete notes
Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.
Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.
Built around you, not around a syllabus PDF
Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.
Revision that hits your weak spots
We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.
Questions calibrated to the real exam
Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.
Notes written for recall, not for volume
Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.
One place for everything
Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.
Honest progress
No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.
Unlock the whole course
Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.
Finite Automata and Regular Expressions Notes for GATE CS
Finite Automata and Regular Expressions notes for GATE CS: 43 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.
Chapter Roadmap: Finite Automata and Regular Expressions
1
NFA-to-DFA Conversion and State Complexity
Foundation: Subset construction, epsilon-closure, and the 2^n bound.
2
DFA Minimization and Language Equivalence
High Yield: Hopcroft's algorithm, distinguishability, and finding the minimal DFA.
3
Regular Expressions and Divisibility Languages
Core Skill: Algebraic manipulation, string counting, and modulo arithmetic automata.
4
Conversion: Finite Automata and Regular Expressions
Bridge: Arden's Theorem, state elimination method, and Thompson's construction.
5
DFA Design and Recognition of String Patterns
Application: Building automata for substrings, suffixes, and specific structural constraints.
The Core Idea: Why Convert NFA to DFA?
The Design vs. Execution Trade-off
Feature
NFA (Non-deterministic)
DFA (Deterministic)
Design Difficulty
Low (intuitive, flexible)
High (requires foresight)
Simulation Speed
Slow (requires backtracking)
Fast (exactly one transition)
Transitions per symbol
Zero, one, or multiple
Exactly one
Epsilon transitions
Allowed
Not allowed
The Bridge: The Subset Construction Algorithm systematically converts any NFA into an equivalent DFA, guaranteeing that both machines accept the exact same language.
Understanding Epsilon-Closure
Definition
The epsilon-closure of a state q, denoted as ϵ-closure(q), is the set of all states reachable from q using zero or more ϵ (epsilon) transitions.
Rules for Calculation
The state q is always in its own epsilon-closure.
If state p is in the epsilon-closure, and there is an ϵ-transition from p to r, then r is also added.
Repeat step 2 until no new states can be added.
Example
If ϵ-closure(q0)={q0,q1} and ϵ-closure(q1)={q1,q2}, then the combined epsilon-closure starting from q0 is {q0,q1,q2}.
The Subset Construction Algorithm
Step-by-Step Method
Step 1: Start State The start state of the DFA, Q0, is ϵ-closure(qstart) of the NFA.
Step 2: Transition Function For each DFA state S and each input symbol a∈Σ:
Find all states reachable from any state in S on input a. Let this be T.
Compute S′=ϵ-closure(T).
Add a transition in the DFA from S to S′ on input a.
Step 3: Iterate If S′ is newly discovered, add it to the list of DFA states to be processed. Repeat Step 2 until no new states are generated.
Step 4: Final States Any DFA state S is a final state if S∩FNFA=∅ (i.e., it contains at least one final state of the NFA).
Finite Automata and Regular Expressions: Solved Questions with Step-by-Step Explanations (10 Problems)
Question 1 · Theory of ComputationMCQ
Assertion (A): The regular expression for binary strings divisible by $3$ is $(0 + 1(01^0)^1)^*$.
Reason (R): In the DFA for this language, the start state $q_0$ has a self-loop on input $0$.
Which of the following is correct?
A.
Both A and R are true, and R is the correct explanation of A
B.
Both A and R are true, but R is NOT the correct explanation of A
C.
A is true but R is false
D.
A is false but R is true
Correct Answer:
B
Step-by-Step Solution
Key idea: This tests understanding of the regex derivation process and whether the reason fully explains the assertion.
Step 1: Verify Assertion (A):
From the card, the canonical regex for binary strings divisible by 3 is indeed (0+1(01∗0)∗1)∗.
Assertion A is true.
Step 2: Verify Reason (R):
In the DFA, from state q0 (remainder 0), reading input 0 gives (2×0+0)mod3=0, so we stay in q0.
This means q0 has a self-loop on input 0.
Reason R is true.
Step 3: Check if R explains A:
R only explains the "$0$" part of the regex (the self-loop on q0).
The full regex (0+1(01∗0)∗1)∗ comes from state elimination, which involves eliminating q2 and q1, not just the self-loop on q0.
R is true but does NOT fully explain A.
Answer: B
Question 2 · Theory of ComputationMCQ
When designing a minimal DFA for strings over {0,1} that end with the pattern $010$, a student incorrectly assumes that the pattern has no overlapping prefixes and suffixes, and thus designs a DFA where every failure transition goes directly to the start state q0. How many failure transitions in this incorrect DFA go to q0 when they should actually go to an intermediate state?
A.
1
B.
2
C.
3
D.
4
Correct Answer:
B
Step-by-Step Solution
Key idea: This is a reverse-engineering question about the overlap trap. We must compare the correct failure transitions with the student's incorrect assumption that all failures go to q0.
Step 1: The correct minimal DFA for "ends with 010" has 4 states: q0 (ϵ), q1 (0), q2 (01), q3 (010).
Step 2: Analyze the correct failure transitions (where the input does not advance the match):
At q1 (have "0"), input "0": The string ends in "00". The longest suffix that is a prefix of "010" is "0". Correct transition: q1→q1.
At q2 (have "01"), input "1": The string ends in "011". The longest suffix is ϵ. Correct transition: q2→q0.
At q3 (have "010"), input "1": The string ends in "0101". The longest suffix is ϵ. Correct transition: q3→q0.
At q3 (have "010"), input "0": The string ends in "0100". The longest suffix is "0". Correct transition: q3→q1.
Step 3: The student's incorrect DFA sends all failures to q0. We compare:
q1 on "0": Student goes to q0. Correct is q1. (1 incorrect transition)
q3 on "0": Student goes to q0. Correct is q1. (1 incorrect transition)
Step 4: Total incorrect transitions = 2.
Answer: B
Question 3 · Theory of ComputationMCQ
Consider the following two statements:
Assertion (A): An NFA with 5 states can have an equivalent DFA with 32 states after subset construction.
Reason (R): The maximum number of states in the equivalent DFA is n2, where n is the number of states in the NFA.
Which of the following is correct?
A.
Both A and R are true, and R is the correct explanation of A
B.
Both A and R are true, but R is NOT the correct explanation of A
C.
A is true but R is false
D.
A is false but R is true
Correct Answer:
C
Step-by-Step Solution
Key idea: The state complexity bound for subset construction is 2n, not n2.
Step 1: Evaluate Assertion (A): An NFA with 5 states can have a DFA with at most 25=32 states. So A is true (it can have 32 states; this is the maximum).
Step 2: Evaluate Reason (R): R claims the maximum is n2. For n=5, n2=25=32. The correct formula is 2n, not n2. So R is false.
Step 3: Since A is true and R is false, the answer is C.
Answer: C
Question 4 · Theory of ComputationMCQ
Consider the following statements:
Assertion (A): If a minimal DFA for a regular language L has k states, the minimal DFA for the complement of L also has exactly k states.
Reason (R): Complementation modifies the transition function of the DFA, which necessitates re-evaluating the distinguishability of all state pairs.
Which of the following is correct?
A.
Both A and R are true, and R is the correct explanation of A
B.
Both A and R are true, but R is NOT the correct explanation of A
C.
A is true but R is false
D.
A is false but R is true
Correct Answer:
C
Step-by-Step Solution
Key idea: This tests the complementation invariant in DFA minimization. Complementation only swaps final and non-final states.
Step 1: Evaluate Assertion (A): Complementation simply swaps the final and non-final states. This does not change the distinguishability of any pair of states. Thus, the minimal DFA for the complement has the same number of states, k. Assertion (A) is true.
Step 2: Evaluate Reason (R): Complementation does not modify the transition function. It only changes the set of final states. Therefore, Reason (R) is false.
Step 3: A is true, but R is false.
Answer: A is true but R is false
Question 5 · Theory of ComputationMCQ
Consider the following statements:
Assertion (A): If a minimal DFA for a regular language L has k states, the minimal DFA for the complement of L also has exactly k states.
Reason (R): Complementation of a language requires reversing the direction of all transitions in the DFA and swapping the final and non-final states.
Which of the following is correct?
A.
Both A and R are true, and R is the correct explanation of A
B.
Both A and R are true, but R is NOT the correct explanation of A
C.
A is true but R is false
D.
A is false but R is true
Correct Answer:
C
Step-by-Step Solution
Key idea: This is a construction question about the complementation invariant.
Step 1: Evaluate Assertion (A): Complementation simply swaps the final and non-final states. This does not change the distinguishability of any pair of states. Thus, the minimal DFA for the complement has the same number of states, k. Assertion (A) is true.
Step 2: Evaluate Reason (R): Complementation does not require reversing transitions. Reversing transitions is used for constructing an NFA for the reverse of a language, not the complement. Complementation only swaps finality. Reason (R) is false.
Step 3: A is true, but R is false.
Answer: C
Question 6 · Theory of ComputationNAT
What is the minimum number of strings of length less than or equal to $2$ over $\{0, 1\}$ that are NOT in the language $0^ + 1^$?
Correct Answer:
2.00
Step-by-Step Solution
Key idea: This requires complementary counting: find the universe, count strings in the language, then subtract.
Step 1: Calculate the universe of binary strings of length ≤2:
Length 0: ϵ (1 string)
Length 1: 0,1 (2 strings)
Length 2: 00,01,10,11 (4 strings)
Total universe = 1+2+4=7 strings.
Step 2: Count strings in 0∗+1∗ of length ≤2:
Length 0: ϵ (from both 0∗ and 1∗, but count once) = 1
Length 1: $0$ (from 0∗), $1$ (from 1∗) = 2
Length 2: $00$ (from 0∗), $11$ (from 1∗) = 2
Total in language = 1+2+2=5 strings.
Step 3: Strings NOT in language = Universe - In language = 7−5=2.
Step 4: Verify: The 2 strings not in 0∗+1∗ are $01$ and $10$ (both length 2).
Answer: 2.00
Question 7 · Theory of ComputationMCQ
Consider the following statements about solving state equations using Arden's Theorem:
Statement I: The equation for the start state includes ϵ to account for the empty string.
Statement II: The equations for non-start states include ϵ as a base case.
Statement III: The final regular expression is derived by solving the equation for the final state(s) after finding the start state's regex.
Which of the above statements are TRUE?
A.
Statement I only
B.
Statements I and III only
C.
Statements II and III only
D.
Statements I, II, and III
Correct Answer:
B
Step-by-Step Solution
Key idea: This tests the bounding rules for setting up state equations in Arden's Theorem.
Step 1: Evaluate Statement I. The start state can be reached without consuming any input (the empty path). Therefore, its equation must include ϵ as a base case. Statement I is TRUE.
Step 2: Evaluate Statement II. Non-start states cannot be reached without consuming at least one input symbol. Their equations do not include ϵ. Statement II is FALSE.
Step 3: Evaluate Statement III. The goal is to find the regex for the language accepted by the FA, which means finding the paths to the final state(s). We solve for the start state first, then substitute it into the final state's equation. Statement III is TRUE.
Step 4: Statements I and III are true.
Answer: B
Question 8 · Theory of ComputationMCQ
A DFA is designed to accept strings over {0,1} ending with the pattern $010$. The states are defined by the state invariant rule, where each state remembers the longest suffix of the input that is a prefix of $010$. Let the states be q0,q1,q2,q3 corresponding to suffix lengths 0,1,2,3. If the DFA is in q2 and receives a "1", it transitions to qk. If the DFA is in q3 and receives a "0", it transitions to qm. Which of the following correctly ranks k and m?
A.
k<m
B.
k=m
C.
k>m
D.
k and m cannot be determined
Correct Answer:
A
Step-by-Step Solution
Key idea: This is a language-to-math question applying the state invariant rule to determine suffix lengths after specific transitions.
Step 1: The DFA is in q2, meaning the longest suffix is "01" (length 2). It receives "1". The string now ends in "011".
Step 2: We must find the longest suffix of "011" that is a prefix of "010". The suffixes of "011" are "1", "11", "011". None of these are prefixes of "010". The longest valid prefix is ϵ (length 0). So k=0.
Step 3: The DFA is in q3, meaning the longest suffix is "010" (length 3). It receives "0". The string now ends in "0100".
Step 4: We must find the longest suffix of "0100" that is a prefix of "010". The suffixes of "0100" are "0", "00", "100", "0100". The longest one that is a prefix of "010" is "0" (length 1). So m=1.
Step 5: Compare k and m: 0<1, so k<m.
Answer: A
Question 9 · Theory of ComputationMCQ
Consider the target pattern $0101$. If the DFA is in the state representing the suffix $010$ and receives the input $1$, the new string ends in $0101$. How many distinct suffixes of this new string are also valid prefixes of the target pattern $0101$?
A.
2
B.
3
C.
4
D.
5
Correct Answer:
B
Step-by-Step Solution
Key idea: This is a casework question applying the state invariant rule to find the intersection of suffixes and prefixes.
Step 1: The new string ends in $0101$. List all its suffixes: $0101$, $101$, $01$, $1$, $\epsilon$.
Step 2: The target pattern is $0101$. List all its prefixes: $0101$, $010$, $01$, $0$, $\epsilon$.
Step 3: Find the intersection (suffixes that are also prefixes):
$0101$: Yes (suffix and prefix).
$101$: No (not a prefix).
$01$: Yes (suffix and prefix).
$1$: No (not a prefix).
$\epsilon$: Yes (empty string is always a prefix and suffix).
Step 4: Count the valid strings in the intersection: $0101$, $01$, $\epsilon$. There are exactly 3.
Answer: B
Question 10 · Theory of ComputationMCQ
When designing a minimal DFA for strings over {0,1} that end with a specific pattern of length n, the method requires creating a linear chain of states representing progressive prefix matches. What is the maximum possible number of states in this chain for a pattern of length n?
A.
n
B.
n+1
C.
n+2
D.
2n
Correct Answer:
B
Step-by-Step Solution
Key idea: This is an observation question about the structural formula for the state count in an "ends with" DFA.
Step 1: The method for "ends with" requires creating a linear chain of states q0,q1,…,qn.
Step 2: q0 represents the empty suffix (length 0). q1 represents a suffix of length 1. qn represents the full pattern (length n).
Step 3: The number of states in this chain is the number of integers from $0$ to n, inclusive. This is exactly n+1.
Step 4: Note that unlike "starts with", the "ends with" DFA does not require an additional dead state because failures can backtrack to intermediate states in the chain.