- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Design NFA with Σ = {0, 1} and accept all string of length at least 2.

Non-deterministic finite automata also have five states which are same as DFA, but with different transition function, as shown follows −

δ: Q X Σ -> 2Q

Non-deterministic finite automata is defined as a 5 tuple,

**M=(Q, Σ, δ,q0,F)**

Where,

- Q: Finite set of states
- Σ: Finite set of the input symbol
- q0: Initial state
- F: Final state
- δ: Transition function: Q X Σ -> 2Q

## Problem

Design a transition diagram and table for the given language that accepts all strings of length at least 2.

## Solution

Before proceeding to the solution, let’s understand what do you mean by length of string and how to find the length of any string.

The **length of a string** means it is the number of symbols in the string or word. It is denoted by |w|.

For Example: w=01011001 from binary alphabet Σ={0,1}

|w| = 8

In a given problem, the strings should have length of at least 2. That is, the length should be 2 or more, but not less than 2 over the alphabet Σ = {0, 1}.

The language L= { 00,01,10,11,001,110,101,111,000,1101,0010,…….}

## Transition Diagram

The transition diagram of NFA for the given language is −

## Transition table

The transition table is as follows −

Present state | Next state for input 0 | Next state for input 1 |
---|---|---|

->q0 | q1 | q1 |

q1 | q2 | q2 |

*q2 | ε | ε |

## Explanation

**Step 1**− q0 is an initial state on input ‘0’ it goes to state q1 and on input ‘1’ goes to state q1.**Step 2**− q1 is an intermediate state on input ‘0’ and ‘1’ goes to state q2.**Step 3**− q2 is the final state, it contains epsilon transitions.

## Example 2

Construct an NFA with Σ = {0, 1} which accepts all string ending with 01.

In a given problem, the language accepts all strings ending with 01.

The language L= { 01,101,1101,001,11001,0101,11101,0001,1001,00101,…….}

## Transition diagram

The transition diagram is as follows −

## Transition Table

The transition table is as follows −

Present state | Next state for input 0 | Next state for input 1 |
---|---|---|

->q0 | q0,q1 | q0 |

q1 | - | q2 |

*q2 | - | - |

## Explanation

**Step 1**− q0 is an initial state on input ‘0’ ii goes to multiple states q0 and q1 and ‘1’ it goes to state q0 itself.**Step 2**− q1 is an intermediate state on input ‘1’ goes to state q2.**Step 3**− q2 is the final state, it contains epsilon transitions.

- Related Questions & Answers
- Design a DFA of a string with at least two 0’s and at least two 1’s
- Construct ∈-NFA of Regular Language L = 0(0+1)*1
- Check If All 1's Are at Least Length K Places Away in C++
- Construct ∈-NFA of Regular Language L = (0+1)*(00+ 11)
- Sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n in C++
- Maximum length subsequence with difference between adjacent elements as either 0 or 1 | Set 2 in C++
- Forming string using 0 and 1 in JavaScript
- Find all the patterns of “1(0+)1” in a given string in C++
- Maximum length of segments of 0’s and 1’s in C++
- Program to find length of longest substring with character count of at least k in Python
- Find all the patterns of “1(0+)1” in a given string using Python Regex
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2
- Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + … + upto n terms in C++
- Find the number of binary strings of length N with at least 3 consecutive 1s in C++
- Contiguous subarray with 0 and 1 in JavaScript