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}
If n,m both are equal then Its, not a Regular language so , impossible to make NFA ,DFA
,TG,GTG.
If n,m both are Not equal then Its, a Regular language so ,
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
Show that the set (02n 1n) is not regular using pumping lemma.
Ans
5
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. A–> a|aS| bAA
3. B –> b| aS | aBB
Ans:
Leftmost derivation:
1. S
2 aB S → aB
3. aaBB B → aBB
4. aabB B→b
5. aabbS B → bS
6. aabbaB S → aB
7. aabbabS B → bS
8. aabbabbA S → bA
9. aabbabba A→a
Q4: Convert TG to RE:
9
sorry a(a+b)*b ana tha mistake * nhi likha gya
So
RE is (a(a+b)*b)+(b(a+b)*a)
10
11
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
12
Q3: Apply kleene theorem:
Ans
13
So
ba*+(a+ba*b)(b+aa*b)*(a+aa*)
14
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 q0q1q2 q0
+q0q1q2 q0q1q2 q0q2
15
DFA is
Q3: Regular expression to DFA
A) (a+b)
B) (a+b)*c(d+e)
16
Q4: Transition table from give machine
state 0 1
-q0 q1 q2
q1 q0 q2
q2 q2 q2
17
Q1: Provide an example of non-regular languages?
This language is not regular:
L1 = { w ∈ {a,b}* : w = aibi, for some i ≥ 0 }
Q2: What is the concept of the Union of FA's?
The union of finite automata is an operation in automata theory that creates a new finite automaton
which recognizes the language that is the union of the languages recognized by two given finite
automata.
Q3: What is the corresponding FA for RE aa((a+b)(a+b))*
Q4: Differentiate between (a,b) and (a+b)?
(a,b) represents the set containing two symbols: a and b. A string that is part of a language over this
alphabet can only contain either a or b at each position, but not both simultaneously.
(a+b) represents the Regular Expression containing two symbols: a and b. that accept a or b at each
position, but not both simultaneously.
Q5: Define Transition Graph with an example?
A transition graph, abbreviated TG, is a collection of three things:
• A finite set of states, at least one of which is designated as the start state and some (maybe
none) of which are designated as final states.
• An alphabet Σ of possible input letters from which input strings are formed.
• A finite set of transitions (edge labels) that show how to go from some states to some others,
based on reading specified substrings of input letters (possibly even the null string λ).
18
Q6: Define NFA with an example?
NFA stands for non-deterministic finite automata. It is easy to construct an NFA when compared to DFA
for a given regular language. The finite automata are called NFA when there exist many paths for
specific input from the current state to the next state. Each NFA can be translated into DFA but every
NFA is Non DFA.
NFA is defined in the same way as DFA but with the following two exceptions,
• it contains multiple next states
• it contains ε transition.
Q7: what does transducers mean provide an example
A finite-state transducer is deterministic if the output is uniquely determined by the input
Q8: Differentiates Kleene Star Closure and PLUS?
Kleene Star
Include Lambda
a* = ^,a,aa,aaa,aaa,aaaa,aaaaa,….
Kleene PLUS
Lambda Not Include
a+ = a,aa,aaa,aaa,aaaa,aaaaa,….
19
Q9: Provide the statement of Pumping lemma?
If A is a regular language, then there is a number p where if s is any string in A of length at least p, then s
may be divided into three pieces, s = xyz, satisfying the following conditions:
• for each i ≥ 0, xyiz ∈ A.
• |y| > 0, and
• |xy| ≤ p.
Q10: What does PDA mean? Provide an example?
A pushdown automaton is a way to implement a context-free grammar in a similar way we design DFA
for a regular grammar. A DFA can remember a finite amount of information, but a PDA can remember
an infinite amount of information.
Basically, a pushdown automaton is −"Finite state machine" + "a stack"
Example
PDA that accepts L = { wwR | w = (a+b)* }
Q11: Define Context Free Grammars?
Context free grammar is a formal grammar which is used to generate all possible strings in a given
formal language.
Context free grammar G can be defined by four tuples as: (V, T, P, S)
• T describes a finite set of terminal symbols.
• V describes a finite set of non-terminal symbols
• P describes a set of production rules
• S is the start symbol.
Q12: Define derivation trees with an example?
Derivation tree is a graphical representation for the derivation of the given production rules for a given
CFG. The derivation tree is also called a parse tree.
A parse tree contains the following properties:
• The root node is always a node indicating start symbols.
• The derivation is read from left to right.
• The leaf node is always terminal nodes.
• The interior nodes are always the non-terminal nodes.
20
Example:
Production rules: Input
E=E+E a*b+c
E=E*E
E=a|b|c
Q13: Discuss Turing Machines shortly with an example?
A Turing Machine (TM) is a mathematical model which consists of an infinite length tape divided into
cells on which input is given. It consists of a head which reads the input tape. A state register stores the
state of the Turing machine. After reading an input symbol, it is replaced with another symbol, its
internal state is changed, and it moves from one cell to the right or left. If the TM reaches the final state,
the input string is accepted, otherwise rejected.
Example
For a*
Q14: Discuss Post Machines shortly with an example
A Post-Turing Machine is a program formulation of specially simple type of Turing Machine comprising a
variant of Emil Post's Turing- equivalent model of computation
Example
21
Q15: What is Universal Turing Machines?
The Universal Turing machine can go on then to simulate M on the rest of the content of the input tape.
A Universal Turing machine can thus simulate any other machine. The idea of connecting multiple Turing
machine gave an idea to Turing
• Can a Universal machine be created that can ‘simulate’ other machines?
• This machine is called as Universal Turing Machine
This machine would have three bits of information for the machine it is simulating
• A basic description of the machine.
• The contents of machine tape.
• The internal state of the machine.
Example:
Q16: What does Context Sensitive Grammar mean?
A Context-sensitive grammar is an Unrestricted grammar in which all the productions are of form
Where α and β are strings of non-terminals and terminals.
Context-sensitive grammars are more powerful than context-free grammars because there are some
languages that can be described by CSG but not by context-free grammars and CSL are less powerful
than Unrestricted grammar.
Q.17. Provide regular expressions of the following, where Σ = {0,1} except
i. Strings with odd number of 1's
1(11)*(0+1)*
ii. String ending in 1 and not containing 00
1((^+0+1)(10+11+01)*)1
iii. Language for C (programming language) identifiers
Nahi ata Bahi ya (Kuch Khud b kr lo )
22
iv. Strings with even number of 0's and odd number of 1's
(00)*(0+1)* + 1(11)*(0+1)*
Q18: Design Finite Automaton for the following regular expressions or languages:
Dast State Khud bna Lana
i. Language 1 of all strings in {a,b} that contains at least one of two substrings ab and bba.
ii. RE={11+110}*0
iii. RE = (0+1)*(10)
iv. A finite automaton M accepting (a+b)*(baaa)
23
Q19: Q.4. If L1 =(a, ab) and L2 = (ab) then find the Union, Intersection and Complement between L1
and L2 Also draw their respective automata and explain each step properly.
Union
RE= L1+L2
= a+ab+ab
= a+ab
L1 FA L2 FA
Table For Union:
Old State a b
-p0q0 p1q1 p3q3
+p1q1 p3q3 p2p2
p3q3 p3q3 p3q3
+p2p2 p3q3 p3q3
DFA For Union:
Intersection
n
RE= L1 L2
= ab
Table For Intersection:
Old State a b
-p0q0 p1q1 p3q3
p1q1 p3q3 p2p2
p3q3 p3q3 p3q3
+p2p2 p3q3 p3q3
24
DFA For Intersection:
For Complement
DFA
Complement
Q20: Convert the following NFA to DFA using Subset Construction Method, where Q3 is the accepting
Old State 0 1
-q0 q0 q0q1
q0q1 q0q2 q0q1q2
q0q2 q0q3 q0q1q3
q0q1q2 q0q2q3 q0q1q2q3
+q0q3 q0 q0q1
+q0q1q3 q0q2 q0q1q2
+q0q2q3 q0q3 q0q1q3
+q0q1q2q3 q0q2q3 q0q1q2q3
25
DFA
Q21: Prove that the language L=1n2 where n >= 0 is a non-regular language
Suppose L is regular. Then there must be a natural number m for all words z in L with length |z|≥m and
there exists a decomposition z=uvw,|uv|≤m,|v|>0 , so that u(vi)w is in the language for any i≥0.
Consider the string am2
Then uv=ak2=ax+y, for some k≤m and x=(k−1)2
Then v=ay=a2k−1
Let i=2 Then u(v2)w=ax+2y. But √𝑥 + 2𝑦 is not necessarily a natural number -> Contradiction! Hence, L
cannot be regular.
26
Q1: Describe the languages accepted by the following FA's
Language is
L= {a,b,aaa,bbb,aba,baa,aab,bab,….}
So RE is
27
(a+b)((a+b)(a+b))* Odd length string
Language is
L= {aa,ba,aaaa,baaa,baaa,aaba,baba,…}
So RE is
(aa+ba)((a+b) (a+b))* Even Length string without lambda starting with aa or ba.
Ya asa kr lo Even Length string without lambda Not starting with bb or ab.
Q2(a): Consider the CFG:
S→XYX
X→aX|bX|e
Y→ bbb
Prove that this generates the language of all strings with a triple b in then (a+b)*bbb(a+b)*
Generated string
L= {bbb,bbbb,abbb,abbba,abbbb,bbbba,….}
XYX XYX XYX XYX XYX XYX XYX XYX XYX
ebbbe axbbbe axbbbax bxbbbe bxbbbbx axbbbbx bxbbbax bxbbbax axbbbax
aebbbe aebbbae bebbbe bebbbbe aebbbbe bebbbae baxbbba abxbbbe
e
bbb abbb bbbb bbbbb abbbb bbbba abebbbe
abbba babbba
abbbb
28
Q2(b): calculate tree
Ans
So
S → 168
Q3: Out Of Syllabus
29
Q4: Build an FA that accepts only those words that have an even number of letters total
∑={a,b}
Build an FA that accepts only those words that do not end with ba
Build an FA that accepts only those words that begin or end with a double letter.
30
Find CFG's that generate these regular languages over the alphabet S= {a, b}:
1. The language defined by (aaa+b)*
S → X|Y|Z
X → aaaX| aaaZ
Y → bY | bZ
Z→ ^
2. The language defined by (a + b)* (bbb + aaa) (a + b)*
S → XYX
X → aX|bX|^
Y → bbb | aaa
3. All strings without the substring aaa.
Moja Sa asi koi CFG nhi Bni ( khud b kuch kro lo )
4. All strings that end in b and have an even number of b's in total.
S → SS
S → YbYb∣^
Y → aY∣^
5. The set of all strings of odd length.
S → aX | bX
X→ aS | bS | ^