- 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

# Construct an NFA accepting strings with an even number of 0s or an odd number of 1s

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

**δ: Q X Σ → 2 ^{Q}**

Where,

- Q : Finite set called states.
- Σ : Finite set called alphabets.
- δ : Q × Σ → Q is the transition function.
- q0 ϵ Q is the start or initial state.
- F : Final or accept state.

## Problem

Construct NFA over an alphabet Σ={0,1}.

## Solution

Design two separate machines for the two conditions, as given below −

NFA accepting only odd number of 1’s

NFA accepting only even number of 0’s

**NFA accepting only odd number of 1’s over an alphabet Σ= {0,1}.**

The language it generates is −

L={1,111,01,001,0111,0010,01110,….}

State o1 on 0 goes to o1 and on 1 goes to state o2.

State o2 on 0 goes to o2 and on 1 goes to o1.

**NFA Accepting only even number of 0’s over an alphabet Σ= {0,1}**

The language it generates is −

L={100,1100,1010,1100010,…….}

State E1 on 1 goes to E1 and on 0 goes to E2.

State E2 on 1 goes to E2 only and on 0 goes to E1.

Now merge the two transition diagrams with an epsilon move.

**The NFA that accepts all strings with an even number of 0s or an odd number of 1s** is as follows −

- Related Questions & Answers
- C Program to construct DFA accepting odd numbers of 0s and 1s
- Design DFA for language over {0,1} accepting strings with odd number of 1’s and even number of 0’s
- Count number of even and odd elements in an array in C++
- Largest subarray with equal number of 0s and 1s in C++
- Java program to Print Odd and Even Number from an Array
- Count Substrings with equal number of 0s, 1s and 2s in C++
- Splitting number to contain continuous odd or even number using JavaScript
- Number of pairs with Bitwise OR as Odd number in C++
- C++ Queries on Probability of Even or Odd Number in Given Ranges
- Odd even sort in an array - JavaScript
- PHP program to check if the total number of divisors of a number is even or odd
- Express an odd number as sum of prime numbers in C++
- Kth odd number in an array in C++
- Encoding a number string into a string of 0s and 1s in JavaScript
- What is an acceptance of language by NFA with Epsilon?