DFA (Deterministic Finite Automaton or Acceptor) is a finite state machine that accepts or rejects strings of symbols. DFA accepts the string if it reaches the final state and rejects otherwise.
Now the problem is, provided a string as input character by character and we have to check whether the string starts and ends with ‘a’. We can only store the current character, since there is no concept of memory and hence the DFA cannot store the string provided. Otherwise, we could have just checked the first and last character for this problem. The input set for this problem is (a, b).
We cannot store anything accept the current character, which make this program a little different and tough than other string related problems.
Input : a b a b a Output : Yes Explanation : (a b a b a) starts and end with 'a' Input : a b a b b Output : No Explanation : (a b a b b) starts with 'a' but doesn't end with 'a'
We first build a DFA for this problem. Making DFA is like making a flowchart for this program and then implement it in any language. You should have the knowledge of DFA and Finite Automata.
The DFA for given problem is:
a a b a a YES
- Return maximum occurring character in an input string
- Print all the duplicates in the input string
- A Program to check if strings are rotations of each other or not
- Write a program to print all permutations of a given string
- Write a program to reverse an array or string
- Program to validate an IP address
- Build Lowest Number by Removing n digits from a given number
- Program to toggle all characters in a string
- Program to find second most frequent character
- C Program to Sort an array of names or strings
- C Program to Check if a Given String is Palindrome
- Program to print all palindromes in a given range
- C++ Program to remove spaces from a string
- Remove comments from a given C/C++ program
- Program to add two binary strings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.