Prerequisite – Finite Automata Introduction
Problem: Construct deteministic finite automata (DFA) for strings not containing consecutive two a’s and starting with a.
Accept Strings that not contain consecutive two a’s. Check if a given string contain consecutive two a’s or not. The any occurrence of (b-z) should not affect the scenario. Strings should follow this pattern:
a.(ww|(ww.a))* where, ww = all possible character except a
All those strings that are not fall in the above mentioned pattern are not accepted.
Deterministic finite automata (DFA) of strings that not contain consecutive two a’s given as following below. The initial and starting state in this dfa is q0.
In this program, consider the 6 states to be 0, 1, 2, 3, 4 and 5. 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.
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 1, 2, 4 or 5 then our string will be accepted otherwise not.
Input : geeksaforaageeks Output : NOT ACCEPTED Input : aageeksforageeks Output : NOT ACCEPTED Input : ageeksaforageeks Output : ACCEPTED
The time complexity of this program is O(n)
- DFA for Strings not ending with "THE"
- Practice questions on Strings
- C++ Program to concatenate two strings using Operator Overloading
- Compiler Design | Single pass, Two pass, and Multi pass Compilers
- Computer Network | Classless Inter Domain Routing (CIDR)
- Functionality of Computer Network
- TOC | Construction of the machines to produce residue modulo ‘2’ of binary numbers
- Computer Networks | Minimum length of Token Ring
- Computer Networks | Pipelining in Packet Switching
- Computer Network Elements
- Computer Networks | Advantages & Disadvantages of Subnetting
- TOC | Regular expression to ∈-NFA
- TOC | Designing Finite Automata from Regular Expression (Set 8)
- TOC | Designing Finite Automata from Regular Expression (Set 7)
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.
Improved By : andrew1234