BC 220203486

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

BC220203486

CS402
Assignment 1

Question no 1
Consider the language L of strings, defined over ∑= {a, b}, Write regular expressions of
following:

● Strings starting with “b” and ending with “a” having “ab” as a substring.
● Strings containing even number of a’s and ending with “baba” or “bb”.
● String that having NULL or starts with “a” and having no consecutive b’s in it.

Answer
● 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: (a(aa)*baba|a(aa)*bb)
● String that has NULL or starts with “a” and has no consecutive b’s in it:
Regular expression: (ε|a|ab)*a?b?(ba)*

Question no 2
Construct a Deterministic Finite Automata (DFA) for part C of Question 1

To construct 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),
we need to follow these steps:

1. Define states: Determine the states of the DFA based on the requirements of the
language.
2. Define the alphabet: Identify the alphabet of the language.
3. Define transitions: Define transitions between states based on input symbols.
4. Determine the initial state: Identify the initial state of the DFA.
5. Determine the accepting states: Identify the accepting states of the DFA.

Let's construct the DFA:

1. Define states:
● State 0: Initial state (start state)
● State 1: Accepting state for strings starting with "a"
● State 2: Accepting state for strings starting with "ab"
2. Define the alphabet:
● ∑ = {a, b}
3. Define transitions:
● From state 0:
● On input "a": Transition to state 1
● On input "b": Transition to state 0
● From state 1:
● On input "a": Transition to state 1
● On input "b": Transition to state 2
● From state 2:
● On input "a": Transition to state 1
● On input "b": Transition to state 0
4. Determine the initial state:
● Initial state: State 0
5. Determine the accepting states:
● Accepting states: {0, 1}

Here is the transition table:

State Input: a Input: b

0 1 0

1 1 2

2 1 0

And the corresponding DFA diagram:


/--a--> [State 1] --a--> [State 1]
/ | |
[State 0] --b--> [State 0] --b--> [State 2]
\____________|___________/

In this DFA:

● State 0 is the initial state.


● States 0 and 1 are accepting states.
● State 2 is a non-accepting state.

You might also like