Solveeit Logo

Question

Question: For the following regular expressions, draw the FA (Finite Automata) recognizing the corresponding l...

For the following regular expressions, draw the FA (Finite Automata) recognizing the corresponding language. [5]

i) ab+ba+ba+(ab)ab^* + ba^* + b^*a + (a^*b)^* ii) ba(a+b)abb^*a (a+b)^*ab^*

Answer

FA drawings as above

Explanation

Solution

To draw the Finite Automata (FA) for the given regular expressions, we will construct Non-deterministic Finite Automata (NFA) using standard conversion rules.

Part i) ab+ba+ba+(ab)ab^* + ba^* + b^*a + (a^*b)^*

This regular expression is a union of four sub-expressions. We will construct an NFA for each sub-expression and then combine them using a new start state and a new final state connected by ϵ\epsilon-transitions.

Let QstartQ_{start} be the global initial state and QfinalQ_{final} be the global final state.

  1. FA for abab^*:

    • State Q1,1Q_{1,1} (initial for this component) transitions to Q1,2Q_{1,2} on 'a'.
    • State Q1,2Q_{1,2} has a self-loop on 'b'.
    • Q1,2Q_{1,2} is the final state for this component.
    • Transitions: QstartϵQ1,1Q_{start} \xrightarrow{\epsilon} Q_{1,1}, Q1,1aQ1,2Q_{1,1} \xrightarrow{a} Q_{1,2}, Q1,2bQ1,2Q_{1,2} \xrightarrow{b} Q_{1,2}, Q1,2ϵQfinalQ_{1,2} \xrightarrow{\epsilon} Q_{final}.
  2. FA for baba^*:

    • State Q2,1Q_{2,1} (initial for this component) transitions to Q2,2Q_{2,2} on 'b'.
    • State Q2,2Q_{2,2} has a self-loop on 'a'.
    • Q2,2Q_{2,2} is the final state for this component.
    • Transitions: QstartϵQ2,1Q_{start} \xrightarrow{\epsilon} Q_{2,1}, Q2,1bQ2,2Q_{2,1} \xrightarrow{b} Q_{2,2}, Q2,2aQ2,2Q_{2,2} \xrightarrow{a} Q_{2,2}, Q2,2ϵQfinalQ_{2,2} \xrightarrow{\epsilon} Q_{final}.
  3. FA for bab^*a:

    • State Q3,1Q_{3,1} (initial for this component) has a self-loop on 'b'.
    • State Q3,1Q_{3,1} transitions to Q3,2Q_{3,2} on 'a'.
    • Q3,2Q_{3,2} is the final state for this component.
    • Transitions: QstartϵQ3,1Q_{start} \xrightarrow{\epsilon} Q_{3,1}, Q3,1bQ3,1Q_{3,1} \xrightarrow{b} Q_{3,1}, Q3,1aQ3,2Q_{3,1} \xrightarrow{a} Q_{3,2}, Q3,2ϵQfinalQ_{3,2} \xrightarrow{\epsilon} Q_{final}.
  4. FA for (ab)(a^*b)^*:

    • Let's first construct FA for aba^*b:
      • State Q4,2Q_{4,2} has a self-loop on 'a'.
      • From Q4,2Q_{4,2}, it transitions to Q4,3Q_{4,3} on 'b'.
      • Q4,2Q_{4,2} is the start of aba^*b, Q4,3Q_{4,3} is the end of aba^*b.
    • Now apply Kleene star:
      • State Q4,1Q_{4,1} is the initial state for (ab)(a^*b)^*.
      • Q4,1Q_{4,1} transitions to Q4,2Q_{4,2} via ϵ\epsilon (start of aba^*b).
      • Q4,1Q_{4,1} transitions to QfinalQ_{final} via ϵ\epsilon (for the empty string, i.e., zero repetitions of aba^*b).
      • Q4,3Q_{4,3} transitions back to Q4,1Q_{4,1} via ϵ\epsilon (for repetitions of aba^*b).
      • Q4,3Q_{4,3} transitions to QfinalQ_{final} via ϵ\epsilon (end of aba^*b to global final).
    • Transitions: QstartϵQ4,1Q_{start} \xrightarrow{\epsilon} Q_{4,1}, Q4,1ϵQfinalQ_{4,1} \xrightarrow{\epsilon} Q_{final}, Q4,1ϵQ4,2Q_{4,1} \xrightarrow{\epsilon} Q_{4,2}, Q4,2aQ4,2Q_{4,2} \xrightarrow{a} Q_{4,2}, Q4,2bQ4,3Q_{4,2} \xrightarrow{b} Q_{4,3}, Q4,3ϵQ4,1Q_{4,3} \xrightarrow{\epsilon} Q_{4,1}, Q4,3ϵQfinalQ_{4,3} \xrightarrow{\epsilon} Q_{final}.

The complete NFA is shown below:

Part ii) ba(a+b)abb^*a (a+b)^*ab^*

This regular expression is a concatenation of five parts. We will construct an NFA for each part and then concatenate them sequentially.

Let Q0Q_0 be the initial state and QFQ_F be the final state.

  1. FA for bb^*:

    • State Q0Q_0 (initial) has a self-loop on 'b'. Q0Q_0 is also a final state for this part.
    • Transitions: Q0bQ0Q_0 \xrightarrow{b} Q_0.
  2. FA for aa:

    • State Q1Q_1 transitions to Q2Q_2 on 'a'. Q2Q_2 is a final state for this part.
    • Transitions: Q1aQ2Q_1 \xrightarrow{a} Q_2.
  3. FA for (a+b)(a+b)^*:

    • State Q3Q_3 has self-loops on 'a' and 'b'. Q3Q_3 is also a final state for this part.
    • Transitions: Q3aQ3Q_3 \xrightarrow{a} Q_3, Q3bQ3Q_3 \xrightarrow{b} Q_3.
  4. FA for aa:

    • State Q4Q_4 transitions to Q5Q_5 on 'a'. Q5Q_5 is a final state for this part.
    • Transitions: Q4aQ5Q_4 \xrightarrow{a} Q_5.
  5. FA for bb^*:

    • State Q6Q_6 has a self-loop on 'b'. Q6Q_6 is also a final state for this part.
    • Transitions: Q6bQ6Q_6 \xrightarrow{b} Q_6.

Now, concatenate these components using ϵ\epsilon-transitions. The final state of one component becomes the initial state of the next via an ϵ\epsilon-transition. The first component's initial state is the overall initial state, and the last component's final state is the overall final state.

  • Q0Q_0 is the overall initial state.
  • The final states of bb^* are Q0Q_0.
  • Connect Q0Q_0 to Q1Q_1 (start of 'a') via ϵ\epsilon.
  • The final states of 'a' are Q2Q_2.
  • Connect Q2Q_2 to Q3Q_3 (start of (a+b)(a+b)^*) via ϵ\epsilon.
  • The final states of (a+b)(a+b)^* are Q3Q_3.
  • Connect Q3Q_3 to Q4Q_4 (start of 'a') via ϵ\epsilon.
  • The final states of 'a' are Q5Q_5.
  • Connect Q5Q_5 to Q6Q_6 (start of bb^*) via ϵ\epsilon.
  • The final states of bb^* are Q6Q_6.
  • Q6Q_6 is the overall final state.

The complete NFA is shown below:

The final state Q6Q_6 can also be the final state directly. The ϵ\epsilon transition from Q6Q_6 to QfinalQ_{final} is optional if Q6Q_6 is marked as final.

The solution involves constructing Non-deterministic Finite Automata (NFA) for the given regular expressions. For regular expressions involving union (++), a new start state and a new final state are introduced, with ϵ\epsilon-transitions connecting the new start state to the start states of the individual components and the final states of the individual components to the new final state. For concatenation, ϵ\epsilon-transitions are used to connect the final state of one component's FA to the initial state of the next component's FA. For Kleene star (*), the standard construction involves creating a loop using ϵ\epsilon-transitions from the final state back to the initial state of the sub-expression, and also an ϵ\epsilon-transition from the initial state to the final state to account for zero repetitions.