1
2
Q1: For S ={a, b} define the regular expression that represent the following languages
A). All string that not start with a and not contain b.
String { Λ }
Regular Expression Λ
Only accept lambda
B). L = {w:|w | mod 3= 0 }.
3 mod 3 = 0 6 mod 3 =0
0 mod 3 = 0
*
Regular Expression Λ + ((a+b)(a+b)(a+b))
C. A language that never end with ba
String ={ Λ,a,b,ab,aa,bb,aab,aaa,abb,bbb,….}
*
Regular Expression (Λ+a+b)+ (a+b) (aa+bb+ab)
Q1: Obtain the NFA for a language defined By
A) L1={anbm n,m>= 1}
String = {ab,aab,abb,aabb,abbb,aaab,….}
3
*
B) L2 = {x E {a,b} | # a(x) mod 4 = 1 }
C)
D) String = {a,aaaaa,abbbb,aabab,ababb,aaabb,….}
RE : a((a+b)(a+b)(a+b)(a+b))
*
Q3. TG to RE
4
Q4: Q4. Consider the CFG:
S→ XbaaX | aX
X→Xa| Xb| e
What is the language this generates? Find a word in this language that can be generated in two
substantially different ways.
Ans
The Language generates is
* *
a(a+b) + (a+b) baa(a+b)*
{a,aa,ab,aaa,aba,abb,aab,…….
baa,abaaab,abaaaa,baaaa,abaaab,…..}
language that can be generated in two substantially different ways.
One such string is "baaa":
S => XbaaX => bXaaX => baXaax => baaa
S => aX => aXa => aXaa => aXaaa => aXaaaa => bXaaaa => baXaaa =>
baaXaa => baaa
5
Show that the set (02n 1n) is not regular using pumping lemma.
Ans
6
7
Q1 : Define the following terms:
Tuples of Moore Machine:
A Moore machine is a type of finite state machine where the output is based on the current state. The
tuples of a Moore machine consist of the following elements:
• A set of states
• An input alphabet
• A transition function that maps each state and input to a new state
• An output function that maps each state to an output symbol
• An initial state
Tuples of DFA:
A DFA, or deterministic finite automaton, is a type of finite state machine where there is a unique
transition for each state and input symbol. The tuples of a DFA consist of the following elements:
• A set of states
• An input alphabet
• A transition function that maps each state and input to a new state
• An initial state
• A set of accepting states
Pumping Lemma:
The Pumping Lemma is a tool used in automata theory to prove that certain languages are not regular. It
states that for any regular language L, there exists a constant p such that any string s in L with length
greater than or equal to p can be divided into three parts: s = xyz, where |y| > 0 and |xy| ≤ p, and xy^iz is
also in L for all i ≥ 0. The Pumping Lemma can be used to derive a contradiction by showing that there is
no such constant p for a given language L..
Q2: DFA with Σ = {0, 1} accepts even number of 0's and even number of 1's.
8
Q3: Derive the string "aabbabba" for leftmost derivation using a CFG given by,
1. S –> aB | bA
2. S –> a|aS| bAA
3. S –> b| aS | aBB
Ans:
leftmost derivation for each CFG to derive the string "aabbabba".
S –> aB | bA
S -> aB (Apply S -> aB production rule)
-> aaBB (Apply B -> a production rule)
-> aabB (Apply B -> bA production rule)
-> aabbA (Apply A -> a production rule)
-> aabbaB (Apply B -> bA production rule)
-> aabbabA (Apply A -> b production rule)
-> aabbabb (Apply B -> b production rule)
9
Therefore, the leftmost derivation for "aabbabba" using CFG 1 is: S -> aB -> aaBB -> aabB -> aabbA ->
aabbaB -> aabbabA -> aabbabb.
S –> a|aS| bAA
S -> aS (Apply S -> aS production rule)
-> aaA (Apply S -> a production rule)
-> aabAA (Apply A -> a production rule)
-> aabbAAA (Apply A -> a production rule)
-> aabbabA (Apply A -> b production rule)
-> aabbabb (Apply A -> b production rule)
Therefore, the leftmost derivation for "aabbabba" using CFG 2 is: S -> aS -> aaA -> aabAA -> aabbAAA ->
aabbabA -> aabbabb.
S –> b| aS | aBB
S -> aS (Apply S -> aS production rule)
-> aaBB (Apply S -> a production rule)
-> aabB (Apply B -> b production rule)
-> aabbA (Apply A -> a production rule)
-> aabbaB (Apply B -> bA production rule)
-> aabbabA (Apply A -> b production rule)
-> aabbabb (Apply B -> b production rule)
Therefore, the leftmost derivation for "aabbabba" using CFG 3 is: S -> aS -> aaBB -> aabB -> aabbA ->
aabbaB -> aabbabA -> aabbabb.
10
Q4: Convert TG to RE:
sorry a(a+b)*b ana tha mistake * nhi likha gya
So
RE is (a(a+b)*b)+(b(a+b)*a)
11
12
Q1: DFA diagram for the language accepting strings containing '01' and '10' as a substring for every
input alphabet Σ = {0, 1} without a dead state.
Q2: Convert NFA to DFA with simple method
RE is (a+b)*ab
Strings = {ab,aab,bab,aaab,bbbab,…}
DFA is
13
Q3: Apply kleene theorem:
Ans
14
So
ba*+(a+ba*b)(b+aa*b)*(a+aa*)
15
Q1: Write down the output generated by the following transducer after running
110010 and 00110101.
Input 1 1 0 0 1 0
State q0 q0 q0 q1 q3 q1 q3
Output 0 0 1 1 0 1
Output is 001101
Input 0 0 1 1 0 1 0 1
State q0 q1 q3 q1 q0 q1 q0 q1 q0
Output 1 1 0 1 1 1 1 1
Output is 11011111
Q2: covert NFA to DFA
State 0 1
-q0 q2 -
+q2 q0q1 q0
q0q1 q2 q0q2
+q0q2 q0q2 q0
16
DFA is
Q3: Regular expression to DFA
A) (a+b)
B) (a+b)*c(d+e)
17
Q4: Transition table from give machine
state 0 1
-q1 q1 q2
q1 q0 q2
q2 q2 q2