Flat
Flat
Flat
1. Cover Page
2. Syllabus copy
3. Vision of the Department
4. Mission of the Department
5. PEOs and POs
6. Course objectives and outcomes
7. Brief notes on the importance of the course and how it fits into the curriculum
8. Prerequisites if any
9. Instructional Learning Outcomes
10. Course mapping with POs
11. Class Time Table
12. Individual Time Table
13. Lecture schedule with methodology being used/adopted
14. Detailed notes
15. Additional topics
16. University Question papers of previous years
17. Question Bank
18. Assignment Questions
19. Unit wise Quiz Questions and long answer questions
20. Tutorial problems
21. Known gaps ,if any and inclusion of the same in lecture schedule
22. Discussion topics , if any
23. References, Journals, websites and E-links if any
24. Quality Measurement Sheets
a. Course End Survey
b. Teaching Evaluation
25. Student List
26. Group-Wise students list for discussion topics
1
GEETHANJALI COLLEGE OF ENGINEERING AND TECHNOLOGY
DEPARTMENT OF CSE
2
2. SYLLABUS
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
UNIT I:
Fundamentals:
Strings, Alphabet, Language, Operations, Finite state machine, definitions, finite automaton
model, acceptance of strings, and languages, deterministic finite automaton and non
deterministic finite automaton, transition diagrams and Language recognizers.
Finite Automata:
NFA with transitions - Significance, acceptance of languages. Conversions & Equivalence:
Equivalence between NFA with and without transitions, NFA to DFA conversion,
minimization of FSM, equivalence between two FSMs, Finite Automata with output- Moore
and Melay machines.
UNIT II:
Regular Languages:
Regular sets, regular expressions, identity rules, Constructing finite Automata for a given regular
expressions, Conversion of Finite Automata to Regular expressions. Pumping lemma of regular
sets, closure properties of regular sets.
Grammar Formalism:
Regular grammars-right linear and left linear grammars, equivalence between regular linear
grammar and FA, inter conversion, Context free grammar, derivation trees, and sentential forms.
Right most and left most derivation of strings.
UNIT III:
Context Free Grammars:
Ambiguity in context free grammars. Minimization of Context Free Grammars. Chomsky normal
form, Greiback normal form, Pumping Lemma for Context Free Languages. Enumeration of
properties of CFL.
Push Down Automata:
Push down automata, definition, model, acceptance of CFL, Acceptance by final state and
acceptance by empty state and its equivalence. Equivalence of CFL and PDA, interconversion.
(Proofs not required). Introduction to DCFL and DPDA.
UNIT IV:
Turing Machine:
Turing Machine, definition, model, design of TM, Computable functions, recursively
enumerable languages. Churchs hypothesis, counter machine, types of Turing machines (proofs
not required). , linear bounded automata and context sensitive language
3
UNIT V:
Computability Theory:
Chomsky hierarchy of languages, decidability of, problems, Universal Turing Machine,
undecidability of posts. Correspondence problem, Turing reducibility, Definition of P and NP
problems, NP complete and NP hard problems.
TEXT BOOKS :
1. Introduction to Automata Theory Languages and Computation. Hopcroft H.E. and
Ullman J. D. Pearson Education.
2. Introduction to Theory of Computation Sipser 2nd edition Thomson.
REFERENCES :
1. Introduction to Formal Languages , Automata Theory and Computation
Kamala Krithivasan, Rama R
2. Introduction to Computer Theory, Daniel I.A. Cohen, John Wiley.
3. Theory of Computation : A Problem Solving Approach- Kavi Mahesh,
Wiley India Pvt. Ltd.
4. Elements of Theory of Computation, Lewis H.P. & Papadimition C.H. Pearson /PHI.
5. Theory of Computer Science Automata languages and computation -Mishra and
Chandrashekaran, 2nd edition, PHI.
6. Introduction to languages and the Theory of Computation, John C Martin, TMH.
4
5. PROGRAM EDUCATIONAL OBJECTIVES (PEOs) OF C.S.E.
DEPARTMENT
1. To provide graduates with a good foundation in mathematics, sciences and engineering
fundamentals required to solve engineering problems that will facilitate them to find
employment in industry and / or to pursue postgraduate studies with an appreciation for
lifelong learning.
2. To provide graduates with analytical and problem solving skills to design algorithms,
other hardware / software systems, and inculcate professional ethics, inter-personal skills
to work in a multi-cultural team.
3. To facilitate graduates to get familiarized with the art software / hardware tools, imbibing
creativity and innovation that would enable them to develop cutting-edge technologies of
multi-disciplinary nature for societal development.
5
6. An ability to recognize the importance of professional, ethical, legal, security and
social issues and addressing these issues as a professional.
7. An ability to analyze the local and global impact of systems /processes /applications
/technologies on individuals, organizations, society and environment.
8. An ability to function in multidisciplinary teams.
9. An ability to communicate effectively with a range of audiences.
10. Demonstrate knowledge and understanding of the engineering, management and
economic principles and apply them to manage projects as a member and leader in a
team.
11. A recognition of the need for and an ability to engage in life-long learning and
continuing professional development
12. Knowledge of contemporary issues.
13. An ability to apply design and development principles in producing software systems
of varying complexity using various project management tools.
14. An ability to identify, formulate and solve innovative engineering problems.
Course Objectives
The aim of this course is,
Course Description
6
Course Outcomes
A40509.2. The student will be able to demonstrate abstract models of computing, including
deterministic (DFA), non-deterministic (NFA), Push Down Automata(PDA) and
Turing (TM) machine models and their power to recognize the languages.
A40509.3 The student will be able to explain the application of machine models and
descriptors to compiler theory and parsing.
A40509.4. Students will be able to relate practical problems to languages, automata,
computability, and complexity.
A40509.6. Students will be able to apply mathematical and formal techniques for solving
problems in computer science.
A40509.7. Students will be able to explain the relationship among language classes and
grammars with the help of Chomsky Hierarchy.
7. Brief Notes on importance of course and how it fits into the curriculum
The theory of computation or computer theory is the branch of computer science and
mathematics that deals with whether and how efficiently problems can be solved on a model of
computation, using an algorithm. The field is divided into two major branches: computability
theory and complexity theory, but both branches deal with formal models of computation.
The purpose of this course is to acquaint the student with an overview of the theoretical
foundations of computer science from the perspective of formal languages.
Classify machines by their power to recognize languages.
Employ finite state machines to solve problems in computing.
Explain deterministic and non-deterministic machines.
Comprehend the hierarchy of problems arising in the computer sciences.
MOTIVATION
7
We will also look at simpler devices than Turing machines (Finite State Automata, Push-
down Automata, . . . ), and specication means, such as grammars and regular
expressions.
NP-hardness = what cannot be eciently computed
COURSE DESCRIPTION
This course will provide a foundation to the Theory of Computation. The student will
realize that the sometimes chaotic technology oriented world of computers has a very elegant
mathematical basis to it. This basis is deeply rooted in mathematics developed before the days
of modern computers. Our study will lead to some interesting implications concerning the
theoretical limits of computing. On the practical side, this course is a background for a course on
compilers. Topics covered in this course include: mathematical prerequisites, finite state
machines (automata), concept of a language and grammars, deterministic and non-deterministic
accepters, regular expressions and languages, context-free languages, normal/canonical forms,
pushdown automata, Turing machines, context sensitive languages, recursive and recursively
enumerable languages. Each of the language classes has two points of view: a class of automata
defining the language, and a class of grammars defining the language. This dual approach to
defining languages, will finally lead to the Chomsky hierarchy of languages. We shall observe
that the Turing Machine not only serves to define a language class, but also a mathematical
model for computation itself and defines the theoretical limits of computation.
8.Prerequisites
Set theory:
o Sets and operations on sets
o Relations and classification of relations
o Equivalence relations and partitions
o Functions operations of functions
o Fundamentals of logic
Graph theory
Algorithms and data structures at the level of an introductory programming sequence.
Mathematical induction and its applications
8
S.No. Unit Contents Outcomes
9
2 II Regular Languages: At the end of the chapter student will
Regular sets, regular
be
expressions, identity
Able to know the importance
rules, Constructing
of regular sets & expressions
finite Automata for a Able to construct FAs for
given regular expressions, REs and vice versa.
Conversion of Finite Able to use pumping lemma
Automata to Regular for show that a language is
expressions. Pumping not regular.
lemma of regular sets,
closure properties of
regular sets
3 III Context Free Grammars: At the end of the chapter the student
10
Context Free Languages. prove that a language is not
Enumeration of properties a CFL.
of CFL
11
5 V Computability Theory: At the end of the chapter the student
Chomsky hierarchy of
languages, decidability will be able to
of problems, Universal Know the hierarchy of
Turing machine,
languages and grammars.
undecidability of posts
correspondence problem, Know decidability of
Turing reducibility,
problems.
Definition of P and NP
Problems, NP complete and Genralize Turing
NP hard problems.
Machines into universal
TMs
Classify P and NP
(complete & hard)
Problems.
FLAT COURSE OUTCOMES PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PO13 PO14
A40509.1. Students 2 1 1
would be able to explain
basic concepts in formal
language theory,
grammars, automata
theory, computability
theory, and complexity
theory.
A40509.2. The student 2 1 2 1 1
will be able to
demonstrate abstract
models of computing,
including deterministic
(DFA), non-deterministic
(NFA), Push Down
Automata(PDA) and
Turing (TM) machine
models and their power
to recognize the
languages.
A40509.3 The student 1 1 2
will be able to explain
the application of
machine models and
descriptors to compiler
13
theory and parsing.
A40509.4. Students will 1 1 2
be able to relate practical
problems to languages,
automata, computability,
and complexity.
A40509.5. Students will 2 1
demonstrate an increased
level of mathematical
sophistication.
A40509.6. Students will 2 2 1
be able to apply
mathematical and formal
techniques for solving
problems in computer
science.
A40509.7. Students will 1 1
be able to explain the
relationship among
language classes and
grammars with the help
of Chomsky Hierarchy.
Period 1 2 3 4 5 6 7
FLA
Wednesday DAA DBMS ES DBMS LAB
T
14
JAV
Thursday FLAT FLAT JAVA DBMS CO NPTEL
A
DBM
Friday DAA DAA* CO JAVA LAB
S
DBM FLA
Saturday JAVA ES* CO* LIBRARY SPORTS/MH
S* T*
1 FLAT M.SRINIVAS
3 CO N.RADHIKA
4 DAA D.VENKATESHWARLU
6 ES SWARUPA
JAVA
7 LAB Dr S.NAGENDER KUMAR/M.SRINIVAS
10 * :- TUTORIAL
D.VENKATESH
Class Teacher WARLU V4
15
0 0
Period 1 2 3 4 5 6 7
FLA
Monday ES DBMS DBMS CRT NPTEL
T
Wednesd
LUNCH
JAV
FLAT CO JAVA DAA FLAT
ay A
DBM LIBRARY/S
Saturday JAVA CO* DAA* FLAT* ES*
S* PORTS
1 FLAT M.SRINIVAS
3 CO N.RADHIKA
4 DAA D.VENKATESHWARLU
6 ES SWARUPA
JAVA Dr S.NAGENDER
7 LAB KUMAR/D.VENKATESHWARLU
DBMS
8 LAB G.MADHURI AGRAWAL GUPTA/M.SIRISHA
10 * :- TUTORIAL
16
Year/Sem/Sec: II-B.Tech II- Room Acad Yr :
Semester C-Section No:LH-24 2014-15 WEF:12-03-2015
B.SRINI
Class Teacher VAS V4
12.0 12.
11.10
09.30- 10.20- 0- 50- 02.20- 03.10-
Time - 01.30-02.20
10.20 11.10 12.5 1.3 03.10 04.00
12.00
0 0
Period 1 2 3 4 5 6 7
Wednesd
JAVA DBMS
LUNCH
DBM DIGITAL
Friday
FLAT* ES* CO S JAVA DBMS LIBRARY
JAV
Saturday DBMS DBMS* NPTEL
DAA* A ES CO *
3 CO Ms P GOWTAMEE RADHA
4 DAA A.SRILAKSHMI
5 DBMS B.SRINIVAS
6 ES SWARUPA
JAVA
7 LAB Y V N PHANI KISHORE/CH ANUPAMA
17
DBMS
8 LAB B.SRINIVAS/N.RADHIKA
10 * :- TUTORIAL
A.SRIL
Class Teacher AXMI V4
12.0 12.
11.10
09.30- 10.20- 0- 50- 02.20- 03.10-
Time - 01.30-02.20
10.20 11.10 12.5 1.3 03.10 04.00
12.00
0 0
Period 1 2 3 4 5 6 7
JAV
Monday FLAT CO DBMS ES NPTEL
A
JAV
Tuesday DAA DBMS ES CRT LIBRARY
A
LUNCH
Wednesd DBM
FLAT DAA JAVA ES DBMS
ay S
DAA DIGITAL
Saturday CO CO* FLAT SPORTS
* JAVA LIBRARY
18
2 JAVA Y V N PHANI KISHORE
3 CO M.VAMSI KRISHNA
4 DAA A.SRILAKSHMI
5 DBMS B.SRINIVAS
6 ES SWARUPA
JAVA
7 LAB Y V N PHANI KISHORE/P.HARITHA
DBMS
8 LAB B.SRINIVAS/N.RADHIKA
10 * :- TUTORIAL
LESSON PLAN
S.NO No of Topics to be covered Regular / Remarks
Periods Additional Teaching
aids used
LCD/OH
P/BB
UNIT 1
1 01 Introduction regular BB
2 01 Alphabet, Strings, Language, Operations regular BB
3 01 Mealy Machine Definition and Examples
4 01 Designing a Mealy Machine
5 01 Moore Machine Definition and Examples
6 01 Equivalence of Moore and Mealy machines
7 01 Conversion between Mealy and Moore
machines
8 01 Finite Automaton Model regular BB
9 01 Accepting strings and languages regular BB
10 01 DFA & NDFA, Transition Diagrams and regular BB
Language Recognizers
11 01 NFA to DFA Conversion regular BB
19
12 01 NFA with Transitions significance, regular BB
acceptance of languages
13 01 Conversions and Equivalence : Equivalence regular BB
between NFA with and without transitions
14 01 Equivalence of two FSMs regular BB
15 01 Minimization of FSM. regular BB
16 01 Designing DFA for Elementary Languages regular BB
17 01 Designing DFA for Complex Languages regular BB
18 01 Designing DFA for Complex Languages with regular BB
not and from left to right constructs
19 01 Designing DFA for more examples regular BB/LCD
20 01 Designing NFA regular BB/LCD
20 No. of classes required
UNIT-II
UNIT-IV
50 01 Turing Machine : Turing Machine, regular BB
definition, model,ID
51 01 Design of TM, regular BB
52 01 Computable functions, regular BB
53 02 Examples on Designing TM regular BB
54 01 Recursively enumerable languages, regular BB
Churchs hypothesis,
55 01 counter machine regular BB
56 01 Types of Turing machines regular BB
57 01 Linear Bounded Automata(LBA) and regular BB
context sensitive language
58 09 No. of classes required
UNIT-V
LESSON PLAN
II Year II Semester CSE A
22
36 01 Context Free Grammars: Ambiguity in regular BB
context free grammars.
37 01 Minimization of Context Free Grammars- regular BB
Elimination of Useless symbols
UNIT-IV
50 01 Turing Machine : Turing Machine, regular BB
definition, model,ID
51 01 Design of TM, regular BB
52 01 Computable functions, regular BB
53 02 Examples on Designing TM regular BB
54 01 Recursively enumerable languages, regular BB
Churchs hypothesis,
55 01 counter machine regular BB
56 01 Types of Turing machines regular BB
57 01 Linear Bounded Automata(LBA) and regular BB
context sensitive language
58 09 No. of classes required
UNIT-V
UNIT-IV
50 01 Turing Machine : Turing Machine, regular BB
definition, model,ID
51 01 Design of TM, regular BB
52 01 Computable functions, regular BB
53 02 Examples on Designing TM regular BB
54 01 Recursively enumerable languages, regular BB
Churchs hypothesis,
55 01 counter machine regular BB
56 01 Types of Turing machines regular BB
57 01 Linear Bounded Automata(LBA) and regular BB
context sensitive language
58 09 No. of classes required
UNIT-V
LESSON PLAN
II Year II Semester CSE C
UNIT-II
UNIT-IV
50 01 Turing Machine : Turing Machine, regular BB
definition, model,ID
51 01 Design of TM, regular BB
52 01 Computable functions, regular BB
53 02 Examples on Designing TM regular BB
54 01 Recursively enumerable languages, regular BB
Churchs hypothesis,
55 01 counter machine regular BB
56 01 Types of Turing machines regular BB
57 01 Linear Bounded Automata(LBA) and regular BB
context sensitive language
58 09 No. of classes required
UNIT-V
LESSON PLAN
II Year II Semester CSE D
UNIT-IV
50 01 Turing Machine : Turing Machine, regular BB
definition, model,ID
51 01 Design of TM, regular BB
52 01 Computable functions, regular BB
53 02 Examples on Designing TM regular BB
54 01 Recursively enumerable languages, regular BB
Churchs hypothesis,
55 01 counter machine regular BB
56 01 Types of Turing machines regular BB
57 01 Linear Bounded Automata(LBA) and regular BB
context sensitive language
58 09 No. of classes required
UNIT-V
30
14. Lecture Notes:
UNIT I:
Fundamentals
Symbol An atomic unit, such as a digit, character, lower-case letter, etc. Sometimes a
word. [Formal language does not deal with the meaning of the symbols.]
Example:
= {0, 1}
* = {, 0, 1, 00, 01, 10, 11, 000, 001,}
+ = {0, 1, 00, 01, 10, 11, 000, 001,}
A language is:
1) A set of strings from some alphabet (finite or infinite). In other words,
2) Any subset L of *
Examples:
= {0, 1}
L = {x | x is in * and x contains an even number of 0s}
= {0, 1, 2,, 9, .}
L = {x | x is in * and x forms a finite length real number}
= {0, 1.5, 9.326,}
= {English words}
L = {x | x is in * and x is a syntactically correct English sentence}
A finite state machine has a set of states and two functions called the next-state function
and the output function
o The set of states correspond to all the possible combinations of the internal
storage
If there are n bits of storage, there are 2n possible states
o The next state function is a combinational logic function that given the inputs and
the current state, determines the next state of the system
The output function produces a set of outputs from the current state and the inputs
Finite Automata
32
Nondeterministic (NFA) There is a fixed number of states but we can be in
multiple states at one time
While NFAs are more expressive than DFAs, we will see that adding nondeterminism
does not let us define any language that cannot be defined by a DFA.
One way to think of this is we might write a program using a NFA, but then when it is
compiled we turn the NFA into an equivalent DFA.
Intuitively, (q,s) is the state entered by M after reading symbol s while in state q.
33
Let M = (Q, , , q0, F) be a DFA and let w be in *. Then w is accepted by M iff
(q0,w) = p for some state p in F.
Let M = (Q, , , q0, F) be a DFA. Then the language accepted by M is the set:
L(M) = {w | w is in * and (q0,w) is in F}
Let L be a language. Then L is a regular language iff there exists a DFA M such that
L = L(M).
Let M1 = (Q1, 1, 1, q0, F1) and M2 = (Q2, 2, 2, p0, F2) be DFAs. Then M1 and M2 are
equivalent iff L(M1) = L(M2).
Notes:
A DFA M = (Q, , ,q0,F) partitions the set * into two sets: L(M) and
* - L(M).
Similarly, if L(M1) = L(M2) then L(M1) is a subset of L(M2) and L(M2) is a subset
of L(M1).
36
Let M = (Q, , ,q0,F) be an NFA. Then the language accepted by M is the set:
L(M) = {w | w is in * and ({q0},w) contains at least one state in F}
TRANSITION DIAGRAMS
37
38
NFAs with Moves
: (Q x ( U {})) > 2Q
(q,s) -The set of all states p such that there is a transition
labeled a from q to p, where a is in U {}
Sometimes referred to as an NFA- other times, simply as an NFA.
Let M = (Q, , ,q0,F) be an NFA-. Then the language accepted by M is the set:
L(M) = {w | w is in * and ^({q0},w) contains at least one state in F}
39
Another equivalent definition:
L(M) = {w | w is in * and w is accepted by M}
Therefore, if L is a regular language then there exists an NFA- M such that L = L(M).
Lemma 1: Let M be an NFA. Then there exists a NFA- M such that L(M) = L(M).
Proof: Every NFA is an NFA-. Hence, if we let M = M, then it follows that L(M) =
L(M).
Lemma 2: Let M be an NFA-. Then there exists a NFA M such that L(M) = L(M).
Proof:
Let M = (Q, , ,q0,F) be an NFA-.
Define an NFA M = (Q, , ,q0,F) as:
F = F U {q0} if -closure(q0) contains at least one state from F
F = F otherwise
(q, a) = ^(q, a) - for all q in Q and a in
Notes:
: (Q x ) > 2Q is a function
M has the same state set, the same alphabet, and the same start state as M
M has no transitions
40
41
42
Theorem: Let L be a language. Then there exists an NFA M such that L= L(M) iff there
exists an NFA- M such that L = L(M).
Proof:
(if) Suppose there exists an NFA- M such that L = L(M). Then by Lemma 2 there
exists an NFA M such that L = L(M).
(only if) Suppose there exists an NFA M such that L = L(M). Then by Lemma 1 there
exists an NFA- M such that L = L(M).
Therefore, if L is a regular language then there exists an NFA M such that L = L(M).
It follows that NFAs accept all regular languages. But do NFAs accept all?
43
Lemma 1: Let M be an DFA. Then there exists a NFA M such that L(M) = L(M).
Proof: Every DFA is an NFA. Hence, if we let M = M, then it follows that L(M) =
L(M).
The above is just a formal statement of the observation from the above example.
Lemma 2: Let M be an NFA. Then there exists a DFA M such that L(M) = L(M).
Proof: (sketch)
44
Let M = (Q, , ,q0,F).
q0 = [q0]
45
Theorem: Let L be a language. Then there exists an DFA M such that L = L(M) iff
there exists an NFA M such that L = L(M).
Proof:
(if) Suppose there exists an NFA M such that L = L(M). Then by Lemma 2 there exists
an DFA M such that L = L(M).
(only if) Suppose there exists an DFA M such that L = L(M). Then by Lemma 1 there
exists an NFA M such that L = L(M).
Acceptor:
The symbols of the sequence
are presented sequentially to a machine M. M responds with a binary signal to each input.
If the string scanned so far is accepted, then the light goes on, else the light is off.
46
s(t) s(i) s(2) s(1)
M
Input channel Output signal
Initialize
A language acceptor
Transducer
Abstract machines that operate as transducers are of interest in connection with the
translation of languages. The following transducer produces a sentence
M
Input channel Output channel
Initialize
If this machine is deterministic, then each sentence of an input language is translated into a
specific sentence of an output language.
47
Generator
M
Output channel
Initialize
We will begin our study with the transducer model of abstract machine (or automaton). We
often refer to such a device as a Finite State Machine (FSM) or as an automaton with output.
FSM
Input string Output string
The FSM model arises naturally from physical settings in which information-denoting
signals are processed. Physical reality dictates that such systems are finite.
Only a finite number of operations may be performed in a finite amount of time. Such
systems are necessarily discrete.
Problems are quite naturally decomposed into sequences of steps hence our model is
sequential.
We require that our machine not be subject to uncertainty, hence its behavior is
deterministic.
48
There are two finite state machine models :
Where,
f:Q*SQ
g : output function
g:Q*SR
Example#1:
Design a FSM (Mealy model) which takes in binary inputs and produces a 1 as output
whenever the parity of the input string ( so far ) is even.
S = R = {0, 1}
When designing such models, we should ask ourselves What is the state set of the
machine?.
The state set Q corresponds to what we need to remember about input strings. We note
that the number of possible input strings corresponds to |S*| which is countably infinite.
We observe, however, that a string may have only one of two possible parities.
And this is all that our machine must remember about a string scanned so far.
Hence |Q| = 2 where Q = {E, } with qI = E indicating the string has even parity and if Mt
is in state , then the string has odd parity.
And finally, of course, we must specify the output function g for this Mealy machine.
49
According to this machines specifications, it is supposed to produce an output of 1
whenever the parity of the input string so far is even. Hence, all arcs leading into state E
should be labeled with a 1 output.
0/1 0/0
1/0
E
1/1
Observe our notation that g(, 1) = 1 is indicated by the arc from state to state E with a
1 after a slash.
The output of our machine is 0 when the current string ( so far ) has odd parity.
for this E E, 1 , 0
parity machine
, 0 E, 1
Observe for the input 10100011 our machine produces the output sequence 00111101
50
Example#2:
Construct a Mealy model of an FSM that behaves as a two-unit delay. i.e.
r(t) = {s(t - 2), t > 2
{ 0 , otherwise
A sample input/output session is given below :
time 1 2 3 4 5 6 7 8 9
stimulus 0 0 0 1 1 0 1 0 0
response 0 0 0 0 0 1 1 0 1
Moore model of FSM the output function assigns an output symbol to each state.
Ms = <Q, S, R, f, h, qI>
f:Q*SQ
h : output function
h:QR
Example#1:
Design a Moore machine that will analyze input sequences in the binary alphabet S = {0, 1}.
Let w = s(1) s(2) s(t) be an input string
N0(w) = number of 0s in w
N1(w) = number of 1s in w
stimulus 1 1 0 1 1 1 0 0
response 0 1 2 1 2 3 0 3 2
Observe that the length of the output sequence is one longer than the input sequence.
Why is this so?
Btw : This will always be the case.
1
B, 1
1
0 0
A, 0 C, 2
0
0
1
D, 3 1
State diagram
0 1
A D B 0
B A C 1
C B D 2
D C A 3
State table
52
1 1 0 1
(A, 0) (B, 1) (C, 2) (B, 1) (C, 2)
1 1 0 0
(D, 3) (A, 0) (D, 3) (C, 2)
Example#2:
Design a Moore machine that functions as a pattern recognizer for 1011. Your machine
should output a 1 whenever this pattern matches the last four inputs, and there has been
no overlap, otherwise output a 0.
t = 1 2 3 4 5 6 7 8 9 10 11 12
S= 0 1 0 1 1 0 1 1 0 1 1 0
R=0 0 0 0 1 0 0 0 0 0 0 1 0
time 1 2 3 4 5 6 7 8 9 10 11 12 13 14
input 0 0 0 0 1 0 0 0 1 0 0 0 1 0
output 0 1 0 1 0 0 0 0 1 0 1 0 0 1
This problem is useful in fault detection and fault location experiments with sequential
circuits ( i.e. digital circuits with memory ).
53
One designs a computer circuit. Six months (or six years) later, how does one know that
the circuit is working correctly?
The procedure to solve this problem is helpful in fault diagnosis of digital circuits.
The Mealy and Moore models of finite state machines are equivalent ( actually similar ).
i.e. Mt Ms
q1,1
1 1
0 0
q0,0 q2,2
Ms : A mod 3 counter
54
0/0 0/1
M1 : 1/1
q q
0 1
1/0
M2 : 0/0 0/1
1/1
q q
0 1
1/1
M3 : 0/0 0/0
1/1
q q
0 1
1/1
UNIT II:
Regular Expressions
Highlights:
Let r and s be regular expressions that represent the sets R and S, respectively.
r+s Represents the set R U S (precedence 3)
rs Represents the set RS (precedence 2)
r* Represents the set R* (highest precedence)
(r) Represents the set R (not an op, provides precedence)
Identities:
1. u = u = Multiply by 0
2. u = u = u Multiply by 1
3. * =
4. * =
5. u+v = v+u
56
6. u + = u
7. u + u = u
8. u* = (u*)*
9. u(v+w) = uv+uw
= u*(u+v)*
= (u+vu*)*
= (u*v*)*
= u*(vu*)*
= (u*v)*u*
Note: Throughout the following, keep in mind that a string is accepted by an NFA- if
there exists a path from the start state to a final state.
Lemma 1: Let r be a regular expression. Then there exists an NFA- M such that L(M) =
L(r). Furthermore, M has exactly one final state with no transitions out of it.
Basis: OP(r) = 0
57
Inductive Hypothesis: Suppose there exists a k 0 such that for any regular expression r
where 0 OP(r) k, there exists an NFA- such that L(M) = L(r). Furthermore, suppose
that M has exactly one final state.
Inductive Step: Let r be a regular expression with k + 1 operators (OP(r) = k + 1), where
k + 1 >= 1.
Case 1) r = r1 + r2
Since OP(r) = k +1, it follows that 0<= OP(r1), OP(r2) <= k. By the inductive
hypothesis there exist NFA- machines M1 and M2 such that L(M1) = L(r1) and
L(M2) = L(r2). Furthermore, both M1 and M2 have exactly one final state.
Case 2) r = r1r2
Since OP(r) = k+1, it follows that 0<= OP(r1), OP(r2) <= k. By the inductive
hypothesis there exist NFA- machines M1 and M2 such that L(M1) = L(r1) and
L(M2) = L(r2). Furthermore, both M1 and M2 have exactly one final state.
58
Case 3) r = r1*
Since OP(r) = k+1, it follows that 0<= OP(r1) <= k. By the inductive hypothesis
there exists an NFA- machine M1 such that L(M1) = L(r1). Furthermore, M1 has
exactly one final state.
Example:
Solution: r = r1r2
r1 = 0
r2 = (0+1)*
r2 = r3*
r3 = 0+1
r3 = r4 + r5
r4 = 0
r5 = 1
Transition graph:
59
Definitions Required to Convert a DFA to a Regular Expression
Let M = (Q, , , q1, F) be a DFA with state set Q = {q1, q2, , qn}, and define:
Ri,j = { x | x is in * and (qi,x) = qj}
Ri,j is the set of all strings that define a path in M from qi to qj.
60
Observations:
Lemma 2: Let M = (Q, , , q1, F) be a DFA. Then there exists a regular expression r
such that L(M) = L(r).
Proof:
First we will show (by induction on k) that for all i,j, and k, where 1 i,j n
And 0 k n, that there exists a regular expression r such that L(r) = Rki,j .
Basis: k=0
R0i,j contains single symbols, one for each transition from qi to qj, and possibly if
i=j.
61
Case 1) No transitions from qi to qj and i != j
r0i,j =
Inductive Hypothesis:
Suppose that Rk-1i,j can be represented by the regular expression rk-1i,j for all
1 i,j n, and some k1.
Inductive Step:
Consider Rki,j = Rk-1i,k (Rk-1k,k)* Rk-1k,j U Rk-1i,j . By the inductive hypothesis there
exist regular expressions rk-1i,k , rk-1k,k , rk-1k,j , and rk-1i,j generating Rk-1i,k , Rk-1k,k ,
Rk-1k,j , and Rk-1i,j , respectively. Thus, if we let
62
63
64
Pumping Lemma for Regular Languages
Pumping Lemma relates the size of string accepted with the number of states in a DFA
Let M be a DFA with |Q| = n states. If there exists a string x in L(M), such that |x| n,
then there exists a way to write it as x = uvw, where u,v, and w are all in * and:
1 |uv| n
|v| 1
such that, the strings uviw are also in L(M), for all i 0
65
Let:
u = a1as
v = as+1at
In addition, let:
w = at+1am
In other words, when processing the accepted string x, the loop was traversed once, but
could have been traversed as many times as desired, and the resulting string would still
be accepted.
66
Closure Properties of Regular Languages
67
Grammar
Example:
Consider the grammar G = ({S}, {a, b}, S, P) with P given by
S aSb, S _.
For instance, we have S aSb aaSbb aabb.
It is not hard to conjecture that L(G) = {anbn | n 0}.
o Example#1:
L((ab)*a)
68
S Aab
A Aab | aB
Ba
is an example of a left-linear grammar.
L(aaab(ab)*)
o Example#3:
Regular Grammar
A linear grammar is a grammar in which at most one variable can occur on the right side
of any production without restriction on the position of this variable.
To test if L = M
69
Example:
We can see" that both DFA accept L(+(0+1)*0). The result of the TF-algo is
It's not hard to show that regular grammars generate and nfa's accept the same class of
languages: the regular languages!
It's a long proof, where we must show that
o Any finite automaton has a corresponding left- or right-linear grammar,
o And any regular grammar has a corresponding nfa.
Example:
Let S aA A abS | b
70
CONTEXT FREE-GRAMMAR
Where,
V - A finite set of variables or non-terminals
T - A finite set of terminals (V and T do not intersect)
P - A finite set of productions, each of the form A > ,
Where A is in V and is in (V U T)*
Note: that may be .
S - A starting non-terminal (S is in V)
Example#1 CFG:
Example Derivations:
Definition: Let G = (V, T, P, S) be a CFG. A tree is a derivation (or parse) tree if:
Every vertex has a label from V U T U {}
The label of the root is S
If a vertex with label A has children with labels X1, X2,, Xn, from left to right,
then
A > X1, X2,, Xn
must be a production in P
If a vertex has label , then that vertex is a leaf and the only child of its parent
More Generally, a derivation tree can be defined with any non-terminal as the root.
71
Notes:
Root can be any non-terminal
Leaf nodes can be terminals or non-terminals
A derivation tree with root S shows the productions used to obtain a sentential
form.
Sentential Form
72
Definition: A derivation is leftmost (rightmost) if at each step in the derivation a production is
applied to the leftmost (rightmost) non-terminal in the sentential form.
The first derivation above is leftmost, second is rightmost and the third is neither.
UNIV III:
Note: Given a CFL L, there may be more than one CFG G with L = L(G). Some
ambiguous and some not.
73
The string has two left-most derivations, and therefore has two distinct parse trees and is
ambiguous .
Definition:
Let G = (V, T, S, P) be a context-free grammar. A variable A V is said to be useful if
and only if there is at least one w L(G) such that
S xAy w
with x, y (V T).
A is useless variable and the production S A plays no role since A cannot be eventually
transformed into a terminal string; while A can appear in a sentential form derived from
S, this sentential form can never lead to sentence!
74
Hence, removing S A (and A aA) does not change the language, but does simplify
the grammar.
B is useless so is the production B bA! Observe that, even though a terminal string can
be derived from B, there is no way to get to B from S, i.e. cannot achieve
S xBy.
Example:
Eliminate useless symbols and productions from G = (V, T, S, P), where
V = {S, A, B, C}, T = {a, b} and
P consists of
S aS | A | C
Aa
B aa
C aCb
First, note that the variable C cannot lead to any terminal string, we can then remove C
and its associated productions, we get G1 with V1 = {S, A, B}, T1 = {a} and P1 consisting
of
S aS | A
Aa
B aa
Next, we identify variables that cannot be reached from the start variable. We can create
a dependency graph for V1. For a context-free grammar, a dependency graph has its
vertices labeled with variables with an edge between any two vertices I and J if there is a
production of the form
I xJy
Consequently, the variable B is shown to be useless and can be removed together with its
associated production.
The resulting grammar G = (V, T, S, P) is with V = {S, A}, T = {a} and P consisting
of
S aS | A
Aa
75
Eliminations of -Production
Definition :
a) Any production of a context-free grammar of the form
A
is called a -production.
If a grammar contains some -productions or nullable variables but does not generate the
language that contains an empty string, the -productions can be removed!
Example:
Consider the grammar, G with productions
S aS1b
S1 aS1b |
L(G) = {a b | n 1} which is a -free language. The -production can be removed after
n n
adding new productions obtained by substituting for S1 on the right hand side.
Theorem:
Let G be any context-free grammar with L(G). There exists an equivalent grammar
G without -productions.
Proof :
Find the set VN of all nullable variables of G
1. For all productions A , put A in VN
2. Repeat the following step until no further variables are added to VN:
For all productions
B A1A2An
With the resulting VN, P can be constructed by looking at all productions in P of the
form
A x1x2xm, m 1
where each xi V T.
76
For each such production of P, we put in P the production plus all productions generated
by replacing nullable variables with in all possible combinations. However, if all xi are
nullable, the resulting production A is not put in P.
Example:
Eliminations of Unit-Production
Definition:
Any production of a context-free grammar of the form
AB
where A, B V is called a unit-production.
Theorem:
Let G = (V, T, S, P) be any context-free grammar without -productions. There exists a
context-free grammar G = (V, T, S, P) that does not have any unit-productions and that
is equivalent to G.
Proof:
First of all, Any unit-production of the form A A can be removed without any effect.
We then need to consider productions of the form A B where A and B are different
variables.
77
The new grammar G is generated by first putting in P all non-unit-productions of P.
Then, for all A and B with A B, we add to P
A y1 | y2 | | yn
where B y1 | y2 | | yn is the set of all rules in P with B on the left. Not that the rules
are taken from P, therefore, none of yi can be a single variable! Consequently, no unit-
productions are created by this step.
Example:
Consider a grammar G with
S Aa | B
A a | bc | B
B A | bb
We have S A, S B, A B and
B A.
Theorem:
Let L be a context-free language that does not contain . There exists a context-free
grammar that generates L and that does not have any useless productions, -productions
or unit-productions.
78
Proof:
We need to remove the undesirable productions using the following sequence of steps.
1. Remove -productions
2. Remove unit-productions
3. Remove useless productions
Definition:
A context-free grammar is in Chomsky normal form if all productions are of the form
A BC
or
Aa
where A, B, C V, and a T.
Note: that the number of symbols on the right side of productions is strictly limited; not
more than two symbols.
Example:
The following grammar is in Chomsky normal form.
S AS | a
A SA | b
Theorem:
Any context-free grammar G = (V, T, S, P) with L(G) has an equivalent grammar G
= (V, T, S, P) in Chomsky normal form.
Proof:
First we assume (based on previous Theorem) without loss of generality that G has no -
productions and no unit-productions. Then, we show how to construct G in two steps.
Step 1:
Construct a grammar G1 = (V1, T, S, P1) from G by considering all productions in
P of the form
A x1x2xn
Where each xi is a symbol either in V or in T.
79
Note that if n = 1, x1 must be a terminal because there is no unit-productions in G.
In this case, put the production into P1.
Step 2:
The length of right side of productions is reduced by means of additional
variables wherever necessary. First of all, all productions with a single terminal
or two variables (n = 2) are put into P. Then, for any production with n 2, new
variables D1, D2, are introduced and the following productions are put into P.
A C1D1
D1 C2D2
Dn-2 Cn-1Cn
Example:
Convert to Chomsky normal form the following grammar G with productions.
S ABa
A aab
B Ac
Solution:
Step 1:
New variables Ba, Bb, Bc are introduced and a new grammar G1 is obtained.
S ABBa
A BaBaBb
B ABc
Ba a
Bb b
Bc c
Step 2:
80
Additional variables are introduced to reduce the length of the first two
productions making them into the normal form, we finally obtain G.
S AD1
D1 BBa
A BaD2
D2 BaBb
B ABc
Ba a
Bb b
Bc c
Definition:
A context-free grammar is said to be in Greibach normal form if all productions have the
form
A ax
where a T and x V
Note that the restriction here is not on the number of symbols on the right side, but rather
on the positions of the terminals and variables.
Example:
The following grammar is not in Greibach normal form.
S AB
A aA | bB | b
Bb
Theorem:
For every context-free grammar G with L(G), there exists an equivalent grammar G
in Greibach normal form.
Conversion
81
2. From intermediate grammar into Greibach
Step1:
Before
A Aa | b
After
A bZ | b
Z aZ | a
Remove the rule with direct left recursion, and create a new one with
recursion on the right
Step2:
Before
A Aa | Ab | b | c
After
A bZ | cZ | b | c
Z aZ | bZ | a | b
Remove the rules with direct left recursion, and create new ones with
recursion on the right
Step3:
Before
A AB | BA | a
Bb|c
After
A BAZ | aZ | BA | a
Z BZ | B
Bb|c
where A, B and C are all in V and a is in T, then G is in Chomsky Normal Form (CNF).
Example:
S > AB | BA | aSb
A > a
B > b
Theorem: Let L be a CFL not containing {}. Then there exists a CNF grammar G such
that L = L(G).
Definition: Let T be a tree. Then the height of T, denoted h(T), is defined as follows:
If T consists of a single vertex then h(T) = 0
If T consists of a root r and subtrees T1, T2, Tk, then h(T) = maxi{h(Ti)} + 1
Corollary: Let G be a CFG in CNF, and let w be a string in L(G). If |w| 2k, where k
0, then any derivation tree for w using G has height at least k+1.
Lemma:
Let G = (V, T, P, S) be a CFG in CNF, and let n = 2|V|. If z is a string in L(G) and |z| n,
then there exist strings u, v, w, x and y in T* such that z=uvwxy and:
|vx| 1 (i.e., |v| + |x| 1)
|vwx| n
uviwxiy is in L(G), for all i 0
Proof:
Since |z| n = 2k, where k = |V|, it follows from the corollary that any derivation tree for
z has height at least k+1.
83
Such a path has:
Length k+1 (i.e., number of edges in the path is k+1)
At least k+2 nodes
1 terminal
At least k+1 non-terminals
Since there are only k non-terminals in the grammar, and since k+1 appear on this long
path, it follows that some non-terminal (and perhaps many) appears at least twice on this
path.
Consider the first non-terminal that is repeated, when traversing the path from the leaf to
the root.
This path, and the non-terminal A will be used to break up the string z.
84
85
In addition, (2) also tells us:
S =>* uAy (1)
=>* uvAxy (2)
86
=>* uv2Ax2y (2)
=>* uv2wx2y (3)
More generally:
S =>* uviwxiy for all i>=1
And also:
S =>* uAy (1)
=>* uwy (3)
Hence:
S =>* uviwxiy for all i>=0
What is n?
n = 2k, where k is the number of non-terminals in the grammar.
Since the height of this subtree is 2, the first production is A->V1V2. Since no non-
terminal derives the empty string (in CNF), either V1 or V2 must derive a non-empty
v or x. More specifically, if w is generated by V1, then x contains at least one symbol,
and if w is generated by V2, then v contains at least one symbol.
Why is |vwx| n?
Observations:
The repeated variable was the first repeated variable on the path from the
bottom, and therefore (by the pigeon-hole principle) the path from the leaf
to the second occurrence of the non-terminal has length at most k+1.
Since the path was the largest in the entire tree, this path is the longest in
the subtree rooted at the second occurrence of the non-terminal. Therefore
the subtree has height k+1. From the lemma, the yield of the subtree has
length 2k=n.
87
CFL Closure Properties
Theorem#1:
The context-free languages are closed under concatenation, union, and Kleene closure.
Proof:
Start with 2 CFL L(H1) and L(H2) generated by H1 = (N1,T1,R1,s1) and H2 =
(N2,T2,R2,s2).
Assume that the alphabets and rules are disjoint.
Concatenation:
Formed by L(H1)L(H2) or a string in L(H1) followed by a string in L(H2) which can be
generated by L(H3) generated by H3 = (N3,T3,R3,s3). N3 = N1 N2, T3 = T1 T2, R3
= R1 R2 {s3 -->s1s2} where s3 s1s2 is a new rule introduced. The new rule
generates a string of L(H1) then a string of L(H2). Then L(H1) L(H2) is context-free.
Union:
Formed by L(H1) L(H2) or a string in L(H1) or a string in L(H2). It is generated by
L(H3) generated by H4 = (N4,T4,R4,s4) where N4 = N1 N2, T4 = T1 T2, and R4 =
R1 R2 {s4-->s1, s4 s2}, the new rules added will create a string of L(H1) or
L(H2). Then L(H1) L(H2) is context-free.
Kleene:
Formed by L(H1)* is generated by the grammar L(H5) generated by H5 = (N1,T1,R5,s1)
with R5 = R1 {s1e, s1s1s1}. L(H5) includes e, every string in L(H1), and through
i-1 applications of s1s1s1, every string in L(H1)i. Then L(H1)* is generated by H5 and
is context-free.
Theorem#2:
The set of context-free languages is not closed under complementation or intersection.
Proof:
Intersections of two languages L1 L2 can be defined in terms of the Complement and
Union operations as follows:
L1 L2 - - L1 - L2)
Therefore if CFL are closed under intersection then it is closed under compliment and if
closed under compliment then it is closed under intersection.
88
The proof is just showing two context-free languages that their intersection is not a
context-free language.
Informally:
A PDA is an NFA- with a stack.
Transitions are modified to accommodate stack operations.
Questions:
What is a stack?
How does a stack help?
A DFA can remember only a finite amount of information, whereas a PDA can remember
an infinite amount of (certain types of) information.
Example:
{0n1n | 0=<n} Is not regular.
89
{0n1n | 0nk, for some fixed k} Is regular, for any fixed k.
For k=3:
L = {, 01, 0011, 000111}
Q on the LHS means that at each step in a computation, a PDA must consider its current state.
on the LHS means that at each step in a computation, a PDA must consider the symbol on
top of its stack.
U {} on the LHS means that at each step in a computation, a PDA may or may not consider
the current input symbol, i.e., it may have epsilon transitions.
Finite subsets on the RHS means that at each step in a computation, a PDA will have several
options.
Q on the RHS means that each option specifies a new state.
* on the RHS means that each option specifies zero or more stack symbols that will replace
the top stack symbol.
Current state is q
Current input symbol is a
Symbol currently on top of the stack z
Move to state pi from q
Replace z with i on the stack (leftmost symbol on top)
Move the input head to the next input symbol
91
Two types of PDA transitions #2:
(q, , z) = {(p1,1), (p2,2),, (pm,m)}
Current state is q
Current input symbol is not considered
Symbol currently on top of the stack z
Move to state pi from q
Replace z with i on the stack (leftmost symbol on top)
No input symbol is read
:
(1) (q1, (, #) = {(q1, L#)}
(2) (q1, ), #) =
(3) (q1, (, L) = {(q1, LL)}
(4) (q1, ), L) = {(q1, )}
(5) (q1, , #) = {(q1, )}
(6) (q1, , L) =
Goal: (acceptance)
Terminate in a non-null state
Read the entire input string
Terminate with an empty stack
Informally, a string is accepted if there exists a computation that uses up all the input and leaves
92
the stack empty.
Transition Diagram:
Example Computation:
Current Input Stack Transition
(()) #
()) L# (1) - Could have applied rule
)) LL# (3) (5), but it would have
) L# (4) done no good
# (4)
- (5)
:
(1) (q1, 0, R) = {(q1, BR)} (9) (q1, 1, R) = {(q1, GR)}
(2) (q1, 0, B) = {(q1, BB)} (10) (q1, 1, B) = {(q1, GB)}
(3) (q1, 0, G) = {(q1, BG)} (11) (q1, 1, G) = {(q1, GG)}
(4) (q1, c, R) = {(q2, R)}
(5) (q1, c, B) = {(q2, B)}
(6) (q1, c, G) = {(q2, G)}
(7) (q2, 0, B) = {(q2, )} (12) (q2, 1, G) = {(q2, )}
(8) (q2, , R) = {(q2, )}
Notes:
Only rule #8 is non-deterministic.
Rule #8 is used to pop the final stack symbol off at the end of a computation.
93
Example Computation:
(1) (q1, 0, R) = {(q1, BR)} (9) (q1, 1, R) = {(q1, GR)}
(2) (q1, 0, B) = {(q1, BB)} (10) (q1, 1, B) = {(q1, GB)}
(3) (q1, 0, G) = {(q1, BG)} (11) (q1, 1, G) = {(q1, GG)}
(4) (q1, c, R) = {(q2, R)}
(5) (q1, c, B) = {(q2, B)}
(6) (q1, c, G) = {(q2, G)}
(7) (q2, 0, B) = {(q2, )} (12) (q2, 1, G) = {(q2, )}
(8) (q2, , R) = {(q2, )}
Example Computation:
(1) (q1, 0, R) = {(q1, BR)} (9) (q1, 1, R) = {(q1, GR)}
(2) (q1, 0, B) = {(q1, BB)} (10) (q1, 1, B) = {(q1, GB)}
(3) (q1, 0, G) = {(q1, BG)} (11) (q1, 1, G) = {(q1, GG)}
(4) (q1, c, R) = {(q2, R)}
(5) (q1, c, B) = {(q2, B)}
(6) (q1, c, G) = {(q2, G)}
(7) (q2, 0, B) = {(q2, )} (12) (q2, 1, G) = {(q2, )}
(8) (q2, , R) = {(q2, )}
Definition: Let M = (Q, , , , q0, z0, F) be a PDA. The language accepted by empty stack,
denoted LE(M), is the set
Definition: Let M = (Q, , , , q0, z0, F) be a PDA. The language accepted by final state,
denoted LF(M), is the set
Definition: Let M = (Q, , , , q0, z0, F) be a PDA. The language accepted by empty stack and
final state, denoted L(M), is the set
Lemma 1: Let L = LE(M1) for some PDA M1. Then there exits a PDA M2 such that L = LF(M2).
Lemma 2: Let L = LF(M1) for some PDA M1. Then there exits a PDA M2 such that L = LE(M2).
Theorem: Let L be a language. Then there exits a PDA M1 such that L = LF(M1) if and only if
there exists a PDA M2 such that L = LE(M2).
Corollary: The PDAs that accept by empty stack and the PDAs that accept by final state define
the same class of languages.
Note: Similar lemmas and theorems could be stated for PDAs that accept by both final state and
empty stack.
Example:
S > aAB | bB
A > aA | a
95
B > bB | c
Lemma 1: Let L be a CFL. Then there exists a PDA M such that L = LE(M).
Proof: Assume without loss of generality that is not in L. The construction can be modified to
include later.
Let G = (V, T, P, S) be a CFG, and assume without loss of generality that G is in GNF.
Construct M = (Q, , , , q, z, ) where:
Q = {q}
=T
=V
z=S
Construct M as:
Q = {q}
= T = {a}
= V = {S}
z=S
Construct M as:
Q = {q}
= T = {a, b}
= V = {S, A, B}
z=S
(1)(q, a, S) = {(q, A), (q, B)} From productions #1 and 2, S->aA, S->aB
(2)(q, a, A) = {(q, A), (q, B)} From productions #3 and 4, A->aA, A->aB
(3) (q, a, B) =
(4) (q, b, S) =
(5) (q, b, A) =
(6)(q, b, B) = {(q, B), (q, )} From productions #5 and 6, B->bB, B->b
(7) (q, , S) =
(8) (q, , A) =
(9) (q, , B) = Recall : Q x ( U {}) x > finite
subsets of Q x *
Consider generating a string using G. Since G is in GNF, each sentential form in a leftmost
derivation has form:
And each step in the derivation (i.e., each application of a production) adds a terminal and some
non-terminals.
A1 > ti+1
Each transition of the PDA simulates one derivation step. Thus, the ith step of the PDAs
computation corresponds to the ith step in a corresponding leftmost derivation.
After the ith step of the computation of the PDA, t1t2ti+1 are the symbols that have already
97
been read by the PDA and A1A2Amare the stack contents.
For each leftmost derivation of a string generated by the grammar, there is an equivalent
accepting computation of that string by the PDA.
For example, the PDA instantaneous description corresponding to the sentential form:
=> t1t2ti A1A2Am
String is read
Stack is emptied
Therefore the string is accepted by the PDA
Example #3: Consider the following CFG in GNF.
(1) S > aABC
(2) A > a G is in GNF
(3) B > b
(4) C > cAB
(5) C > cC
98
Construct M as:
Q = {q}
= T = {a, b, c}
= V = {S, A, B, C}
z=S
Notes:
Recall that the grammar G was required to be in GNF before the construction could be applied.
As a result, it was assumed at the start that was not in the context-free language L.
Suppose is in L:
1) First, let L = L {}
Counter Example:
Consider L = {, b, ab, aab, aaab, }
Then L = {b, ab, aab, aaab, }
99
The GNF CFG for L:
(1) S > aS
(2) S > b
Lemma 1: Let L be a CFL. Then there exists a PDA M such that L = LE(M).
Lemma 2: Let M be a PDA. Then there exists a CFG grammar G such that LE(M) = L(G).
Theorem: Let L be a language. Then there exists a CFG G such that L = L(G) iff there exists a
PDA M such that L = LE(M).
Suppose the input to our parser is the expression, n*(v+n*v). Since G is unambiguous
this expression has only one leftmost derivation, p = 2345712463456. We describe the
behavior of the PDA in general, and then step through its moves using this derivation to
guide the computation.
PDA Simulator:
o Step 1: Initialize the stack with the start symbol (E in this case). The start symbol
will serve as the bottom of stack marker (Z0).
o Step 2: Ignoring the input, check the top symbol of the stack.
Case(b) Top of stack is a terminal, a: Read the next input. If the input
matches a, then pop the stack and repeat step 2.
Otherwise, halt (without popping a from the stack.)
(q0, n*(v+n*v), E)
2M (q0, n*(v+n*v), T)
101
5M (q0, n*(v+n*v), n*F) readM (q0, *(v+n*v), *F)
1M (q0, v+n*v),E+T) )
102
[2] Conversely, if d(q, L, Z) , for some Z, then d(q, a, Z) , for all a ,
and d(q, L, Z)= 1.
NOTE: DPDAs can accept their input either by final state or by empty stack just as for
the non-deterministic model. We therefore define Dstk and Dste, respectively, as the
corresponding families of Deterministic Context-free Languages accepted by a DPDA by
empty stack and final state.
UNIT IV:
103
Recursively enumerable languages are also known as type 0 languages.
Context-sensitive languages are also known as type 1 languages.
Context-free languages are also known as type 2 languages.
Regular languages are also known as type 3 languages.
TMs model the computing capability of a general purpose computer, which informally can
be described as:
Effective procedure
Finitely describable
Well defined, discrete, mechanical steps
Always terminates
Computable function
A function computable by an effective procedure
TMs formalize the above notion.
104
Deterministic Turing Machine (DTM)
Two-way, infinite tape, broken into cells, each containing one symbol.
Two-way, read/write tape head.
Finite control, i.e., a program, containing the position of the read head, current symbol being
scanned, and the current state.
An input string is placed on the tape, padded to the left and right infinitely with blanks,
read/write head is positioned at the left end of input string.
In one move, depending on the current state and the current symbol being scanned, the TM 1)
changes state, 2) prints a symbol over the cell being scanned, and 3) moves its tape head one
cell left or right.
Many modifications possible.
A DTM is a seven-tuple:
M = (Q, , , , q0, B, F)
Intuitively, (q,s) specifies the next state, symbol to be written and the direction of tape
head movement by M after reading symbol s while in
state q.
105
Example #1: {0n1n | n >= 1}
0 1 X Y B
q0 (q1, X, R) - - (q3, Y, R) -
q3 - - - (q3, Y, R) (q4, B, R)
q4 - - - - -
106
Example #1: {0n1n | n >= 1}
0 1 X Y B
q0 (q1, X, R) - - (q3, Y, R) -
q1 (q1, 0, R) (q2, Y, L) - (q1, Y, R) -
q2 (q2, 0, L) - (q0, X, R) (q2, Y, L) -
q3 - - - (q3, Y, R) (q4, B, R)
q4 - - - - -
0
00
10
10110
Not
0 1 B
q0 (q0, 0, R) (q0, 1, R) (q1, B, L)
q1 (q2, 0, R) - -
q2 - - -
q0w |* 1p2
{w | w is in * and w is accepted by M}
Notes:
In contrast to FA and PDAs, if a TM simply passes through a final state then the
string is accepted.
Given the above definition, no final state of an TM need have any exiting transitions.
Henceforth, this is our assumption.
If x is not in L(M) then M may enter an infinite loop, or halt in a non-final state.
Some TMs halt on all inputs, while others may not. In either case the language
defined by TM is still well defined.
Definition: Let L be a language. Then L is recursively enumerable if there exists a TM M
such that L = L(M).
Notes:
108
The set of all recursive languages is a subset of the set of all recursively enumerable
languages
Observation: Let L be an r.e. language. Then there is an infinite list M0, M1, of TMs
such that L = L(Mi).
Question: Let L be a recursive language, and M0, M1, a list of all TMs such that L =
L(Mi), and choose any i>=0. Does Mi always halt?
Answer: Maybe, maybe not, but at least one in the list does.
Question: Let L be a recursive enumerable language, and M0, M1, a list of all TMs such
that L = L(Mi), and choose any i>=0. Does Mi always halt?
Answer: Maybe, maybe not. Depending on L, none might halt or some may halt.
Let M be a TM.
Let M be a TM.
Question: Suppose that L(M) is recursive. Does that mean that M always halts?
Answer: Not necessarily. However, some TM M must exist such that L(M) = L(M)
and M always halts.
TM Block Diagrams:
If L is a recursive language, then a TM M that accepts L and always halts can be
pictorially represented by a chip that has one input and two outputs.
Conceivably, M could be provided with an output for no, but this output cannot be
counted on. Consequently, we simply ignore it.
Theorem: The recursive languages are closed with respect to complementation, i.e., if L is
a recursive language, then so is
111
follows:
Note That:
M accepts iff M does not
M always halts since M always halts
From this it follows that the complement of L is recursive.
Theorem: The recursive languages are closed with respect to union, i.e., if L1 and L2 are
recursive languages, then so is
Proof: Let M1 and M2 be TMs such that L1 = L(M1) and L2 = L(M2) and M1 and M2 always
halts. Construct TM M as follows:
Note That:
L(M) = L(M1) U L(M2)
L(M) is a subset of L(M1) U L(M2)
L(M1) U L(M2) is a subset of L(M)
M always halts since M1 and M2 always halt
Theorem: The recursive enumerable languages are closed with respect to union, i.e., if L1
and L2 are recursively enumerable languages, then so is L3 = L1 U L2
Proof: Let M1 and M2 be TMs such that L1 = L(M1) and L2 = L(M2). Construct M as
follows:
112
Note That:
L(M) = L(M1) U L(M2)
L(M) is a subset of L(M1) U L(M2)
L(M1) U L(M2) is a subset of L(M)
M halts and accepts iff M1 or M2 halts and accepts
It follows from this that is recursively enumerable.
Definition: A decision problem is a problem having a yes/no answer (that one presumably
wants to solve with a computer). Typically, there is a list of parameters on which the
problem is based.
Given a list of numbers, is that list sorted?
Given a number x, is x even?
Given a C program, does that C program contain any syntax errors?
Given a TM (or C program), does that TM contain an infinite loop?
From a practical perspective, many decision problems do not seem all that interesting.
However, from a theoretical perspective they are for the following two reasons:
Decision problems are more convenient/easier to work with when proving
complexity results.
Non-decision counter-parts are typically at least as difficult to solve.
Notes:
The following terms and phrases are analogous:
Algorithm - A halting TM program
Decision Problem - A language
(un)Decidable - (non)Recursive
113
Statement of the Halting Problem
Analogy:
Input: DFA M with input alphabet and string w in *.
Question: Is w in L(M)?
Over-All Approach:
(P3):
Input: Turing machine M with input alphabet and one final state, and string w in *.
Notes:
Lu is P3 expressed as a language
Asking if Lu is recursive is the same as asking if P3 is decidable.
We will show that Lu is not recursive, and from this it will follow that P3 is un-
decidable.
From this we can further show that the halting problem is un-decidable.
Note that Lu is recursive if M is a DFA.
Church-Turing Thesis
There is an effective procedure for solving a problem if and only if there is a TM that
halts for all inputs and solves the problem.
There are many other computing models, but all are equivalent to or subsumed by TMs.
There is no more powerful machine (Technically cannot be proved).
DFAs and PDAs do not model all effective procedures or computable functions, but only
a subset.
o If there are, then there are things that simply can't be "computed."
o In other words, there is no problem for which we can describe an algorithm that
cant be done by a Turing machine.
If Tms are so damned powerful, cant we build one that simulates the behavior of any
Tm on any tape that it is given?
o We place an encoding of any Turing machine on the input tape of the Universal
Tm.
o The tape consists entirely of zeros and ones (and, of course, blanks)
o Any Tm is represented by zeros and ones, using unary notation for elements and
zeros as separators.
Every Tm instruction consists of four parts, each a represented as a series of 1's and
separated by 0's.
0 = 1,
1 = 11,
2 = 111,
116
3 = 1111,
We encode qn as n + 1 1's
1111011101111101110100101101101101100
Any Turing machine can be encoded as a unique long string of zeros and ones,
beginning with a 1.
A Turing machine that has the length of its tape limited to the length of the input string is
called a linear-bounded automaton (LBA).
1. There are two extra tape symbols < and >, which are not elements of G.
2. The TM begins in the configuration (q0<x>), with its tape head scanning the symbol <
in cell 0. The > symbol is in the cell immediately to the right of the input string x.
3. The TM cannot replace < or > with anything else, nor move the tape head left of < or
right of >.
117
Context-Sensitivity
No empty productions.
Context-Sensitive Language
Example:
The language L = {anbncn : n 1} is a C.S.L. the grammar is
S abc/ aAbc,
Ab bA,
AC Bbcc,
bB Bb,
aB aa/ aaA
S aAbc
abAc
abBbcc
aBbbcc aaAbbcc
aabAbcc
aabbAcc aabbBbccc
aabBbbccc
aaBbbbccc
aaabbbccc
118
CSG = LBA
Given an x CSG G, you can intuitively see that and LBA can start with S, and
nondeterministically choose all derivations from S and see if they are equal to the input
string x. Because CSLs are non-contracting, the LBA only needs to generate derivations
of length |x|. This is because if it generates a derivation longer than |x|, it will never be
able to shrink to the size of |x|.
UNIT V
The Hierarchy
Type 0 Unrestricted:
Rules are of the form: , where and are arbitrary strings over a vocabulary V and
Type 1 Context-sensitive:
A B
where
A, S N
, , B (N )
Type 2 Context-free:
Where
120
AN
(N )
Type 3 Regular:
A B
where
A, B N and
If Tms are so damned powerful, cant we build one that simulates the behavior of any
Tm on any tape that it is given?
We place an encoding of any Turing machine on the input tape of the Universal
Tm.
121
The tape consists entirely of zeros and ones (and, of course, blanks)
Any Tm is represented by zeros and ones, using unary notation for elements and
zeros as separators.
Every Tm instruction consists of four parts, each a represented as a series of 1's and
separated by 0's.
0 = 1,
1 = 11,
2 = 111,
3 = 1111,
We encode qn as n + 1 1's
1111011101111101110100101101101101100
Any Turing machine can be encoded as a unique long string of zeros and ones, beginning
with a 1.
Turing Reducibility
An oracle Turing machine with an oracle for EQTM can decide ETM
122
TEQ-TM = On input <M>
M1 has a transition from start state to reject state for every element of
Applications
If A T B and B is decidable, then A is decidable
If A T B and A is undecidable, then B is undecidable
If A T B and B is Turing-recognizable, then A is Turing-recognizable
If A T B and A is non-Turing-recognizable, then B is non-Turing-recognizable
The class P
The class NP
123
There exists a polynomial p such that for each potential witnesses of each instance of
size n of D, the execution of the algorithm A takes at most p(n) steps.
Think of a non-deterministic computer as a computer that magically guesses a
solution, then has to verify that it is correct
o One way to imagine it: a parallel computer that can freely spawn an infinite
number of processes
NP-Complete Problems
We will see that NP-Complete problems are the hardest problems in NP:
o If any one NP-Complete problem can be solved in polynomial time.
o Then every NP-Complete problem can be solved in polynomial time.
o And in fact every problem in NP can be solved in polynomial time (which would
show P = NP)
o Thus: solve hamiltonian-cycle in O(n100) time, youve proved that P = NP. Retire
rich & famous.
The crux of NP-Completeness is reducibility
An example:
124
o Transformation: (x1, x2, , xn) = (y1, y2, , yn) where yi = 1 if xi = TRUE, yi = 0
if xi = FALSE
Another example:
Given one NP-Complete problem, we can prove many interesting problems NP-Complete
o Hamiltonian cycle
o Hamiltonian path
o Knapsack problem
o Traveling salesman
NP Hard
Definition: Optimization problems whose decision versions are NP- complete are
called NP-hard.
125
15. Additional Topics
Two Way Finite Automata
Proof of Closure properties of Regular Languages
Two Stack Pushdown Automata
CYK Algorithm for CFL
Cookss Theorem
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
17. Question Bank:Descriptive Type Questions - Unit Wise
UNIT I
1. Explain the Finite automation how the language constructs can be recognized?
2. List out the Finite automatas?
3. Define: string, sub string, transitive closure and reflexive transitive closure?
4. Describe the finite state machine with a block diagram.
5. Construct DFA to accept the language of all strings of even numbers of as &
numbers of bs divisible by three over (a+b)*.
0 1
A B, 0 C, 1
B C, 1 B, 1
C A, 1 C, 0
10. Give Mealy and Moore machines for the following processes:
a) For input from (0 + 1)*, if the input ends in 101, output A; if the input ends
in 110, output B; otherwise output C.
b) For input from (0 + 1 + 2)*, print the residue modulo 5 of the input treated
as a ternary (base 3, with digits 0, 1, and 2) number.
152
UNIT II
UNIT III
1. What is an ambiguity?
2. What does an ambiguity trouble in the CFG?
3. What are the techniques used to minimize the CFG?
4. Explain the CNF and GNF with an example.
7. Write the push down automata to accept the language {ww* | w e {0, 1}}
8. Explain the equivalence of CFL and PDA.
9. Construct PDA equivalent to the following grammar: S aAA, A aS/bS/a.
Show that the set of all strings over {a, b} consisting of equal numbers of as and
bs accepted by a PDA.
UNIT IV
153
UNIT V
UNIT-I
1. a) Given L1={a,ab,a2} and L2={b2,aa} are the languages over A={a,b}.
b) Given A={a, b, c} find L* where i)L={b2} ii) L={a, b} and iii) L={a,b,c3}.
2. Determine which of the following strings are accepted by the given Finite Automata
b) Design a DFA which accepts set of all strings containing odd number of 0s and odd
number of 1s.
154
b) Convert the following NFA with - transitions to without - transitions.
5. a) Construct the minimum state automata for the following : Initial State :A Final State: D
Q/ a b
A B A
B A C
C D B
D D A
E D F
F G E
G F G
H G D
b) Design FA to accept strings with a and b such that the number of bs are divisible by 3
iii) L= {w| w is any string that does not contain exactly two as}.
7. Design a Moore and Mealy machine to determine the residue mod 5 for each ternary
155
9. Construct the Mealy machine for the following Moore machine
i) L={ abaan | n 1}
iii) To accept strings with as and bs such that the string end with bb.
UNIT-II
1. a)Define Regular Expression.
b) List the Identity Rules of Regular sets.
c) Prove the following
i) +1*(011)*(1* (011)*)* = (1+011)*
ii) (1=00*1)+(1+00*1)(0+10*1)*(0+10*1) = 0*1(0+10*1)*
iii) (rs+r)*r=r(sr+r)*
156
4. a) State and prove pumping lemma for regular languages. Apply pumping lemma for
following
language and prove that it is not regular L={ambn | gcd(m,n) = 1}.
b) Show that L= {an! |n>=1} is not regular.
5. a) Obtain a regular expression to accept strings of as and bs such that every block of four
consecutive symbols contains at least two as.
b) Give regular expression for representing the set L of strings in which every 0 is immediately
at least two 1s.
c) Find the regular expression for the language L={a2nb2m|n0, m0}.
d) Find the regular expression for L= {w | every odd position of w is a 1}
6. a) Define Regular Grammar. Explain in detail obtaining a right linear and left linear grammar
for the
following FA.
b) Find the right linear grammar and left linear grammar for the regular expression
(0+1)*010(1(0+1))*
7. a) Explain the process of obtaining a DFA from the given Regular Grammar.
b) Construct a DFA to accept the language generated by CFG:
157
SaB|bA, Aa|aS|bAA, Bb|bS|aBB.
iii) Describe the language generated by the grammar SaAB, AbBb, BA| .
ii) Construct the leftmost, rightmost derivation and parse tree for the following grammar
which
i) L= {anbn|n1}
ii) L= {aibjck|i=j}
iii) Language of strings with unequal number of as and bs.
iv) L= {aibjck| i+j=k,i0, j0}
v) L= {wwR| w is in (a,b)* and wR is the reversal of w}
UNIT-III
1. a) Discuss Ambiguity, left recursion and factoring in context free grammar.
b) i) Eliminate Null productions in the grammar SABaC, ABC, Bb|, CD|, Dd.
158
ii) Eliminate Unit productions in the grammar SAB, Aa, BC, Bb,CD,DE,Ea.
iii) Find a reduced grammar equivalent to the grammar G whose productions are
SAB|CA, BBC|AB, Aa, CaB|b.
c) Simplify the following grammar: SAaB|aaB, AD, BbbA|, DE, EF, FaS.
5. a) Explain and prove the pumping lemma for context free languages.
c) Consider the following grammar and find whether it is empty, finite or infinite
i) SAB, ABC|a, BCc|B, Ca.
ii) SAB, ABC|a, BCC|b, Ca, CAB.
6. a) Define Push Down Automata. Explain its model with a neat diagram.
b) Explain ID of PDA
given by
159
b) Explain acceptance of PDA by empty state and final state.
c) Prove the equivalence of acceptance of PDA by empty state and final state.
UNIT-IV
1. a) Define Turing Machine. Explain its model with a neat diagram.
b) Explain ID of a Turing Machine.
c) Design a Turing machine which accepts the following languages
i) L= {anbncn | n0}.
ii) L= {a2nbn | n1}.
iii) accepting palindrome strings over {a ,b}.
2. a) Explain how a Turing Machine can be used to compute functions from integers to integers.
b) Design a Turing Machine to perform proper subtraction m n, which is defined as m-n for
a) x2 b) n! c) log2 n
160
UNIT-V
1. Explain the Chomsky Hierarchy with a neat diagram.
UNIT - I
1. The prefix of abc is _ _ _ _ _ _ _ _ _ _ _ _ (d)
a. c
b. b
c. bc
d. a
10. Let a is any symbol, x is a palindrome then which of the following is not a
Palindrome. (d)
a. e
b. a
c. axa
d. xa
162
11. Let a is any symbol , x is a palindrome then which of the following is a palindrome. (a)
a. e
b. xa
c. ax
d. aax
13. The number of states of the FSM required to simulate the behavior of a computer witha
memory capable of storing m words each of length n bits is _ _ _ _ _ (b)
a. m
b.
c. 2mn
d. 2m
16. An FSM can be used to add two given integers .This is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (b)
a. true
b. false
c. may be true
d. can't say
24. An FSM can be used to add two given integers .This is _ _ _ _ _ _ _ _ (b)
a. true
b. false
c. may be true
d. can't say
164
25. An FSM can be used to perform subtracttion of given two integers .This is _ _ (b)
a. true
b. false
c. may be true
d. can't say
38. In transition diagrams a state pointed by an arrow represents the _ _ _ _ _ _ _ state. (c)
a. final
b. interior
c. start
d. final or start
45. Let NFA has a finite number n of states ,the DFA will have at most _ _ _ _ _ _ _ _ states.
(d)
a. 2n
b. n/2
c. n 2
d. 2 n
46. Let NFA has a finite number 6 of states ,the DFA will have at most _ _ _ _ _ _ _ _ states.
(d)
a. 12
b. 2
167
c. 36
d. 64
168
54. The major difference between a mealy and a moore machine is that (b)
a. The output of the former depends on the present state and present input
b. The output of the former depends only on the present stste
c. The output of the former depends only on the present input
d. The output of the former doesn't depends on the present state
57. In case of regular sets the question ' is the intersection of two languages a language of the
same type ?' is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (c)
a. Decidable
b. Un decidable
c. trivially decidable
d. Can't say
58. In case of regular sets the question 'is the complement of a language also a language of the
same type ? ' is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (c)
a. Decidable
b. Un decidable
c. trivially
dd.e Cciadna'tb slaey
60. In case of regular sets the question ' is L=R where R is a given regular set ?' is _ _ _ _ _ (a)
a. Decidable
b. Undecidable
c. trivially decidable
d. Can't say
169
61. In case of regular sets the question ' is L regular?' is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (c)
a. Decidable
b. Undecidable
c. trivially decidable
d. Can't say
62. In case of regular sets the question 'Is w in L? 'Is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
(a)
a. Decidable
b. Undecidable
c. trivially decidable
d. Can't say
66. In case of regular sets the question 'is L1subset or equal to L2? Is _ _ _ _ _ _ (a)
a. Decidable
b. Undecidable
c. trivially decidable
d. Can't say
67. The regular expression (1 + 10) * denotes all strings of 0's and 1's beginning with _ _ _ _ _ _
_ _ _ _ _ _ _ and not having two consecutive _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (a)
a. 1, 0's
b. 0, 1's
c. 0, 0's
d. 1, 1's
68. Let r and s are regular expressions denoting the languages R and S.
Then (r + s) denotes _ _ _ _ _ _ _ _ _ _ _ (c)
a. RS
b. R*
c. RUS
d. R+
170
69. Let r and s are regular expressions denoting the languages R and S.
Then (r s) denotes _ _ _ _ _ _ _ _ _ _ _ _ (a)
a. RS
b. R*
c. RUS
d. R+
70. Let r and s are regular expressions denoting the languages R and S.
Then ( r*) denotes _ _ _ _ _ _ _ _ _ _ (b)
a. RS
b. R*
c. RUS
d. R+
72. (0+1) * 011 denote all strings of 0's and 1's ending in _ _ _ _ _ _ _ _ _ _ _ (c)
a. 0
b. 0111
c. 011
d. 111
82. In NFA for r=e the minimum number of states are _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (b)
a. 0
b. 1
c. 2
d. 3
83. In NFA for r=F the minimum number of states are _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (c)
a. 0
172
b. 1
c. 2
d. 3
84. In NFA for r=a the minimum number of states are _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (c)
a. 0
b. 1
c. 2
d. 3
85. ( e + 00 )* = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (d)
a. e
b. 0
c. e 0
d. (00 )*
87. 1 + 01 = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (b)
a. e + 0
b. (e + 0) 1
c. 1 (e +0)
d. 101
89. Let f(0)=a and f(1) = b* If L is the language 0*(0+1)1* then f(L)= _ _ _ _ (d)
a. ab
b. a b*
c. b*
d. a* b*
95. 'The regular sets are closed under kleene closure' is _ _ _ _ _ _ _ _ _ _ (a)
a. True
b. False
c. True or False
d. can't say
97. The class of regular sets is closed under complementation .That is if L is a regular set and L
is
subset or equal to * then _ _ _ _ _ _ _ _ _ _ _ _ _ is regular set (d)
a.
b. *
c. * + L
d. * - L
UNIT III
98. Regular grammars also known as _ _ _ _ _ _ _ _ _ _ _ _ grammar. (d)
174
a. Type 0
b. Type 1
c. Type 2
d. Type3
102. P,Q, R are three languages .If P and R are regular and if PQ=R then (c)
a. Q has to be regular
b. Q cannot be regular
c. Q need not be regular
d. Q has to be a CFL
103. Let A = {0,1 } L= A * Let R = { 0 n1n , n >0 } then LUR is regular and R is _ _ (b)
a. regular
b. not regular
c. regular or not regular
d. can`t say
175
105. Let L denote the language generated by the grammar S0s0100 then (c)
a. L= 0 +
b. L is CFL but not regular
c. L is regular but not 0 +
d. L is not context free
109. Pick the correct statement the logic of pumping lemma is a good example of (a)
a. the pigeon hole principle
b. divide and conquer
c. recursion
d. iteration
113. In CFG each production is of the form Where A is a variable and is string of
Symbols from _ _ _ _ _ _ _ _ _ _ ( V, T are variables and terminals ) (d)
a. V
b. T
c. VUT
d. *(VUT)
114. Any string of terminals that can be generated by the following CFG (d)
a. has atleast one b
b. should end in a 'a'
c. has no consecutive a's or b's
d. has atleast two a's
117. Let G=(V,T,P,S) be a CFG. A tree is a derivation (or parse) tree for G if If vertex n has
label ? then n is a _ _ _ _ node (d)
a. root
b. interior
c. root or interior
d. leaf
118. The vernacular language English ,if considered a formal language is a (b)
a. regular language
177
b. context free language
c. context sensitive language
d. can`t say
119. The language constructs which are most useful in describing nested structures such as
balanced parentheses matching begin ends etc are _ _ _ _ _ _ _ _ (b)
a. RE
b. CFG
c. NM CFG
d. CSG
178
126. The class of languages generated by ---- grammar is exactly the linear bounded languages.
(b)
a. RG
b. CFG
c. CSG
d. PSG
127. Which of the following is the most general phase-structured grammar? (b)
a. regular
b. context-sensitive
c. context free
d. none of the above
130. The language L= (0^n 1^n 2^R 3^R where n, R>0) is a (a)
c. context free language
d. context sensitive language
c. regular language
d. recursively enumerable language
130.A Pushdown automata is.....if there is at most one transition applicable to each configuration
?
a. Deterministic (a)
b. Non Deterministic
c. Finite
d. Non Finite
a. Finite automata
c. Deterministic automata
179
d. None of these
133. Which of the following is not accepted by DPDA but accepted by NDPDA ()
a. Strings end with a particular alphabet
b. All strings which a given symbol present at least twice
c. Even palindromes
d. None
UNIT - IV
136. Any turing machine is more powerful than FSM because (c)
a.Tape movement is confined to one direction
b.It has no finite state control
c.It has the capability to remember arbitrary long input symbols
d. TM is not powerful than FSM
180
137.In which of the following the head movement is in both directions (d)
a. TM
b.FSM
c.LBA
d.a& c
139. Any Turning machine with m symbols and n states can be simulated by another TM with
just
2 s symbols and less than (d)
a. 8mn states
b.4mn+8states
c. 8mn+ 4 states
d. mn states
UNIT - V
a. Type 0 Grammar
b. Type 1 Grammar
c. Type 2 Grammar
d. Type 3 Grammar
UNIT-I
1. Define epsilon closure. Find NFA without for the following NFA with where
a b
qo qo q1
q1 {q3,q1} q2
q2 q2 {q1,q3}
q3
0 1
A A,B A C
B C
C C C A
3. Minimize the FA given below and show both given and reduced FAS are equivalent or not where
0 1
qo q1 q2
q1 q3 q4
q2 q5 q6
q3 q3 q4
q4 q5 q6
q5 q3 q4
q6 q5 q6
q0 q1 N q2 N
q1 q1 Y q2 N
q2 q1 N q2 Y
5. a) Explain significance of NFA with transitions and write differences between NFA with and
ordinary NFA. Define NFA- transitions
1. Define grammar, regular grammar, right linear grammar, left linear grammar with examples.
2. a) what are the rules to construct regular grammar for a given finite automata
0 1
qo q1
q1 q2 q1
q2 q2 q3
q3 q2 q1
3. a) What are the rules to construct finite automata for a given regular grammar
SaS|bA|b
AaA|bS|a
b) Obtain CFG to obtain balanced set of parentheses (that is every left parentheses should
match with the corresponding right parentheses
b) Find LMD, RMD, and DT for the string: 00110101 where the grammar is
S0B|1A
A0|0S|1AA
B1|1S|0BB
UNIT-III
184
2. Given the grammar G as S0B|1A, A0|0S|1AA, B1|1S|0BB. Find leftmost and
3. Construct the leftmost, rightmost derivation and parse tree for the following grammar
5. Simplify the following grammar: SAaB|aaB, AD, BbbA|, DE, EF, FaS.
10. Construct PDA for the grammar SaA, AaABC|bB|a, Bb, Cc.
UNIT-IV
3. Design a Turing Machine to perform proper subtraction m n, which is defined as m-n for
5. Design a Turing Machine that gives twos complement for the given binary representation
185
UNIT-V
1. Show that the PCP with two lists x=(b,bab3,ba) and y=(b3,ba,a) has a solution. Give the
solution sequence.
List A List B
i wi xi
1 a aaa
2 abaaa ab
3 ab b
3. Explain why the PCP with two lists x= (ab,b,b) and y=(ab2,ba,b2) has no solution?
a b B
q0 (q1,b,R) (q1,a,L) (q1,b,L)
q1 (qA,a,L) (q0,a,R) (q1,a,R)
qA
22.Discussion topics
1) Importance of formal languages and it use.
2) Applications of automata theory.
3) Types of finite automata and its application.
4) Importance of FSM with outputs & what are they?
5) Importance of grammar & its formalism.
186
6) Grammar Normalisation techniques
7) Significance of push down automata
8) Types of PDA & its conversions
9) Significance of Turing machine
10) Types of languages & its importance.
References:
Journals:
1) On external contextual grammars with subregular selection
languages.
2) Nonterminal complexity of tree controlled grammars
3) Weighted grammars and automata with threshold interpretation.
Aspects of Language and Automata Theory Special Issue Dedicated
to Jrgen Dassow.
Websites:
http://www.cse.chalmers.se/edu/course/TMV027/
http://www.eecs.wsu.edu/~ananth/CptS317/
http://www.nptel.iitm.ac.in/downloads/106106049/
187
E-links
http://books.google.co.in/books?id=tzttuN4gsVgC&source=gbs_similarbooks
http://en.wikipedia.org/wiki/Formal_language
http://en.wikipedia.org/wiki/Automata_theory
http://cs.fit.edu/~dmitra/FormaLang/
http://www.computersciencemcq.com/mcq.aspx?name=Theory_of_Computati
on_MCQ_14
188
ACADEMIC YEAR : SEM : II Date :28-April-2015
2014-15
5 4 3 2 1
5 4 3 2 1 %
GENERAL OBJECTIVES:
189
10) To what extent you feel the course 24 10 8 0 0 4.38(87%)
outcomes have been achieved.
b) What are your suggestions, if any, for changes that would improve this course?
c) Given all that you learned as a result of this course, what do you consider to be most
important?
190
5 4 3 2 1
5 4 3 2 1 %
GENERAL OBJECTIVES:
b) What are your suggestions, if any, for changes that would improve this course?
191
c) Given all that you learned as a result of this course, what do you consider to be most important?
d) Do you have any additional comments or clarifications to make regarding your responses to
any particular survey item?
e) Do you have any additional comments or suggestions that go beyond issues addressed on this
survey?
b.Teaching Evaluation
Course Assessment
Faculty: M.SRINIVAS
192
Geethanjali College of Engineering and Technology
CHEERYAL (V), KEESARA (M), R.R.DIST-501301, ANDHRAPRADESH
Faculty: M.SRINIVAS
193
S.No Roll No StudentName
9 13R11A0508 B SOUJANYA
19 13R11A0519 G YAMINI
194
23 13R11A0523 GUNDABATTULA SHRAVANI
39 13R11A0540 RAHUL T
43 13R11A0544 S JAYANTH
195
46 13R11A0547 TADIPARTHI CHRISTINA
52 13R11A0553 P S MANASA
II Yr CSE B
196
10 13R11A0565 B TEJASREE
24 13R11A0579 J SUSMITHA
32 13R11A0588 M S BHUVAN
197
33 13R11A0589 MANGA VIVEK KUMAR
42 13R11A0598 RAMESH B K
43 13R11A0599 S SAIKIRAN
51 13R11A05A8 V LAKSHMI
198
56 13R11A05B3 YALLAMBHOTLA ACHYUTH
3 13R11A05B7 ANJANI A
10 13R11A05C4 G APOORVA
11 13R11A05C5 G NIKITHA
13 13R11A05C7 G SRIHITHA
199
20 13R11A05D5 KASULA SWAPNA PRIYA
40 13R11A05F6 R BHAVANI
200
47 13R11A05G4 TEJASWEE VEERAVALLI
5 13R11A05H6 ABHINAY T
201
13 13R11A05J4 AASHISH REDDY D
18 13R11A05J9 G PRATHAM
20 13R11A05K1 SRIKANTH R B
23 13R11A05K4 28
39 13R11A05M0
REDNAM KOTA
202
SATYANARAYANA
46 13R11A05M7 T JAGAN
47 13R11A05M8 T MOUNIKA
51 13R11A05N2 V P S PRASHANTH
52 13R11A05N3 V TRISHA
G2
9 13R11A0508 B SOUJANYA
G3
G4
19 13R11A0519 G YAMINI
204
G5
21
G6
G7
G8
39 13R11A0540 RAHUL T
G9
43 13R11A0544 S JAYANTH
205
45 13R11A0546 SANJEEVU TEJASWANI
G10
G11
52 13R11A0553 P S MANASA
G1
G2
206
8 13R11A0563 BANDARU PRADEEP
10 13R11A0565 B TEJASREE
G3
G4
G5
24 13R11A0579 J SUSMITHA
G6
G7
207
32 13R11A0588 M S BHUVAN
G8
G9
42 13R11A0598 RAMESH B K
43 13R11A0599 S SAIKIRAN
G10
G11
51 13R11A05A8 V LAKSHMI
208
54 13R11A05B1 VIDYA BHARATHI CHEGU
StudentName
SlNo AdmnNo
G1
3 13R11A05B7 ANJANI A
G2
10 13R11A05C4 G APOORVA
G3
11 13R11A05C5 G NIKITHA
13 13R11A05C7 G SRIHITHA
209
15 13R11A05C9 GADAGONI SAI CHARAN
G4
G5
G6
G7
G8
210
37 13R11A05F3 PARUCHURI DIVYA
40 13R11A05F6 R BHAVANI
G9
G10
G11
211
1
5 13R11A05H6 ABHINAY T
G2
G3
212
G4
16
18 13R11A05J9 G PRATHAM
20 13R11A05K1 SRIKANTH R B
G5
23 13R11A05K4 28
G6
213
29 13R11A05L0 KOVELAMUDI RAMYASRI
G7
G8
REDNAM KOTA
39
13R11A05M0 SATYANARAYANA
G9
13R11A05M7 T JAGAN
214
G10
46
47 13R11A05M8 T MOUNIKA
G11
51 13R11A05N2 V P S PRASHANTH
52 13R11A05N3 V TRISHA
215