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)
- Count strings that end with the given pattern
- Check if strings are rotations of each other or not | Set 2
- DFA for strings not containing consecutive two a's and starting with 'a'
- String matching with * (that matches with any) in any of the two strings
- Python program to find uncommon words from two Strings
- Longest substring of only 4's from the first N characters of the infinite string
- Print the longest prefix of the given string which is also the suffix of the same string
- Print a number as string of 'A' and 'B' in lexicographic order
- TOC | Construction of the machines to produce residue modulo ‘2’ of binary numbers
- TOC | Regular expression to ∈-NFA
- TOC | Designing Finite Automata from Regular Expression (Set 8)
- TOC | Designing Finite Automata from Regular Expression (Set 7)
- TOC | Construction of the machines that produce 'A', 'B', or 'C' if input ends with '1', '0', or nothing
- TOC | Designing Finite Automata from Regular Expression (Set 6)
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.