gate theory of computation book
Post on 02-Jun-2018
255 Views
Preview:
TRANSCRIPT
-
8/10/2019 GATE Theory of Computation Book
1/12
-
8/10/2019 GATE Theory of Computation Book
2/12
THEORY OF COMPUTATION
For
Computer Science
Information Technology
By
www.thegateacademy.com
http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/ -
8/10/2019 GATE Theory of Computation Book
3/12
Syllabus Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30thCross, 10thMain, Jayanagar 4thBlock, Bangalore-11 080 65700750 i f @th t d C i ht d W b th t d
Syllabus for Theory Of Computation
Regular languages and finite automata, Context free languages and Push-down automata, Recursively
enumerable sets and Turing machines, Undecidability; NP completeness.
Analysis of GATE Papers
(Theory Of Computation)
Year
Percentage of marks
Overall Percentage
2013
8.00
8.09
2012
5.00
2011
9.00
2010
7.00
2009 6.66
2008
10.00
2007
8.00
2006
9.33
2005
9.33
2004
6.00
2003
10.67
-
8/10/2019 GATE Theory of Computation Book
4/12
Contents Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30thCross, 10thMain, Jayanagar 4thBlock, Bangalore-11 080 65700750 i f @th t d C i ht d W b th t d P I
C O N T E N T S
Chapter Page No
#1. Introduction/ Preliminaries 1 3 Preliminaries 1 2
Properties of Relations 2 3
#2.Finite Automata 4 30
Finite Automata Introduction 4 5
Deterministic Finite Automata 5 6
Transition Diagram 6 8
Non-Deterministic Finite Automata 8 10 Construction of DFA From NFA 10 11
NFA with -Transitions 11 14
Eliminating -Transitions 14 16
Assignment 1 17 21
Assignment 2 21 24
Answer keys 25
Explanations 25 30
#3.Regular Expression 31 74
Definitions 31 32 Languages Associated with Regular Expressions 32 33
Algebraic Laws for Regular Expressions 33 34
Converting Regular Expression to Automata (-NFA) 34 36
Construction of Regular Expression From Finite
Automata
37 40
Ordering the Elimination of States 40 42
Finite Automata with Output 42 45
Regular Grammars 45 50
Properties of Regular Languages 50 55
Myhill-Nerode Theorem 55 57 Pumping Lemma for Regular Languages 57 - 62
Finding (in) Distiguishable States 63 65
Assignment 1 66 67
Assignment 2 68 69
Answer keys 70
Explanations 70 74
#4.Context Free Grammar
75 123
Introduction 75 76
Context Free Language 76 78 Leftmost and Rightmost Derivations Ambiguity 78 80
-
8/10/2019 GATE Theory of Computation Book
5/12
Contents Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30thCross, 10thMain, Jayanagar 4thBlock, Bangalore-11 080 65700750 i f @th t d C i ht d W b th t d P II
Simplification of Context Free Grammars 80
Elimination of Useless Symbols 80 84
Normal Forms 85 91 Pushdown Automata 91 92
Definition of PDAs 92 98
Consruction of CFG from a PDA With Empty Stack 98 100
Properties of Context Free Languages 100 104
Decision Algorithms for CFLs 104 105
Non-Context Free Languages 106 108
The Pumping Lemma for CFLs 108 110
Membership Algorithm for Context -Free Grammars 111 112
Assignment 1 113 115
Assignment 2 115 119 Answer keys 120
Explanations 120 - 123
#5. Turing Machines 124 161 Introduction 124 126
Modification of Turing Machines 126 128
Post Machine 128 130
Two-Pushdown Stack Machine 130 131
Counter Machines 131
Storage in the State 132 Multiple Tracks 133 139
Universal Turing Machine 139 140
Context Sensitive Grammar 140 141
Linear Bounded Automata 141 142
Hierarchy of Formal Languages 142 143
Undesidability 143 144
The Universal Language 144 151
The Classes P & NP 151 153
Some of the NP-Hard Problems 153 154
Assignment 1 155 156 Assignment 2 157 158
Answer Keys 159
Explanations 159 161
Module Test 162 177
Test Questions 162 170
Answer Keys 171
Explanations 171 177
Reference Books 178
-
8/10/2019 GATE Theory of Computation Book
6/12
Chapter-1 Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 1
CHAPTER 1
Introduction/ Preliminaries
(String, Alphabet, Set, Relation, Equivalence of Relation etc.)
Preliminaries:
1. String:A string is a finite sequence of symbols put together.
Ex: bbvl
The length of this string is '4'.Note: The length of empty string denoted by , is the string consisting of zero symbols. Thus
I I = 0.
2. Alphabet:An alphabet is a finite set of symbols
Ex: {a, b, 0, 1, B}
3. Formal language:A formal language is a set of strings of symbols from some alphabet.
Ex: The language consisting of all strings formed by the alphabet {0, 1}Note:
1.
The empty set, , is a formal language. The cardinality (size) of this language is zero.2.
The set consisting of empty string, {e} is a formal language. The cardinality (size) of this
language is one.
4. Set:A set is a collection of objects (members of the set) without repetition.i.
Finite Set: A set which contains finite number of elements is said to be finite set.
Ex:- {1,2,3,4}
ii.
Countably Infinite Set:Sets that can be placed in one-to-one correspondence with the
integers are said to be countably infinite or countable or denumerable.
Ex:-The set * of the finite-length strings from an alphabet are countably infinite, (if : {0, 1} then *: {0,01,1,10,011.....} i.e all possible strings with l0' and'1')
iii. Uncountable set:
Sets that can't be placed in one-to-one correspondence with the
integers are said to be uncountable sets.
Ex:-The set of real numbers.
-
8/10/2019 GATE Theory of Computation Book
7/12
Chapter-1 Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 2
5. Relations: A(binary) relation is a set of ordered tuple. The first component of each tuple is
chosen from a set called the domain and the second component of each pair is chosen from a
(possibly different) set called the range.
Ex:
Let A {1, 2, 3, 4} be a set. A relation R, on 'A' can be defined as R: {(1,2), (1,3), (1,1), (2,3)}
Properties of Relations:We say a relation R on set S is
1.
Reflexiveif aRa for all a in S.2.
Irreflexive
if aRa is false for all a is S.
3. Transitiveif aRb and bRc implies aRc.4.
Symmetricif aRb implies bRa.
5. Asymmetric
if aRb implies that bRa is false.
6. Anti-symmetricif aRb and bRa implies a = b.
quivalence Relation: A relation is said to be equivalence relation if it satisfies the following
properties.
1.
Reflexive
2. Symmetric3. Transitive
Animportant property of equivalence relation 'R' on set 'S' is that R partitions 'S' into disjointnonempty equivalence classes (may be infinite)
i.e., S = S1 S2....., where for each i and j, with i j
1. Si Sj= 2. For each 'a' and 'b' in S jaRb is true.
3.
For each 'a' in Sj and 'b' in Sj, aRb is false.
The Si's are called equivalence classes.
Ex: The relation 'R' on people defined by pRq if and only if p and q were born at the same hour
of the same day of some year.
The number of equivalence classes are: 24 (no. of hours) 7 (no. of days in a week).
Closure of relations: Suppose P is a set of properties of relations. The P-closure of a relation Ris the smallest relation R that includes all the pairs of R and possesses the properties in P.
Ex:- Let R = {(1,2), (2,3), (3,1)} be a relation on set {l,2,3}
i. The reflexive-transitive closure of R is denoted by R* is
Added by reflexivity
(1,2), (2,3), (3,1), (1,1), (2,2), (3,3), (1,3), (2,1), (3,2)}
By transitivity
ii.
The symmetric closure of R is
{(1,2), (2,3), (3,1), (2,1),(3,2), (1,3)}
-
8/10/2019 GATE Theory of Computation Book
8/12
Chapter-1 Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 3
TERM DEFINITION
prefix of s A string obtained by removing zero or more trailingsymbols of string s; e.g., ban is a prefix of banana.
suffix of s A string formed by deleting zero or more of the leading
symbols of s; e.g., nana is a suffix of banana.
substring of s A string obtained by deleting a prefix and a suffix from s;
e.g., nan is a substring of banana. Every prefix and every
suffix of s is a substring of s, but not every substring of sis a prefix or a suffix of s. For every string s, both s and s
are prefixes, suffixes, and substrings of s.
proper prefix, suffix, or substring
of s
Any nonempty string x that is, respectively, a prefix,
suffix, or substring of s such that s x.
subsequence of s Any string formed by deleting zero or more notnecessarily contiguous symbols from s; e.g., baaa is a
subsequence of banana.
-
8/10/2019 GATE Theory of Computation Book
9/12
Chapter-2 Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 4
CHAPTER 2
Finite Automata
Finite Automata Introduction
A finite automaton involves states and transitions among states in response to inputs. They are
useful for building several different kinds of software, including the lexical analysis componentof a complier and systems for verifying the correctness of circuits or protocols. They also serve
as the control unit in many physical systems including: vending machines, elevators, automatictraffic signals, and computer microprocessors. Also network protocol stacks.
Deterministic Finite Automata
A DFA captures the basic elements of an abstract machine: it reads in a string, and depending on
the input and the way the machine was designed, it outputs either true or false. A DFA is alwaysis in one of N states, which we usually name 0 through N-1. Each state is labeled true or false.
The DFA begins in a designated state called the start state .As the input characters are read inone at a time, the DFA changes from one state to another in a pre-specified way. The new state is
completely determined by the current state and the character just read in. When the input isexhausted, the DFA outputs true or false according to the label of the state it is currently in.
A Deterministic finite automaton is represented by a Quintuple
(5-tuple: Q,,,q0,F)whereQ : Finite set of states
: Finite set of input symbols called the alphabet. : Q X Q is a transition function from Q X to Qq0: A start state, one of the states in QF : A set of final states, such that F Q.
Induction
Suppose is a string of the form that ism a is the last symbol of , and is the stringconsisting of all but the last symbol. For example is broken into and .Then
, (
, , )
Now (2.1) may seem like a lot to take in, but the idea is simple. To compute , first compute, the state that the automaton is in after processing all but the last symbol of . Supposethis state is p; that is. , . Then , is what we get by making a transition from state pon input a, the last symbol of w. That is, , = ,
Example 1
Let us design a DFA to accept the language
L = {| has both an even number of 0's and an even number of 1's}
-
8/10/2019 GATE Theory of Computation Book
10/12
Chapter-2 Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 5
It should not be surprising that the job of the states of this DFA is to count both the number of
0's and the number of l's, but count them modulo 2. That is, the state is used to remember
whether the number of 0's seen so far is even or odd, and also to remember whether the numberof l's seen so far is even or odd. There are thus four states, which can be given the followinginterpretations:
: Both the number of 0's seen so far and the number of l's seen so far are even.
: The number of 0's seen so far is even, but the number of l's seen so far is odd.
: The number of l's seen so far is even, but the number of 0's seen so far is odd.
: Both the number of 0's seen so far and the number of l's seen so far are odd.
State is both the start state and the alone the accepting state. It is the start state, becausebefore reading any inputs, the numbers of 0's and l's seen so far are both zero, and zero is even.It is the only accepting state, because it describes exactly the condition for a sequence of 0's and
l's to be in language L.
We now know almost how to specify the DFA for language L. It is
*, , , +, *,+, , , *+
Deterministic Finite Automata
Figure 2 1: Transition diagram for the DFA of Example 1
where the transition function S is described by the transition diagram of Fig. 2.1. Notice howeach input 0 causes the state to cross the horizontal, dashed line. Thus, after seeing an even
number of 0's we are always above the line, in state go or qi while after seeing an odd number of
0's we are always below the line, in state q-z or q%. Likewise, every 1 causes the state to crossthe vertical, dashed line. Thus, after seeing an even number of l's. we are always to the left, in
state q0or q2. while after seeing an odd number of l's we are to the right, in state q\ or g3. These
observations are an informal proof that the four states have the interpretations attributed to
them. However, one could prove the correctness of our claims about the states formally, by amutual induction with respect to example.
We can also represent this DFA by a transition table. Figure 2.2 shows this table. However, weare not just concerned with the design of this DFA; we want to use it to illustrate the
construction of 5 from its transition function 8. Suppose the input is 110101. Since this string
-
8/10/2019 GATE Theory of Computation Book
11/12
Chapter-2 Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 6
has even numbers of 0's and l's both, we expect it is in the language. Thus, we expect that S( ,110101) = since is the only accepting state. Let us now verify that claim.
Figure 2 2: Transition table for the DFA of Example 1
The check involves computing 8(q0,w) for each prefix w of 110101, starting at e and going inincreasing size. The summary of this calculation is:
, ., ( , , ) (,) , ( , , ) (,) , ( , , ) (,) , ( ,, ) (,) , ( ,, ) (,) , ( ,, ) (,)
Acceptance by an Automata :
A string x is said to be accepted by a finite automaton M Q, , , q0, F if q0, x) = P forsome p in F. The language accepted by M, designated L M, is the set *x | q0,x) is in F}.
A language is a regular set (or just regular) if it is the set accepted by some automaton.
There are two preferred notations for describing Automata
1 Transition diagram
2 Transition table
Example
1. Give DFA for accepting the set of all strings containing as substring.
Transition diagram
Transition Table:
0 1
q0 q0 q1
q1 q0 q2
q2 q0 q3
*q3 q3 q3
1 1q1 q2 q3q0
1
0/10
Start
0
0
-
8/10/2019 GATE Theory of Computation Book
12/12
top related