Bc220206873 CS204
Bc220206873 CS204
Bc220206873
CS204
Strings starting with “b” and ending with “a” having “ab” as a substring:
Regular Expression: **b(ab)*a**
Strings containing even number of a’s and ending with “baba” or “bb”:
Regular Expression: **((baba)|(bb))(aa)*|((aa)*baba|(aa)*bb)**
Strings that have NULL or start with “a” and have no consecutive b’s in it: Regular
Expression: **ε | a(b|ε)*a**
1. Defining the states: In this step we need states to keep track of whether the string seen so far has
started with “a” and whether it has encountered consecutive “b”s.
2. Defining the alphabet: In this step the alphabet consists of symbols ‘a’ and ‘b’.
3. Defining the transitions: In this step we define transitions between states based on the input
symbols.
4. Defining the accepting states: In this step we define which states are accepting states, i.e., states
where the DFA accepts the input string.
States:
- q0: Initial state, the string has not started with “a” yet and has encountered no consecutive “b”s.
- q1: The string has started with “a” but has encountered no consecutive “b”s.
- q2: The string has not started with “a” yet but has encountered one “b”.
- q3: The string has started with “a” and has encountered one “b”.
Alphabet: {a, b}
Transitions:
- q0 on ‘a’ goes to q1
- q0 on ‘b’ goes to q2
- q1 on ‘a’ stays at q1
- q1 on ‘b’ goes to q3
- q2 on ‘a’ goes to q1
- q2 on ‘b’ stays at q2
- q3 on ‘a’ stays at q3
- q3 on ‘b’ goes to q2
DFA Diagram:
a b
→(q0) ------→ (q1) ------→ (q3)
↑ | ↑ |
| | | |
| ↓ | ↓
| (q2) ------- | (q2)
| | |
--------------- | ---