0% found this document useful (0 votes)
18 views2 pages

Bc220206873 CS204

The document discusses regular expressions and DFA construction. It provides regular expressions for three cases and describes the steps taken to construct a DFA for strings that start with 'a' and have no consecutive 'b's. The DFA construction includes defining states, alphabet, transitions, and accepting states.

Uploaded by

wahajmalik292
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Bc220206873 CS204

The document discusses regular expressions and DFA construction. It provides regular expressions for three cases and describes the steps taken to construct a DFA for strings that start with 'a' and have no consecutive 'b's. The DFA construction includes defining states, alphabet, transitions, and accepting states.

Uploaded by

wahajmalik292
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Muhammad Wahaj Tariq

Bc220206873
CS204

Solution of Question No.1

The regular expressions for each case:

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**

Solution of Question No.2


For constructing a Deterministic Finite Automaton (DFA) for the language described in part C of
Question 1 (strings that have NULL or start with “a” and have no consecutive “b”s), I used steps
described below:

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.

Now constructing the DFA:

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

Accepting states: {q0, q1, q3}

DFA Diagram:

a b
→(q0) ------→ (q1) ------→ (q3)
↑ | ↑ |
| | | |
| ↓ | ↓
| (q2) ------- | (q2)
| | |
--------------- | ---

You might also like