Problem – Accept Strings that not ending with substring “THE”. Check if a given string is ending with “the” or not. The different forms of “the” which are avoided in the end of the string are:
"THE", "ThE", "THe", "tHE", "thE", "The", "tHe" and "the"
All those strings that are ending with any of the above mentioned forms of “the” are not accepted.
Determinitis finite automata (DFA) of strings that not ending with “THE” –
The initial and starting state in this dfa is Qo
Approach used in the program –
In this program, consider the 4 states to be 0, 1, 2 and 3. Now let us take a variable named DFA which will be initially 0. Whenever any transition takes place, it will update the value of DFA with the number associated with new state.
Example : If a transition occurs from state 0 to state 1 then the value of DFA will be updated to 1. If a transition occurs from state 2 to state 3 then the value of dfa will be updated to 3. In this way, apply this algorithm on entire string and if in the end, then reach state 0, 1 or 2 then our string will be accepted otherwise not.
Input : XYzabCthe Output : NOT ACCEPTED Input : Themaliktth Output : ACCEPTED
The time complexity of this program is O(n)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Program to build a DFA that accepts strings starting and ending with different character
- Count strings that end with the given pattern
- DFA for strings not containing consecutive two a's and starting with 'a'
- Check if strings are rotations of each other or not | Set 2
- Count of all sub-strings with sum of weights at most K
- String matching with * (that matches with any) in any of the two strings
- Count of sub-strings with equal consecutive 0's and 1's
- Check whether two strings contain same characters in same order
- Count all sub-strings with weight of characters atmost K
- NFA to accept strings that has atleast one character occurring in a multiple of 3
- Program to build a DFA to accept strings that start and end with same character
- Python program to find uncommon words from two Strings
- Total length of string from given Array of strings composed using given characters
- For each lowercase English alphabet find the count of strings having these alphabets
- Sort the strings based on the numbers of matchsticks required to represent them
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.