- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Program to build DFA accepting the languages ending with “01”
Problem
Design deterministic finite automata (DFA) with ∑ = {0, 1} that accepts the languages ending with “01” over the characters {0, 1}.
Solution
The strings that are generated for a given language are as follows −
L={01,001,101,110001,1001,……….}
The minimum length of the string is 2, the number of states that the DFA consists of for the given language is: 2+1 = 3 states.
Here,
q0 − On input 0 it goes to state q1 and on input 1 it goes to itself.
q1 − On input 0 it goes to itself and on input 1 it goes to State q2.
q2 − On input 0 it goes to State q1 and on input 1 goes to State q0. State to q2 is the final state.
Example
Following is the C program to construct a DFA with ∑ = {0, 1} that accepts the languages ending with “01” over the characters {0, 1} -
#include #define max 100 main() { char str[max],f='a'; int i; printf("enter the string to be checked: "); scanf("%s",str); for(i=0;str[i]!='\0';i++) { switch(f) { case 'a': if(str[i]=='0') f='b'; else if(str[i]=='1') f='a'; break; case 'b': if(str[i]=='0') f='b'; else if(str[i]=='1') f='c'; break; case 'c': if(str[i]=='0') f='b'; else if(str[i]=='1') f='a'; break; } } if(f=='c') printf("
String is accepted", f); else printf("
String is not accepted", f); return 0; }
Output
The output is as follows −
Run 1: enter the string to be checked: 10101001 String is accepted. Run 2: enter the string to be checked: 10000010 String is not accepted.
- Related Articles
- DFA for Strings not ending with “THE” in C++?
- Construct DFA for strings not ending with "THE"
- C Program to construct DFA accepting odd numbers of 0s and 1s
- Program to build DFA that starts and end with ‘a’ from input (a, b) in C++
- Program to build DFA that starts and ends with ‘a’ from the input (a, b)
- C program for DFA accepting all strings over w ∈(a,b)* containing “aba” as a substring
- Python Program to accept string ending with alphanumeric character
- Design a DFA accepting stringw so that the second symbol is zero and fourth is 1
- Deletions of “01” or “10” in binary string to make it free from “01” or “10” in C++ Program
- Design a DFA accepting a language L having number of zeros in multiples of 3
- Design DFA for language over {0,1} accepting strings with odd number of 1’s and even number of 0’s
- 01 Matrix in C++
- Design a DFA machine accepting odd numbers of 0’s or even numbers of 1’s
- C Program to construct DFA for Regular Expression (a+aa*b)*
- C Program to construct a DFA which accepts L = {aN | N ≥ 1}

Advertisements