- 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
- Design a DFA machine accepting odd numbers of 0’s or even numbers of 1’s
- Design a DFA of a string with at least two 0’s and at least two 1’s
- Design DFA for language over {0,1} accepting strings with odd number of 1’s and even number of 0’s
- 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
- Maximum length of segments of 0’s and 1’s in C++
- C++ Largest Subtree having Equal No of 1's and 0's
- Convert RE 1(0+1)*0 into equivalent DFA.
- Count subarrays with equal number of 1’s and 0’s in C++
- Find the Pattern of 1’s inside 0’s using C++
- Segregate 0’s and 1’s in an array list using Python?
- Find the index of first 1 in a sorted array of 0's and 1's in C++
- Construct ∈-NFA of Regular Language L = 0(0+1)*1
- Largest number with binary representation is m 1’s and m-1 0’s in C++
- Construct a DFA recognizing the language {x | the number of 1's is divisible by 2, and 0'sby 3} over an alphabet ∑={0,1}