0% found this document useful (0 votes)
26 views4 pages

Fall 2024 - CS402 - 1 - Assignment

N MNM

Uploaded by

Tanveer Ramzan
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)
26 views4 pages

Fall 2024 - CS402 - 1 - Assignment

N MNM

Uploaded by

Tanveer Ramzan
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/ 4

Theory of Automata (CS402) Total marks = 20

Assignment # 01
Fall 2024 Deadline Date
November 22, 2024

Question No. 1

a) Regular Expression for the Language

The language consists of all strings over the alphabet Σ = {a, b} that:

 End with exactly one 'b'.


 Can have any number of 'a's before the 'b', but at least one 'a' is required before
the 'b'.

The regular expression that describes this language is:

(a+)*b

Explanation:

 (a+)*: This part represents zero or more 'a's, but with the condition that at least
one 'a' is required (as indicated by the + within the parentheses).
 b: The string must end with exactly one 'b'.
 The construction (a+)*b ensures that there is one or more 'a's (since 'a+' means
at least one 'a') before the 'b', and the string ends with exactly one 'b'.

b) Finite Automaton for the Above Language

To draw a Finite Automaton (FA) that recognizes this language, follow these steps:

1. State 1 (Initial State): This is where the automaton starts. It can loop on 'a'
(indicating one or more 'a's are allowed before a 'b').
2. State 2: This state is reached when a 'b' is encountered. From this state, the
automaton can no longer accept any additional 'a's or 'b's.
3. Final State (State 2): The automaton must reach this state after reading
exactly one 'b', and no further symbols can be processed.

Here’s a basic state diagram for the Finite Automaton:

State 1 --> a --> State 1


State 1 --> b --> State 2 (Final State)

State 2 --> (No transition as no further symbols can be processed)


 State 1 is the starting state where any number of 'a's can occur (but at least one
'a' is needed before reaching State 2 with a 'b').
 Once the 'b' is encountered, the automaton transitions to State 2, which is a
final state, and no further inputs can be accepted.
Question No. 2

a) Regular Expression is (ab)*, how many different strings of length 4 are in this
language?

The regular expression (ab)* represents any number (including zero) of repetitions of
the sequence "ab". Since the string is of length 4, we need to determine how many
different ways the string can be formed using the pattern "ab".

The possible combinations of "ab" to form a length 4 string are:

 "abab"
 "baba"

Thus, there are 2 different strings of length 4.

b) Regular Expression is (a∣b)², how many strings of length 2 can it generate?

The regular expression (a∣b)² represents all strings of length 2 where each position
can independently be either 'a' or 'b'.

The total number of different strings of length 2 that can be formed is:

 First position: 2 choices ('a' or 'b')


 Second position: 2 choices ('a' or 'b')

Thus, the total number of strings is 2×2=42 \times 2 = 4.

The strings are:

 "aa"
 "ab"
 "ba"
 "bb"

So, 4 strings of length 2 can be generated.

c) Regular Expression is (ab∣ba)², how many distinct strings of length 4 can be


generated?

The regular expression (ab∣ ba)² means that we are forming strings of length 4 by
repeating either "ab" or "ba" exactly twice.

The possible combinations for a string of length 4 are:

 "abab"
 "baba"

Thus, only 2 distinct strings of length 4 can be generated.


Summary of Answers:

1. Regular expression for the language that ends with one 'b' and has at least one
'a' before it: *(a+)b
2. Finite Automaton:

o State 1: Start, loop on 'a', move to State 2 on 'b'


o State 2: Final state, no further input allowed

For Question 2:

 a) 2 different strings of length 4 can be generated.


 b) 4 different strings of length 2 can be generated.
 c) 2 distinct strings of length 4 can be generated.

You might also like