- 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 DFA of alternate 0’s and 1’s

## Problem

Construct deterministic Finite automata (DFA) whose language consists of strings with alternate 0’s and 1’s over an alphabet ∑ ={0,1}.

## Solution

If Σ = {0, 1} (ε + 1)(01)* (ε + 0) is the set of strings that alternate 0’s and 1’s Another expression for the same language is (01)*+ 1(01)*+ (01)*0+ 1(01)*0.

The strings the given language generates are as follows −

If no input is either 0 or 1 then it generates {ε} .

String starts with 0 and followed by 1 = {0101…}.

String starts with 1 followed by 0 ={101010….. }

So, based on string generation it is clear the strings are start with ε,(01)*, (10)*, but there is no restriction that string begin with 0 only or 1 only, so by considering all these points in the mind, the expression that it satisfies the given language with alternate 0’s and 1’s is −

(01)* + (10)* + 0(10)* + 1(01)*

## DFA

The DFA for the given language is −

## Explanation

Starting with the initial state, the string it generates, q0 on 0 goes to q1 which is one of the final states , accepting only 0, which satisfies the given condition.

Starting with the initial state, the string it generates, q0 on 1 goes to q3 which is one of the final states, accepting only 1, that satisfies the given condition.

q0 to reach final state q2 it generates a string “01” which is accepted by the language.

q0 to reach one of the final states q4, it generates a string “10” which is accepted by the language.

Similarly for the remaining strings also accepted by the DFA.

- Related Questions & Answers
- Sort an arrays of 0’s, 1’s and 2’s using C++
- Sort an arrays of 0’s, 1’s and 2’s using Java
- Design a DFA machine accepting odd numbers of 0’s or even numbers of 1’s
- Maximum length of segments of 0’s and 1’s in C++
- Design a DFA of a string with at least two 0’s and at least two 1’s
- Find the Pattern of 1’s inside 0’s using C++
- Count subarrays with equal number of 1’s and 0’s in C++
- Segregate 0’s and 1’s in an array list using Python?
- Design DFA for language over {0,1} accepting strings with odd number of 1’s and even number of 0’s
- 1’s and 2’s complement of a Binary Number?
- Largest number with binary representation is m 1’s and m-1 0’s in C++
- Maximum 0’s between two immediate 1’s in binary representation in C++
- Count number of binary strings of length N having only 0’s and 1’s in C++
- Count the number of 1’s and 0’s in a binary array using STL in C++
- Count subarrays consisting of only 0’s and only 1’s in a binary array in C++