Wednesday, 28 August 2013

Obtain a DFA to accept strings of a’s and b’s starting with the string ab.

Solution: It is clear that the string should start with ab and so, the minimum string that can be accepted by the machine is ab.
To accept the string ab, we need three states and the machine can be written as

where q2 is the final or accepting state. In state q0, if the input symbol is b, the machine should reject b (note that the string should start with a). So, in state q0, on input b, we enter into the rejecting state q3. The machine for this can be of the form



The machine will be in state q1, if the first input symbol is a. If this a is followed by another a, the string aa should be rejected by the machine. So, in state q1, if the input symbol is a, we reject it and enter into q3 which is the rejecting state. The machine for this can be of the form


Whenever the string is not starting with ab, the machine will be in state q3 which is the rejecting state. So, in state q3, if the input string consists of a’s and b’s of any length, the entire string can be rejected and can stay in state q3 only.
The resulting machine can be of the form




The machine will be in state q2, if the input string starts with ab. After the string ab, the string containing any combination of a’s and bs, can be accepted and so remain in state q2 only. The complete machine to accept the strings of a’s and b’s starting with the string ab is shown in figure.
The state q3 is called trap state or rejecting state.

In the set notation, the language accepted by DFA can be represented as
L = {ab(a + b)n |n ≥ 0}
Or
L = {ab(a + b)*}
Therefore the DFA which accepts strings of a’s and b’s starting with the string ab is given by M = (Q, S, d, q0, F), where
Q = {q0, q1, q2, q3}, ∑ = {a, b}, q0: initial state, F = {q2}, and the transition function d is defined as



To accept the string abab: The string is accepted by the machine.
clip_image012[15](q0, abab) = d (clip_image012[15] (q0, aba), b)
= d (d (clip_image012[15] (q0, ab), a), b)
= d (d (d (d (q0, a), b), a), b)
= d (d (d (q1, b), a), b)
= d (d (q2, a), b)
= d (q2, b)
= q2  F.
To reject the string aabb:
clip_image012[15] (q0, aabb) = d (clip_image012[15] (q0, aab), b)
= d (d (clip_image012[15] (q0, aa), b), b)
= d (d (d (d (q0, a), a, b), b)
= d (d (d (q1, a), b), b)
= d (d (q3, b), b)
= d (q3, b)
= q3  F.


Therefore the string aabb is not accepted by the machine.

No comments:

Post a Comment