IAE Academy

GATE CS

Regular expressions and finite automata

Regular languages are exactly the languages that DFAs, NFAs, epsilon-NFAs and regular expressions describe. These notes cover designing and minimising DFAs, the subset construction and its state bound, removing epsilon-moves, regular-expression identities and Arden's rule, the conversions between the forms with their costs, and Moore and Mealy machines.

18 previous-year questions · 17 solved · 5 practice questions

Strings, languages and DFAs

Conventions. is the input alphabet (a finite, non-empty set of symbols), is the empty string, is the length of , and is the set of all strings over . A language is any subset of . is the complement of with respect to . Concatenation of languages is and with .

DFA. A deterministic finite automaton is a 5-tuple : a finite set of states , the alphabet , a transition function , a start state and accepting states . In these notes a DFA is complete: is total, so a non-accepting dead (trap) state is counted whenever it is needed. State counts below are for complete DFAs unless said otherwise. In transition tables, → marks the start state and * marks accepting states.

EXTENDED TRANSITION FUNCTION AND LANGUAGE

A string is accepted if the unique path it traces from ends in an accepting state; is accepted exactly when .

COMPLEMENT OF A DFA LANGUAGE

Valid only for a complete DFA. Swapping the accepting states of an NFA does not in general complement its language.

PRODUCT CONSTRUCTION (UNION, INTERSECTION, DIFFERENCE)

Run complete DFAs with and states together; states are pairs. Accept when both components accept (intersection), at least one accepts (union), the first accepts and the second does not (difference), or exactly one accepts (symmetric difference).

Minimal complete DFA sizes for common languages (alphabet with at least two symbols)

Language over {a,b} (or {0,1})

States in the minimal complete DFA

exactly

(one is the dead state)

ends with a fixed string of length

contains a fixed substring of length

starts with a fixed string of length

(one is the dead state)

number of 's

number of 's mod and number of 's mod both fixed

binary value of (most significant bit first, has value 0 and is accepted) divisible by odd

(state = remainder). For even it can be fewer: needs 3 (the language is 'ends in 00' or or ...); needs 2

the -th symbol from the right is a fixed symbol

NUMBER OF DFAS ON N STATES

For a fixed set of labelled states, a fixed start state and an alphabet of symbols: each of the transitions has choices, and is any of the subsets of . This counts machines, not languages; many machines accept the same language. Example: , gives .

Designing a DFA for a property

  1. Decide what the machine must remember about the prefix read so far (a remainder, a count capped at a limit, the longest useful suffix, a flag).

  2. Make each distinct piece of memory one state; the start state stands for the empty prefix.

  3. Write for every state and every symbol, sending impossible continuations to a dead state.

  4. Mark as accepting every state whose memory satisfies the property.

  5. Test on , on a one-symbol string and on a string that nearly satisfies the property.

WORKED EXAMPLE

Design a DFA over accepting the binary strings (most significant bit first) whose value is divisible by 3 (the empty string has value 0 and is accepted). Give its transition table.

Solution
  1. Remember the value of the prefix modulo 3, so the states are .

  2. Reading bit turns value into , so .

  3. From : bit 0 gives , bit 1 gives . From : bit 0 gives , bit 1 gives . From : bit 0 gives , bit 1 gives .

  4. Start and accepting state: . Check: (value 6) goes , accepted.

Answer: The transition table is below. Start and accepting state . Three states are needed: the three remainders are pairwise distinguishable, so 3 is minimal.

DFA for binary values divisible by 3

State

0

1

→*

NFA, epsilon-NFA and the subset construction

NFA. A nondeterministic finite automaton has : from a state on a symbol it may go to zero, one or several states. A string is accepted if some path ends in an accepting state. A missing transition means the path dies. An -NFA also allows moves that consume no input.

The -closure of a state is the set of states reachable from using -moves only (including itself). For a set of states it is the union of the closures of its members.

REMOVING EPSILON-MOVES (EPSILON-NFA TO NFA)

Same states and start state. Each new edge stands for '-moves, then , then -moves'; a state becomes accepting if an accepting state can be reached from it by -moves alone.

Subset construction (NFA or $\varepsilon$-NFA to DFA)

  1. Start state of the DFA: the -closure of (just if there are no -moves).

  2. For a DFA state and symbol : take all NFA states reachable from members of on , then take the -closure of that set. This is .

  3. Build only the subsets reachable from the start; stop when no new subset appears.

  4. A DFA state is accepting if it contains at least one NFA accepting state.

  5. If is reached it is the dead state of the DFA.

SIZE BOUND OF THE SUBSET CONSTRUCTION

The bound is tight: the language 'the -th symbol from the right is 1' has an -state NFA whose minimal DFA has states. Often far fewer subsets are reachable.

DFAs, NFAs and -NFAs accept exactly the same class of languages (the regular languages). Nondeterminism changes the number of states needed, not the power.

NFA for the example below (∅ = no move)

State

a

b

→

WORKED EXAMPLE

For the NFA over in the table above (start , accepting ), build the reachable part of the equivalent DFA.

Solution
  1. Start: .

  2. : on go to ; on go to .

  3. : on go to ; on go to .

  4. : on go to ( has no move); on go to .

  5. Only contains , so it is the only accepting state. is never reached.

Answer: Three reachable DFA states: {p}, {p,q}, {p,r}, with {p,r} accepting. The language is the set of strings ending in ab.

EXAM TIP

Before building any subset, write the transition table of the NFA once. Do the subset construction row by row from that table, and list only subsets that actually get reached; this saves time and avoids counting unreachable subsets as states.

DFA minimisation

Two states are equivalent if for every string , is accepting exactly when is accepting. Equivalent states can be merged. For a regular language the minimal complete DFA is unique up to renaming of states.

MINIMAL DFA SIZE (MYHILL–NERODE)

Each class of prefixes is one state. is regular exactly when there are finitely many classes.

Partition-refinement method

  1. Delete every state that is unreachable from the start state.

  2. Make the DFA complete (add a dead state if needed and count it).

  3. Start with two groups: accepting states and non-accepting states .

  4. Split a group whenever two of its states, on some symbol, go to different groups.

  5. Repeat until no group splits. Each final group is one state of the minimal DFA.

  6. The new start state is the group of ; a group is accepting if its members are accepting.

Table-filling method. Mark every pair with exactly one accepting member as distinguishable. Then repeatedly mark if for some symbol the pair is already marked. Unmarked pairs at the end are equivalent. Both methods give the same answer.

Equivalence of two DFAs. Two DFAs accept the same language exactly when their minimal DFAs are identical up to renaming of states. Equivalently, the product DFA for the symmetric difference reaches no accepting state from its start.

DFA for the example below

State

0

1

→

WORKED EXAMPLE

Find the number of states of the minimal DFA equivalent to the complete DFA over in the table above (start , accepting ).

Solution
  1. All five states are reachable. Initial partition: and .

  2. Refine : goes to (both in the first group) on 0 and 1, while and go into . So splits off: .

  3. Check : both go to on 0 and on 1, so they stay together. Check : both go to on both symbols, so they stay together.

  4. No group splits further.

Answer: 3 states: {A}, {B,C}, {D,E}. The language is the strings of length at least 2.

EXAM TIP

Do not count the dead state twice, and do not forget it: if the question says 'minimal DFA' without qualification, the complete DFA (with a dead state) is meant by convention here. A question that allows missing transitions will say so; then the dead state is dropped and the count is one smaller whenever a dead state was needed.

Regular expressions and their identities

Definition. Regular expressions over are built from (language ), (language ), each symbol (language ), and, for expressions : union (language ), concatenation and star . Precedence from highest to lowest: star, concatenation, union. So means . A language is regular exactly when some regular expression denotes it.

Reading a regular expression (over {a,b})

Expression

Language in words

strings ending in

strings with at least one

all strings,

strings with an even number of 's

IDENTITIES FOR $\EMPTYSET$ AND $\VAREPSILON$

Union is commutative and associative; concatenation is associative but not commutative.

IDENTITIES FOR STAR

means one or more repetitions.

STAR OF A UNION

All five denote the strings formed by any mixture of -strings and -strings. is NOT equal to .

SHIFTING IDENTITY

Both sides are followed by alternating , blocks. in general.

DISTRIBUTIVITY

Concatenation distributes over union on both sides; union does not distribute over concatenation ( in general).

ARDEN'S RULE

When the stated solution is the unique one. When it is still a solution (the smallest) but not the only one. The first form fits Arden's method below, where each equation lists the strings that reach a state.

EXAM TIP

To test an identity, try the shortest strings. because is on the left only. because is on the left only. A single counterexample string settles a false identity; a true one needs an argument.

Converting between regular expressions and automata

Regular expression to $\varepsilon$-NFA (Thompson's construction)

  1. Symbol : two states, start and accept , with one edge labelled . : the same with label . : two states and no edge.

  2. Union : a new start with -edges to the starts of both machines, and -edges from both accept states to a new accept state.

  3. Concatenation : an -edge from the accept state of to the start of .

  4. Star : a new start and accept state; -edges new start to old start, old accept to new accept, new start to new accept, and old accept back to old start.

  5. Every machine built has exactly one start and one accept state; the start state has no incoming edge and the accept state has no outgoing edge.

SIZE OF THOMPSON'S MACHINE

Linear in the length of the expression. Each symbol (, or ) and each union or star adds two states; concatenation adds none.

Automaton to regular expression (state elimination)

  1. Add a new start state with an -edge to the old start, and a new accept state with -edges from every old accepting state.

  2. Label edges with regular expressions (merge parallel edges by ).

  3. Eliminate each other state in turn: for every pair of edges and , add an edge labelled , where is the label of the loop on (omit if there is no loop); merge with any existing edge using .

  4. When only the new start and accept state remain, the label on the edge between them is the answer.

Arden's method. Write one equation per state, (plus for the start state), where means 'reach , then read the symbol on the edge '. Solve by substitution using the form . The regular expression is the sum of the solved variables of the accepting states.

DFA for the example below

State

0

1

→*

WORKED EXAMPLE

Find a regular expression for the language of the DFA over in the table above (start and accepting state ).

Solution
  1. Write the equations for the strings that reach each state: and .

  2. Apply Arden to (here , ): .

  3. Substitute into : .

  4. Apply Arden again (, , and ): . Only accepts.

Answer: , the strings with an even number of 1's.

Costs of conversions (worst case)

Conversion

Size of the result

regular expression to -NFA

linear: at most states

-NFA to NFA (remove -moves)

same number of states, possibly more edges

NFA with states to DFA

up to states (tight)

DFA to regular expression

can be exponentially larger in the worst case

complete DFA to the DFA of its complement

same number of states

Moore and Mealy machines

These are finite automata with output instead of accept/reject. Both have a finite input alphabet , an output alphabet , a transition function and a start state; the output function differs.

Moore versus Mealy

Feature

Moore machine

Mealy machine

Output function

(output attached to the state)

(output attached to the transition)

Output on input of length

symbols (the start state's output comes first)

symbols

Output on

the start state's output

empty string

Reacts to a new input symbol

after the move, in the next state

immediately, on the same transition

OUTPUT LENGTH

Holds for every input because both machines are deterministic and complete.

Equivalence. A Mealy machine and a Moore machine are equivalent when the Moore output, ignoring its first symbol, equals the Mealy output on every input. Every Moore machine converts to a Mealy machine with the same states (give each transition the output of its target state). Every Mealy machine converts to a Moore machine, but the number of states may grow, to at most (number of states) (number of distinct outputs).

Mealy machine for the example below (next state/output)

State

0

1

→

WORKED EXAMPLE

For the Mealy machine over in the table above (start ), give its output on input .

Solution
  1. Start in . Read 1: go to , output 0.

  2. Read 0: go to , output 0. Read 0: stay in , output 0.

  3. Read 1: go to , output 1. Read 1: stay in , output 0.

  4. Read 0: go to , output 0. Read 1: go to , output 1.

Answer: 0001001 (seven symbols; the machine outputs 1 exactly when a 1 follows a 0).

EXAM TIP

A Moore machine's output string is one symbol longer than the input. When a question gives the output of a Moore machine, count the extra first symbol before comparing lengths.

PREVIOUS-YEAR QUESTIONS

18 questions from the CS papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE CSE 2026 Set 1 · GATE CSE 2026 Set 2 · GATE CSE 2025 Set 1 · GATE CSE 2025 Set 2 · GATE CSE 2024 Set 1 · GATE CSE 2024 Set 2 · GATE CSE 2023 · GATE CSE 2022 · GATE CSE 2020 · GATE CSE 2018

GATE 2026 CS2 Q.47

GATE 2026 · CS2Q.47 · 2 marks · MSQ

Consider the following two finite automata and .

Which of the following statements is/are true?

GATE 2026 CS2 question 47: Two state diagrams over 0,1.Tap to open full size
Figure from the GATE 2026 CS2 paper. It is part of the question.
Figure description

Two state diagrams over 0,1. D1: five states. The start state q0 is also the only accepting state (double circle). Other states: a, b (both upper right, nearly collinear with q0), c (far upper right), d (lower right) and e (lower left, below q0). Transitions: q0 -0-> b; b -0-> a; a -0-> q0 (upper arc); a -1-> q0 (lower curve); b -1-> c; c -0-> q0 (large outer arc); q0 -1-> d; d -0-> e; e -1-> q0. D2: five states. The start state p0 is also the only accepting state. Other states: f (upper middle), g (upper right), h (middle right) and i (bottom). Transitions: p0 -0-> f; f -1-> g; g -1-> p0 (upper arc); p0 -1-> h; h -1-> g; h -0-> i; h -1-> i (curve); i -0-> p0. Every path from the start state back to it has length exactly 3.

  1. (A)

  2. (B)

    is a proper subset of

  3. (C)

  4. (D)

    consists of all strings in whose length is divisible by 3

Answer and solution
GATE 2026 CS2 Q.47: answer and solution

GATE 2025 CS1 Q.28

GATE 2025 · CS1Q.28 · 1 mark · MSQ

A regular language is accepted by a non-deterministic finite automaton (NFA) with states. Which of the following statement(s) is/are FALSE?

  1. (A)

    may have an accepting NFA with states.

  2. (B)

    may have an accepting DFA with states.

  3. (C)

    There exists a DFA with states that accepts .

  4. (D)

    Every DFA that accepts has states.

Answer and solution
See the question in the paper
GATE 2025 CS1 Q.28: answer and solution

GATE 2025 CS1 Q.50

GATE 2025 · CS1Q.50 · 2 marks · MSQ

Consider the following deterministic finite automaton (DFA) defined over the alphabet, . Identify which of the following language(s) is/are accepted by the given DFA.

GATE 2025 CS1 question 50: A DFA with four states in a row, left to right: q_0 (start, arrow entering from the left), q_1, q_2, q_3 (q_3 is…Tap to open full size
Figure from the GATE 2025 CS1 paper. It is part of the question.
Figure description

A DFA with four states in a row, left to right: q_0 (start, arrow entering from the left), q_1, q_2, q_3 (q_3 is accepting, double circle). Transitions: q_0 has a self-loop on a; q_0 → q_1 on b; q_1 has a self-loop on b; q_1 → q_2 on a; q_2 → q_3 on b; q_3 → q_2 on a (top curved arc); q_2 → q_0 on a (bottom long arc ending at q_0); q_3 → q_1 on b (bottom arc ending at q_1).

  1. (A)

    The set of all strings containing an even number of 's.

  2. (B)

    The set of all strings containing the pattern .

  3. (C)

    The set of all strings ending with the pattern .

  4. (D)

    The set of all strings not containing the pattern .

Answer and solution
GATE 2025 CS1 Q.50: answer and solution

GATE 2025 CS2 Q.60

GATE 2025 · CS2Q.60 · 2 marks · NAT

Let . For , let be the product of symbols in modulo 7. We take , where is the null string.

For example, .

Define .

The number of states in a minimum state DFA for is ___________. (Answer in integer)

Answer and solution
See the question in the paper
GATE 2025 CS2 Q.60: answer and solution

GATE 2024 CS1 Q.50

GATE 2024 · CS1Q.50 · 2 marks · MSQ

Consider the 5-state DFA accepting the language shown below. For any string let be the number of 0's in and be the number of 1's in . Which of the following statements is/are FALSE?

GATE 2024 CS1 question 50: DFA with states 1, 2, 3, 4, 5.Tap to open full size
Figure from the GATE 2024 CS1 paper. It is part of the question.
Figure description

DFA with states 1, 2, 3, 4, 5. Start state is 1, which is also the only accepting state (double circle). Transitions: 1 -0-> 2; 1 -1-> 4; 2 -0-> 3; 2 -1-> 1; 3 -0-> 1; 3 -1-> 2; 4 -0-> 1; 4 -1-> 5; 5 -0-> 4; 5 -1-> 1.

  1. (A)

    States 2 and 4 are distinguishable in M

  2. (B)

    States 3 and 4 are distinguishable in M

  3. (C)

    States 2 and 5 are distinguishable in M

  4. (D)

    Any string w with n_0(w) = n_1(w) is in L(M)

Answer and solution
GATE 2024 CS1 Q.50: answer and solution

GATE 2024 CS2 Q.22

GATE 2024 · CS2Q.22 · 1 mark · MCQ

Which one of the following regular expressions is equivalent to the language accepted by the DFA given below?

GATE 2024 CS2 question 22: A DFA with two states.Tap to open full size
Figure from the GATE 2024 CS2 paper. It is part of the question.
Figure description

A DFA with two states. The left state (call it q_0) is the start state (an arrow enters it from the left) and is not accepting. The right state (q_1) is accepting (double circle). q_0 has a self-loop labelled 0. q_1 has a self-loop labelled 0. There is an edge from q_0 to q_1 labelled 1 (upper arc) and an edge from q_1 back to q_0 labelled 1 (lower arc).

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution
GATE 2024 CS2 Q.22: answer and solution

GATE 2024 CS2 Q.41

GATE 2024 · CS2Q.41 · 2 marks · MCQ

Let be the 5-state NFA with -transitions shown in the diagram below. Which one of the following regular expressions represents the language accepted by ?

GATE 2024 CS2 question 41: States 1 to 5.Tap to open full size
Figure from the GATE 2024 CS2 paper. It is part of the question.
Figure description

States 1 to 5. State 1 is the start state (arrow entering from the left). States 2 and 5 are accepting (double circles). Transitions: 1 --ε--> 2; 1 --ε--> 4; 2 --0--> 3; 3 --0--> 2; 3 --ε--> 5; 4 --1--> 5; 5 --1--> 4.

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution
GATE 2024 CS2 Q.41: answer and solution
Show the other 8 questions

GATE 2023 CS Q.14

GATE 2023 · CSQ.14 · 1 mark · MCQ

Consider the Deterministic Finite-state Automaton (DFA) shown below. The DFA runs on the alphabet , and has the set of states , with being the start state and being the only final state.

Which one of the following regular expressions correctly describes the language accepted by ?

GATE 2023 CS question 14: State diagram with states s, p, q, r.Tap to open full size
Figure from the GATE 2023 CS paper. It is part of the question.
Figure description

State diagram with states s, p, q, r. Start state s (arrow entering from the left). p is the only accepting state (double circle). Transitions: s --1--> p; s --0--> r; p --0--> p (self-loop); p --1--> q; q --1--> p; q --0--> r; r --0,1--> r (self-loop, r is a dead state).

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution
GATE 2023 CS Q.14: answer and solution

GATE 2023 CS Q.19

GATE 2023 · CSQ.19 · 1 mark · MCQ

Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions:

letter → [A-Za-z]
digit → [0-9]
id → letter (letter | digit)*

Which one of the following Non-deterministic Finite-state Automata with ε-transitions accepts the set of valid identifiers? (A double-circle denotes a final state)

GATE 2023 CS question 19: Four NFAs with ε-transitions, each starting from a start state (arrow in).Tap to open full size
Figure from the GATE 2023 CS paper. It is part of the question.
Figure description

Four NFAs with ε-transitions, each starting from a start state (arrow in). (A) Start state q0 has a 'letter' transition to a double-circle final state q1, and also an ε-transition from q0 to q1 (curved arrow below). q1 has a self-loop labelled 'letter' and 'digit'. (B) Start q0 --letter--> double-circle q1. q1 has an ε-transition to a double-circle state q2 and another ε-transition to a double-circle state q3. q2 has a self-loop labelled 'letter'; q3 has a self-loop labelled 'digit'. (C) Start q0 --letter--> double-circle q1. q1 --ε--> q2 --letter--> q3 --ε--> q5, and q1 --ε--> q4 --digit--> q6 --ε--> q5, where q5 is a non-final state with an ε-transition back to q1. (D) Start q0 --letter--> double-circle q1 --letter--> q2 --digit--> q3, and q3 has an ε-transition back to q1.

  1. (A)

    Figure — NFA (A) as described

  2. (B)

    Figure — NFA (B) as described

  3. (C)

    Figure — NFA (C) as described

  4. (D)

    Figure — NFA (D) as described

Answer and solution
GATE 2023 CS Q.19: answer and solution

GATE 2022 CS Q.12

GATE 2022 · CSQ.12 · 1 mark · MCQ

Which one of the following regular expressions correctly represents the language of the finite automaton given below?

GATE 2022 CS question 12: A DFA with three states.Tap to open full size
Figure from the GATE 2022 CS paper. It is part of the question.
Figure description

A DFA with three states. The start state q_0 (arrow entering from the left) is a non-accepting single circle. The two other states are accepting (double circles): q_1 (upper right) and q_2 (lower right). Transitions: q_0 --a--> q_1; q_1 --b--> q_0; q_1 has a self-loop labelled b; q_0 --b--> q_2; q_2 --a--> q_0; q_2 has a self-loop labelled a.

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution
GATE 2022 CS Q.12: answer and solution

GATE 2020 CS Q.7

GATE 2020 · CSQ.7 · 1 mark · MCQ

Which one of the following regular expressions represents the set of all binary strings with an odd number of 1's?

  1. (A)

    ((0 + 1)*1(0 + 1)*1)10

  2. (B)

    (0*10*10*)*0*1

  3. (C)

    10*(0*10*10*)*

  4. (D)

    (0*10*10*)10

Official answer

Official answer: marks to all candidatesSource: Official answer key, GATE 2020 CS (IIT Delhi)

See the question in the paper
GATE 2020 CS Q.7: official answer

GATE 2018 CS Q.52

GATE 2018 · CSQ.52 · 2 marks · NAT

Given a language , define as follows:


The order of a language is defined as the smallest such that . Consider the language (over alphabet 0) accepted by the following automaton. The order of is ______.

GATE 2018 CS question 52: State diagram with three states in a row.Tap to open full size
Figure from the GATE 2018 CS paper. It is part of the question.
Figure description

State diagram with three states in a row. The first state (call it q0) has an incoming start arrow and is a double circle (accepting). The second state (q1) is also a double circle (accepting). The third state (q2) is a single circle (non-accepting). Transitions: q0 --0--> q1 (arrow from first to second labelled 0); q1 --0--> q2 (upper curved arrow from second to third labelled 0); q2 --0--> q1 (lower curved arrow from third back to second labelled 0). No other transitions.

Answer and solution
GATE 2018 CS Q.52: answer and solution

OTHER EXAMS

ISRO: 5 questions

From ISRO's Scientist/Engineer written test: ISRO CS 2025, ISRO CS 2023. They are not counted in the GATE numbers on this page.

ISRO CS 2025 Q.79

ISRO 2025 · CSQ.79 · 1 mark · MCQ

Consider the deterministic finite-state automaton (DFA) below over the alphabet {a,b}. The state with a small incoming arrow is the initial state, while a double circle state denotes a final state. The number of states in the MINIMAL DFA for the language accepted by this DFA is:

ISRO CS 2025 question 79: A DFA with three states.Tap to open full size
Figure from the ISRO CS 2025 paper. It is part of the question.
Figure description

A DFA with three states. State P (single circle, non-final) is the initial state, with an incoming arrow from the left, placed top-left. State Q (double circle, final) is top-right. State R (double circle, final) is bottom-centre. Transitions: P --a--> Q; P --b--> R; Q has a self-loop labelled b; Q --a--> R; R has a self-loop labelled a,b.

  1. (A)

    1

  2. (B)

    2

  3. (C)

    3

  4. (D)

    4

Answer and solution
ISRO CS 2025 Q.79: answer and solution

ISRO CS 2023 Q.55

ISRO 2023 · CSQ.55 · 1 mark · MCQ

Consider the deterministic finite-state automaton (DFA) below. The alphabet is {a, b}. The state with a small incoming arrow is the initial state, while the double circle state denotes a final state. Which of the following regular expressions defines the language accepted by the DFA?

ISRO CS 2023 question 55: A DFA with three states.Tap to open full size
Figure from the ISRO CS 2023 paper. It is part of the question.
Figure description

A DFA with three states. The left state has a small incoming arrow (initial state). The right state is drawn with a double circle (final state) and has a self-loop labelled b. The bottom state is a single circle with a self-loop labelled a,b. Transitions: initial --a--> final (arrow to the right); initial --b--> bottom state (arrow down and to the right); final --a--> bottom state (arrow down and to the left).

  1. (A)

    ab*

  2. (B)

    a*b*

  3. (C)

    (ab)*

  4. (D)

    a*b

Answer and solution
ISRO CS 2023 Q.55: answer and solution

ISRO CS 2023 Q.56

ISRO 2023 · CSQ.56 · 1 mark · MCQ

Consider the Nondeterministic Finite-State Automaton (NFA) below. States with a small incoming arrow are initial states, while a double circle state denotes a final state. The number of states in the MINIMAL Deterministic Finite-State Automaton (DFA) for this language is:

ISRO CS 2023 question 56: An NFA with three states in a row, left to right.Tap to open full size
Figure from the ISRO CS 2023 paper. It is part of the question.
Figure description

An NFA with three states in a row, left to right. The leftmost state is initial (small incoming arrow from the left) and has a self-loop labelled a,b. A transition labelled b goes from the leftmost state to the middle state. A transition labelled a,b goes from the middle state to the rightmost state, which is drawn as a double circle (final). No other transitions.

  1. (A)

    2

  2. (B)

    4

  3. (C)

    6

  4. (D)

    8

Answer and solution
ISRO CS 2023 Q.56: answer and solution

PRACTICE

5 questions to test yourself

PRACTICE 12 marks · MCQ

Let be the set of strings over in which the number of 0's is even and the number of 1's is divisible by 3. How many states does the minimal complete DFA for have?

  1. (A)

    5

  2. (B)

    6

  3. (C)

    8

  4. (D)

    9

Answer and solution

Answer: (B)

  1. Track the pair (number of 0's mod 2, number of 1's mod 3). This gives states, all reachable; the accepting state is .

  2. Take two different pairs . Appending takes to , which accepts, and takes to , which is not because .

  3. So every two states are distinguishable, no two merge, and the minimal DFA has 6 states.

PRACTICE 22 marks · NAT

Let be the set of strings over whose 4th symbol from the right is 1 (strings shorter than 4 symbols are not in ). What is the number of states of the minimal complete DFA for ?

Answer and solution

Answer:

  1. After reading a string the machine must remember its last 4 symbols; strings shorter than 4 behave like strings padded on the left with 0's, since a missing symbol can never be the required 1.

  2. There are possible last-four patterns and all are reachable.

  3. Two different patterns differ in some position from the right (); appending symbols shifts that position into the 4th place from the right, so one string is accepted and the other is not.

  4. Hence all 16 states are distinguishable and the minimum is .

PRACTICE 31 mark · NAT

A Mealy machine over has states (start), and ; the state records the previous input symbol ( means no symbol read yet). On each input symbol it outputs 1 if the symbol equals the previous input symbol and 0 otherwise (the first symbol always gives output 0). How many 1's are in the output for the input ?

Answer and solution

Answer:

  1. Compare each symbol with the one before it: 0 (first, output 0); 1 vs 0 gives 0; 1 vs 1 gives 1; 0 vs 1 gives 0; 0 vs 0 gives 1; 1 vs 0 gives 0; 1 vs 1 gives 1.

  2. The output is 0010101, which contains three 1's.

PRACTICE 42 marks · MSQ

Over , which of the following equalities between regular expressions hold?

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution

Answer: (A), (B), (D)

  1. A holds: with .

  2. B holds: it is the shifting identity with .

  3. C fails: is in but is neither all 's nor all 's.

  4. D holds: is a concatenation of blocks each ending in , so it is or a string ending in ; conversely every string ending in splits after each of its 's into such blocks.

PRACTICE 51 mark · MCQ

An NFA over has states , start , accepting , and transitions , , , ( has no moves). How many states does the subset-construction DFA have if only subsets reachable from the start are built?

  1. (A)

    2

  2. (B)

    3

  3. (C)

    4

  4. (D)

    8

Answer and solution

Answer: (C)

  1. Start : on it goes to , on back to .

  2. : on to ; on to .

  3. : on to ; on to . : on to ; on to .

  4. No new subset appears and is not reached, so the reachable DFA has 4 states. (The language is 'the second symbol from the right is ', which needs states.)

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE CS

Regular expressions and finite automata

Preparing in Kolkata? IAE Academy's course for GATE CSE.