VOOZH about

URL: https://www.geeksforgeeks.org/theory-of-computation/designing-non-deterministic-finite-automata-set-1/

⇱ Designing Non-Deterministic Finite Automata (Set 1) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Designing Non-Deterministic Finite Automata (Set 1)

Last Updated : 11 Jul, 2025

Prerequisite:

Finite Automata Introduction

In this article, we will see some designing of Non-Deterministic Finite Automata (NFA).

Problem-1:

Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language starts with 'a'.

Explanation:

The desired language will be like:

L1 = {ab, abba, abaa, ...........}

Here as we can see that each string of the above language starts with 'a' and end with any alphabet either 'a' or 'b'. But the below language is not accepted by this NFA because none of the string of below language starts with 'a'.

L2 = {ba, ba, babaaa..............}

The state transition diagram of the desired language will be like below:

👁 Image

In the above NFA, the initial state 'X' on getting 'a' as the input it transits to a final state 'Y'. The final state 'Y' on getting either 'a' or 'b' as the input it remains in the state of itself.

Python Implementation:

output:

String accepted

Problem-2:

Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language is not starting with 'a'.

Explanation:

The desired language will be like:

L1 = {ba, bba, bbaa, ...........}

Here as we can see that each string of the above language is not starting with 'a' but can end with either 'a' or 'b'. But the below language is not accepted by this NFA because some of the string of below language starts with 'a'.

L2 = {ab, aba, ababaab..............}

The state transition diagram of the desired language will be like below:

👁 Image

In the above NFA, the initial state 'X' on getting 'b' as the input it transits to a final state 'Y'. The final state 'Y' on getting either 'a' or 'b' as the input it remains in the state of itself.

Python Implementation:

Comment
Article Tags:

Explore