![]() |
VOOZH | about |
Prerequisite: Introduction to Deterministic Finite Automata
Construct a DFA that accepts string str starting with input alphabet 'a' but does not contain 'aab' as a substring over input {a, b}.
Examples:
Input: str = "babba"
Output: Not Accepted
Explanation:
The given string doesn't start with 'a'.Input: str = "abbaaaaa"
Output: Accepted
Explanation:
The given string start with 'a'and doesn't contains "aab" as a substring.
Approach:
The transition table helps to understand how the transition of each state takes place on the input alphabets. In the transition table initial state is represented by ---> and the final state is represented by *. There are 3 final states, one initial and one dead state.
State Transition table of the given DFA:
| STATE | INPUT (a) | INPUT (b) |
|---|---|---|
| ---> A | B* | Q (dead state) |
| B* | C* | D* |
| C* | C* | Q (dead state) |
| D* | B* | D* |
| Q (dead state) | Q (dead state) | Q (dead State) |
Below is the DFA diagram:
Below is the implementation of the above DFA:
Not Accepted
Time Complexity: O(N)
Auxiliary Space: O(N)