- 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 construct a DFA which accepts L = {aN | N ≥ 1}
Let us take a string S of size N, we have to design a Deterministic Finite Automata (DFA) for accepting the language L = {aN | N ≥ 1}.
The string accepting the language L is {a, aa, aaa, aaaaaaa…, }.
Now the user has to enter a string, if that string is present in the given language, then print “entered string is Accepted”. Otherwise, print “entered string is not Accepted”.
DFA transition diagram for the given language is −
Example
Following is the C program to construct DFA which accepts the language L = {aN | N ≥ 1} −
#include<stdio.h> int main() { char S[30]; int l,i; int count = 0; printf("To implement DFA of language {aN | N ≥ 1}
enter input string:"); scanf("%s",S); l=strlen(S); for (i=0;i<l;i++) { if(S[i]!='a') { printf("entered string is NOT ACCEPTED"); getch(); exit(0); } if (S[i] == 'a') count++; else printf("invalid input"); } if (count == l && count != 0) { printf("entered string is accepted"); } return 0; }
Output
You will get the following output −
Run 1: To implement DFA of language {aN | N >= 1} enter input string:aaaa entered string is accepted Run 2: To implement DFA of language {aN | N >= 1} enter input string:badsaa entered string is NOT ACCEPTED
- Related Articles
- Construct Turing machine for L = {an bm a(n+m) - n,m≥1} in C++
- Construct DFA with Σ= {0,1} accepts all strings with 0.
- Construct a Turing Machine for L = {a^n b^n | n>=1}
- Construct PDA for L = {0n1m2(n+m) | m,n >=1}
- Construct a Turing Machine for language L = {0n1n2n | n≥1}
- Draw DFA which accepts the string starting with ‘ab’.
- Construct a PDA for language L = {0n 1m2m3n | n>=1, m>=1}
- C Program to construct DFA for Regular Expression (a+aa*b)*
- Construct PDA for accepting L = {anb(2n) | n>=1} U {anbn | n>=1}
- If ( a=x^{m+n} y^{l}, b=x^{n+l} y^{m} ) and ( c=x^{l+m} y^{n} ), prove that ( a^{m-n} b^{n-1} c^{l-m}=1 . )
- C Program to construct DFA accepting odd numbers of 0s and 1s
- Design a DFA that accepts at most 3 a"s
- Construct DFA of alternate 0’s and 1’s
- Construct Pushdown automata for L = {0n1m2(n+m) | m,n = 0} in C++
- Construct Pushdown automata for L = {0n1m2m3n | m,n = 0} in C++

Advertisements