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)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Program to build a DFA that accepts strings starting and ending with different character
- Check if strings are rotations of each other or not | Set 2
- Count strings that end with the given pattern
- Find strings that end with a given suffix
- Count of all sub-strings with sum of weights at most K
- DFA for strings not containing consecutive two a's and starting with 'a'
- Check whether two strings contain same characters in same order
- 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
- Count all sub-strings with weight of characters atmost K
- Build a DFA to accept Binary strings that starts or ends with "01"
- Program to build a DFA to accept strings that start and end with same character
- NFA to accept strings that has atleast one character occurring in a multiple of 3
- Python program to find uncommon words from two Strings
- Sort the strings based on the numbers of matchsticks required to represent them
- For each lowercase English alphabet find the count of strings having these alphabets
- Total length of string from given Array of strings composed using given characters
- Sort an array of strings based on the frequency of good words in them
- NFA machines accepting all strings that ends or not ends with substring 'ab'
- Strings formed from given characters without any consecutive repeating characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.