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
- Difference Between Go-Back-N and Selective Repeat Protocol
- Difference between Stop and Wait protocol and Sliding Window protocol
- Difference between Ring Topology and Mesh Topology
- Difference between LAN and VLAN
- Difference between Star and Ring Topology
- Difference between Long-Term and Short-Term Scheduler
- Difference between SMTP and POP3
- Difference between Star and Mesh Topology
- Differences between Computer Architecture and Computer Organization
- DBMS | Domain Relational Calculus
- Differences between Magnetic Tape and Magnetic Disk
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