English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
DFA stands for Deterministic Finite Automaton. It is a finite state machine that can accept or reject strings based on its acceptor.
Here, we will create a DFA that accepts strings that start and end with 'a'. Input comes from the set (a,b). Based on this, we will design the DFA. Now, let's discuss some valid and invalid cases that the DFA accepts.
DFA accepts strings: ababba, aabba, aa, a.
DFA does not accept strings: ab, b, aabab.
This program checks for strings that start and end with 'a'. This DFA will accept all strings that start and end with 'a'. The code checks if the first and last elements are equal and can place anything between them (a,b).
#include <iostream> #include <string.h> using namespace std; int main() { char str[] = {"ababba"}; int length = strlen(str); if(str[0] == 'a' && str[lenght-1] == 'a' { printf("Accepted"); else{ printf("Rejected"); return 0; } } }
Output Result
Accepted