chapter

    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 , denoted as , is the set of all states reachable from using zero or more (epsilon) transitions.

    Rules for Calculation

    1. The state is always in its own epsilon-closure.
    2. If state is in the epsilon-closure, and there is an -transition from to , then is also added.
    3. Repeat step 2 until no new states can be added.

    Example

    q0 epsilon q1 epsilon q2

    If and , then the combined epsilon-closure starting from is .

    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 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 . How many failure transitions in this incorrect DFA go to 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 , where 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 has states, the minimal DFA for the complement of also has exactly 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 has states, the minimal DFA for the complement of also has exactly 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 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 corresponding to suffix lengths . If the DFA is in and receives a "1", it transitions to . If the DFA is in and receives a "0", it transitions to . Which of the following correctly ranks and ?

    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 that end with a specific pattern of length , 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 ?

    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.

    Explore complete test series, official past papers, and chapter-wise study tools.

    Why MastersUp

    Personalised first. High quality throughout.

    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 , denoted as , is the set of all states reachable from using zero or more (epsilon) transitions.

    Rules for Calculation

    1. The state is always in its own epsilon-closure.
    2. If state is in the epsilon-closure, and there is an -transition from to , then is also added.
    3. Repeat step 2 until no new states can be added.

    Example

    q0 epsilon q1 epsilon q2

    If and , then the combined epsilon-closure starting from is .

    The Subset Construction Algorithm

    Step-by-Step Method

    Step 1: Start State
    The start state of the DFA, , is of the NFA.
    Step 2: Transition Function
    For each DFA state and each input symbol :
    1. Find all states reachable from any state in on input . Let this be .
    2. Compute .
    3. Add a transition in the DFA from to on input .
    Step 3: Iterate
    If 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 is a final state if (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 Computation MCQ

    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?

    1. A.

      Both A and R are true, and R is the correct explanation of A

    2. B.

      Both A and R are true, but R is NOT the correct explanation of A

    3. C.

      A is true but R is false

    4. 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 .
    • Assertion A is true.

    Step 2: Verify Reason (R):

    • In the DFA, from state (remainder 0), reading input 0 gives , so we stay in .
    • This means 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 ).
    • The full regex comes from state elimination, which involves eliminating and , not just the self-loop on .
    • R is true but does NOT fully explain A.

    Answer: B

    Question 2 · Theory of Computation MCQ

    When designing a minimal DFA for strings over 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 . How many failure transitions in this incorrect DFA go to when they should actually go to an intermediate state?

    1. A.

      1

    2. B.

      2

    3. C.

      3

    4. 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 .

    Step 1: The correct minimal DFA for "ends with 010" has 4 states: (), (0), (01), (010).

    Step 2: Analyze the correct failure transitions (where the input does not advance the match):

    • At (have "0"), input "0": The string ends in "00". The longest suffix that is a prefix of "010" is "0". Correct transition: .
    • At (have "01"), input "1": The string ends in "011". The longest suffix is . Correct transition: .
    • At (have "010"), input "1": The string ends in "0101". The longest suffix is . Correct transition: .
    • At (have "010"), input "0": The string ends in "0100". The longest suffix is "0". Correct transition: .

    Step 3: The student's incorrect DFA sends all failures to . We compare:

    • on "0": Student goes to . Correct is . (1 incorrect transition)
    • on "0": Student goes to . Correct is . (1 incorrect transition)

    Step 4: Total incorrect transitions = 2.

    Answer: B

    Question 3 · Theory of Computation MCQ
    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 , where is the number of states in the NFA. Which of the following is correct?
    1. A.

      Both A and R are true, and R is the correct explanation of A

    2. B.

      Both A and R are true, but R is NOT the correct explanation of A

    3. C.

      A is true but R is false

    4. 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 , not . Step 1: Evaluate Assertion (A): An NFA with 5 states can have a DFA with at most states. So A is true (it can have 32 states; this is the maximum). Step 2: Evaluate Reason (R): R claims the maximum is . For , . The correct formula is , not . So R is false. Step 3: Since A is true and R is false, the answer is C. Answer: C
    Question 4 · Theory of Computation MCQ

    Consider the following statements:

    Assertion (A): If a minimal DFA for a regular language has states, the minimal DFA for the complement of also has exactly 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?

    1. A.

      Both A and R are true, and R is the correct explanation of A

    2. B.

      Both A and R are true, but R is NOT the correct explanation of A

    3. C.

      A is true but R is false

    4. 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, . 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 Computation MCQ

    Consider the following statements:

    Assertion (A): If a minimal DFA for a regular language has states, the minimal DFA for the complement of also has exactly 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?

    1. A.

      Both A and R are true, and R is the correct explanation of A

    2. B.

      Both A and R are true, but R is NOT the correct explanation of A

    3. C.

      A is true but R is false

    4. 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, . 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 Computation NAT

    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 :

    • Length 0: (1 string)
    • Length 1: (2 strings)
    • Length 2: (4 strings)
    • Total universe = strings.

    Step 2: Count strings in of length :

    • Length 0: (from both and , but count once) = 1
    • Length 1: $0$ (from ), $1$ (from ) = 2
    • Length 2: $00$ (from ), $11$ (from ) = 2
    • Total in language = strings.

    Step 3: Strings NOT in language = Universe - In language = .

    Step 4: Verify: The 2 strings not in are $01$ and $10$ (both length 2).

    Answer: 2.00

    Question 7 · Theory of Computation MCQ

    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?

    1. A.

      Statement I only

    2. B.

      Statements I and III only

    3. C.

      Statements II and III only

    4. 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 Computation MCQ

    A DFA is designed to accept strings over 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 corresponding to suffix lengths . If the DFA is in and receives a "1", it transitions to . If the DFA is in and receives a "0", it transitions to . Which of the following correctly ranks and ?

    1. A.

    2. B.

    3. C.

    4. D.

      and 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 , 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 .

    Step 3: The DFA is in , 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 .

    Step 5: Compare and : , so .

    Answer: A

    Question 9 · Theory of Computation MCQ

    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$?

    1. A.

      2

    2. B.

      3

    3. C.

      4

    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 Computation MCQ

    When designing a minimal DFA for strings over that end with a specific pattern of length , 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 ?

    1. A.

    2. B.

    3. C.

    4. D.

    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 .

    Step 2: represents the empty suffix (length 0). represents a suffix of length 1. represents the full pattern (length ).

    Step 3: The number of states in this chain is the number of integers from $0$ to , inclusive. This is exactly .

    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.

    Answer: B

    More notes in this unit