Construct DFA with Σ = {0, 1} and Accept All String of Length At Most 2
Last Updated :
19 Sep, 2022
Construct a DFA for a language accepting strings of length at most two, over input alphabets Σ = {0,1}. So that means in DFA, language consisting of a string of lengths 0, 1, and 2 is present. Length of string zero means when the machine doesn't get any symbol as an input but it still accepts something(epsilon).
Approach:
- First, try to make the language with the help of string conditions.
- Find the minimum possible string that satisfies the condition of length at most two.
- So, the required strings which have lengths 0, 1, and 2 will be the strings in the given language.
Concept:
String with length 0: String with length zero also satisfies our condition. To denote the string with length zero we use epsilon(ε).
L1 = {ε}
String with length 1: String with length 1, we have two strings "a" and "b" because we have an input alphabet a and b only.
L2 = {a, b}
String with length 2: String with length 2, we have four strings that satisfy our needs "aa", "ab", "ba", and "bb".
L2 = {aa, ab, ba, bb}
So all these strings satisfy the condition of the string of length at most two. So the language generated by these strings consists of these all strings. This is shown below:
L = {ε, a, b, aa, ab, ba, bb}
So here the approach is, for satisfying the above strings:
Steps for construction:
Accepting epsilon:
Design an initial state which will not take any input alphabet but it should accept the string which means it should take the string which has a length of zero. So for accepting such a string, we will make the final state to an initial state so whatever the input will come on that state it will accept it.
Accepting a and b:
For a and b, the transition from the initial state to the new state which is q1 while it will take the transition from the initial to q1 state it should be accepted by DFA Machine so for that it should have the q1 state as a final state. If it has a self-loop for a and b on the initial state which is q0, then string length may be increased but the constraint is it should have a fixed length which is 0, 1, and 2.
Accepting aa, ab, ba, and bb:
For this set of strings, the new state will be required. So the new state is named q2 and the transition from q1 to q2 is required. The state q2 must be the final state as it should accept the given strings satisfied by the given condition.
Reject all other strings:
The transition of two input symbols for q0, and q1 is done but not for q2. When the machine state is q2 whatever the input string will come, the length of the string will be increased but it should not happen to a given DFA machine, it must not take the string of length greater than 2. So here machine needs the one trap/dead state so it will help to discard the strings which have a length greater than 2.
Trap State:
In the trap state, it doesn't matter which input alphabet will come because the length of the string is already increased. So it will discard all strings no matter what input alphabet is there.
Similar Reads
Construct DFA with Σ = {0, 1} and Accept All String of Length at Least 2
Construct a DFA for a language accepting strings of length at least two, over input alphabets Σ = {a, b}. This means that in DFA, language consists of a string of length of at least 2 and can be greater than two. That means if DFA got the string of Length 0 or 1 then it will not accept it. A string
6 min read
DFA that Accepts All the Strings With At Least 1 'a' and Exactly 2 b's
Deterministic Finite Automata(DFA) is also known as Deterministic finite state automata(DSA). DFA is a Mathematical model of computation it is an abstract machine used to recognize patterns, it takes a string as input and changes its states accordingly when the desired terminal is found, then the tr
3 min read
DFA of a string with at least two 0âs and at least two 1âs
Problem - Draw deterministic finite automata (DFA) of a string with at least two 0âs and at least two 1âs. The first thing that come to mind after reading this question us that we count the number of 1's and 0's. Thereafter if they both are at least 2 the string is accepted else not accepted. But we
3 min read
Program to construct DFA accepting odd number of 0s and odd number of 1s
Given a binary string S, the task is to write a program for DFA Machine that accepts a string with odd numbers of 0s and 1s. Examples: Input: S = "010011"Output: AcceptedExplanation:The given string S contains odd number of zeros and ones. Input: S = "00000"Output: Not AcceptedExplanation:The given
7 min read
NFA machines accepting all strings that ends or not ends with substring 'ab'
Prerequisite: Basic Knowledge of NFA and state transition diagrams Problem 1:Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language ends with 'ab'. ExplanationThe desired language will be like: L1 = {ab, abbab, abaab, ...........} Here as we can see
2 min read
Construct a DFA which accept the language L = {w | w ∈ {a,b}* and Na(w) mod 3 = Nb (w) mod 3}
Problem: Construct a deterministic finite automata (DFA) for accepting the language L = {w | w â {a,b}* and Na(w) mod 3 = Nb (w) mod 3}. Language L={w | Na(w) = Nb(w)mod 3} which means all string contain modulus of count of a's equal to modulus of count of b's by 3. Examples: Input: a a b b b Output
14 min read
Construct a DFA that Start With aa or bb
Prerequisite: Designing Finite Automata DFA (Deterministic Finite Automata or Acceptor) is a finite state machine that accepts or rejects strings of symbols. DFA accepts the string if it reaches the final state otherwise it rejects it. In these types of problems, we have some given parameters accord
2 min read
Program to build a DFA to accept strings that start and end with same character
Given a string consisting of characters a and b, check if the string starts and ends with the same character or not. If it does, print 'Yes' else print 'No'.Examples: Input: str = "abbaaba" Output: Yes Explanation: The given input string starts and ends with same character 'a' So the states of the b
12 min read
Design a DFA that accepts a string containing 3 a's and 3 b's
Problem Statement: Design a Definite Finite Automata for accepting the permutation of Three a's and Three b's over the input {a, b} Input: S = "aaabbb" Output: Accepted Explanation: The input has three a and three b. Input: S = "abababa" Output: Accepted Explanation: The input has three a and three
15+ min read
Build a DFA to accept a binary string containing "01" i times and "1" 2j times
Given a binary string str, the task is to build a DFA that accepts given binary string if it contains "01" i times and "1" 2j times, i.e., [Tex]L={(01)^i (1)^{2j} \text{ where }i\geq1\text{ and }j\geq1} [/Tex] Examples: Input: str = "011111" Output: Accepted Explanation: The string follows the langu
9 min read