# NFA machines accepting all strings that ends or not ends with substring ‘ab’

**Prerequisite:** Finite Automata Introduction

**Problem-1:**

Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language ends with ‘ab’.

**Explanation:**

The desired language will be like:

L1 = {ab, abbab, abaab, ...........}

Here as we can see that each string of the above language ends with ‘ab’ but the below language is not accepted by this NFA because some of the string of below language does not end with ‘ab’.

L2 = {bba, abb, aaabbbb, .............}

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

In the above NFA, the initial state ‘X’ on getting ‘a’ as the input it either remains in the state of itself or transit to a state ‘Y’ and on getting ‘b’ as the input it remains in the state of itself. The state ‘Y’ on getting ‘b’ as the input it transmits to a final state ‘Z’.

**Problem-2:**

Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language is not ending with ‘ab’.

**Explanation:** The desired language will be like:

L1 = {bba, abb, aaabbbb, .............}

Here as we can see that each string of the above language is not ending with ‘ab’ but the below language is not accepted by this NFA because some of the string of below language is ending with ‘ab’.

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

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

In the above NFA, the initial state ‘X’ on getting ‘a’ as the input it remains in the state of itself and on getting ‘b’ as the input it transmits to a state ‘Y’. The state ‘Y’ on getting ‘b’ as the input it either remains in the state of itself or transmits to a final state ‘Z’. The final state ‘Z’ on getting ‘a’ as the input it remains in the state of itself.

## Recommended Posts:

- TOC | Construction of the machines that produce 'A', 'B', or 'C' if input ends with '1', '0', or nothing
- TOC | Moore and Mealy machines to count number of substring ‘ab’
- TOC | Construction of finite machines to prints ‘1’ as the output for every occurrence of ‘a’ as a substring
- DFA machines accepting odd number of 0’s or/and even number of 1’s
- Mealy and Moore Machines
- TOC | Moore and Mealy machines to produce 'A', 'B', 'C' depends on inputs that end with ’10’ or with ’11’ else other
- TOC | Construction of the machines to produce residue modulo ‘2’ of binary numbers
- DFA for accepting the language L = {a
^{n}b^{m}| n+m=odd} - DFA for accepting the language L = { a
^{n}b^{m}| n+m=even } - NPDA for accepting the language L = {a
^{n}b^{m}c^{n}| m,n>=1} - NPDA for accepting the language L = {a
^{m}b^{(m+n)}c^{n}| m,n ≥ 1} - NPDA for accepting the language L = {a
^{n}b^{n}| n>=1} - NPDA for accepting the language L = {a
^{m}b^{n}c^{n}| m,n ≥ 1} - NPDA for accepting the language L = {a
^{2m}b^{3m}| m ≥ 1} - NPDA for accepting the language L = {a
^{m}b^{(2m)}| m>=1}

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.