SlideShare uma empresa Scribd logo
1 de 12
Baixar para ler offline
THEORY OF COMPUTATION
For
Computer Science
&
Information Technology
By
www.thegateacademy.com
Syllabus Theory of Computation
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com
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
Contents 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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
Contents 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page II
 Simplification of Context Free Grammars 80
 Elimination of Useless Symbols 80 – 84
 Normal Forms 85 – 91
 Pushdown Automata 91 – 92
 Definition of PDA’s 92 – 98
 Consruction of CFG from a PDA With Empty Stack 98 – 100
 Properties of Context Free Languages 100 – 104
 Decision Algorithms for CFL’s 104 – 105
 Non-Context Free Languages 106 – 108
 The Pumping Lemma for CFL’s 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
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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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.
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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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. Reflexive if aRa for all a in S.
2. Irreflexive if aRa is false for all a is S.
3. Transitive if aRb and bRc implies aRc.
4. Symmetric if aRb implies bRa.
5. Asymmetric if aRb implies that bRa is false.
6. Anti-symmetric if aRb and bRa implies a = b.
→ Equivalence Relation: A relation is said to be equivalence relation if it satisfies the following
properties.
1. Reflexive
2. Symmetric
3. Transitive
→ An important property of equivalence relation 'R' on set 'S' is that R partitions 'S' into disjoint
nonempty 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 SjaRb 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 R
is 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)}
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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 3
TERM DEFINITION
prefix of s A string obtained by removing zero or more trailing
symbols 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 s
is 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 not
necessarily contiguous symbols from s; e.g., baaa is a
subsequence of banana.
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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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 component
of 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, automatic
traffic 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 always
is 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 in
one 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 is
exhausted, 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)
where
Q : Finite set of states
∑ : Finite set of input symbols called the alphabet.
δ : Q X ∑ ⇨ Q (δ is a transition function from Q X ∑ to Q)
q0 : A start state, one of the states in Q
F : 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 string
consisting 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 . Suppose
this state is p; that is. ̂( , ) . Then ̂( , )is what we get by making a transition from state p
on 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}
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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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 number
of l's seen so far is even or odd. There are thus four states, which can be given the following
interpretations:
: 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, because
before 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 how
each 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 cross
the vertical, dashed line. Thus, after seeing an even number of l's. we are always to the left, in
state q0 or 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 a
mutual induction with respect to example.
We can also represent this DFA by a transition table. Figure 2.2 shows this table. However, we
are 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
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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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 in
increasing 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 for
some 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
1 1
111
111
1
1
1 1
111
111
1
q1
1 1
111
111
1
q2
1 1
111
111
1
q3
1 1
111
111
1
q0
1 1
111
111
1
1
1 1
111
111
1
0/1
0
Start
0
0
Computer Science Engineering : Theory of computation, THE GATE ACADEMY

Mais conteúdo relacionado

Destaque

Introduction to-automata-theo
Introduction to-automata-theo Introduction to-automata-theo
Introduction to-automata-theo
baharn1
 
Decidability
DecidabilityDecidability
Decidability
andrejko
 
Formal language & automata theory
Formal language & automata theoryFormal language & automata theory
Formal language & automata theory
NYversity
 
Automata languages and computation
Automata languages and computationAutomata languages and computation
Automata languages and computation
Karthik Velou
 

Destaque (16)

Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Introduction to-automata-theo
Introduction to-automata-theo Introduction to-automata-theo
Introduction to-automata-theo
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEM
 
Applications of Automata in Electronic Machines and Android Games (Finite Aut...
Applications of Automata in Electronic Machines and Android Games (Finite Aut...Applications of Automata in Electronic Machines and Android Games (Finite Aut...
Applications of Automata in Electronic Machines and Android Games (Finite Aut...
 
Theory of Computer Science - Post Correspondence Problem
Theory of Computer Science - Post Correspondence ProblemTheory of Computer Science - Post Correspondence Problem
Theory of Computer Science - Post Correspondence Problem
 
Lect 5 2d clipping
Lect 5 2d clippingLect 5 2d clipping
Lect 5 2d clipping
 
Decidability
DecidabilityDecidability
Decidability
 
06 clipping
06 clipping06 clipping
06 clipping
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Introduction to Automata Theory, Languages and Computation
Introduction to Automata Theory, Languages and ComputationIntroduction to Automata Theory, Languages and Computation
Introduction to Automata Theory, Languages and Computation
 
Formal language & automata theory
Formal language & automata theoryFormal language & automata theory
Formal language & automata theory
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)
 
Automata languages and computation
Automata languages and computationAutomata languages and computation
Automata languages and computation
 
Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2
 
Forouzan atm
Forouzan atmForouzan atm
Forouzan atm
 

Mais de klirantga

Mais de klirantga (12)

Mechanical Engineering : Engineering mechanics, THE GATE ACADEMY
Mechanical Engineering  : Engineering mechanics, THE GATE ACADEMYMechanical Engineering  : Engineering mechanics, THE GATE ACADEMY
Mechanical Engineering : Engineering mechanics, THE GATE ACADEMY
 
Instrumentation Engineering : Transducers, THE GATE ACADEMY
 Instrumentation Engineering : Transducers, THE GATE ACADEMY Instrumentation Engineering : Transducers, THE GATE ACADEMY
Instrumentation Engineering : Transducers, THE GATE ACADEMY
 
Instrumentation Engineering : Signals & systems, THE GATE ACADEMY
Instrumentation Engineering : Signals & systems, THE GATE ACADEMYInstrumentation Engineering : Signals & systems, THE GATE ACADEMY
Instrumentation Engineering : Signals & systems, THE GATE ACADEMY
 
Electrical and Electronics Engineering : Power electronics, THE GATE ACADEMY
Electrical and Electronics Engineering : Power electronics, THE GATE ACADEMYElectrical and Electronics Engineering : Power electronics, THE GATE ACADEMY
Electrical and Electronics Engineering : Power electronics, THE GATE ACADEMY
 
Electronics and Communication Engineering : Digital circuits, THE GATE ACADEMY
Electronics and Communication Engineering : Digital circuits, THE GATE ACADEMYElectronics and Communication Engineering : Digital circuits, THE GATE ACADEMY
Electronics and Communication Engineering : Digital circuits, THE GATE ACADEMY
 
Electronics and Communication Engineering : Control systems, THE GATE ACADEMY
 Electronics and Communication Engineering  : Control systems, THE GATE ACADEMY Electronics and Communication Engineering  : Control systems, THE GATE ACADEMY
Electronics and Communication Engineering : Control systems, THE GATE ACADEMY
 
Electronics and Communication Engineering : Communications, THE GATE ACADEMY
Electronics and Communication Engineering : Communications, THE GATE ACADEMYElectronics and Communication Engineering : Communications, THE GATE ACADEMY
Electronics and Communication Engineering : Communications, THE GATE ACADEMY
 
Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY
 Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY
Electronics and Communication Engineering : Analog circuits, THE GATE ACADEMY
 
Computer Science Engineering: Discrete mathematics & graph theory, THE GATE A...
Computer Science Engineering: Discrete mathematics & graph theory, THE GATE A...Computer Science Engineering: Discrete mathematics & graph theory, THE GATE A...
Computer Science Engineering: Discrete mathematics & graph theory, THE GATE A...
 
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMYComputer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
 
Civil Engineering : Rcc & steel structures, THE GATE ACADEMY
Civil Engineering : Rcc & steel structures, THE GATE ACADEMYCivil Engineering : Rcc & steel structures, THE GATE ACADEMY
Civil Engineering : Rcc & steel structures, THE GATE ACADEMY
 
Gate material civil engineering, environmental engineering
Gate material   civil engineering, environmental engineeringGate material   civil engineering, environmental engineering
Gate material civil engineering, environmental engineering
 

Último

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Computer Science Engineering : Theory of computation, THE GATE ACADEMY

  • 1.
  • 2. THEORY OF COMPUTATION For Computer Science & Information Technology By www.thegateacademy.com
  • 3. Syllabus Theory of Computation THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11 : 080-65700750,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com 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
  • 4. Contents 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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
  • 5. Contents 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page II  Simplification of Context Free Grammars 80  Elimination of Useless Symbols 80 – 84  Normal Forms 85 – 91  Pushdown Automata 91 – 92  Definition of PDA’s 92 – 98  Consruction of CFG from a PDA With Empty Stack 98 – 100  Properties of Context Free Languages 100 – 104  Decision Algorithms for CFL’s 104 – 105  Non-Context Free Languages 106 – 108  The Pumping Lemma for CFL’s 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
  • 6. 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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.
  • 7. 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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. Reflexive if aRa for all a in S. 2. Irreflexive if aRa is false for all a is S. 3. Transitive if aRb and bRc implies aRc. 4. Symmetric if aRb implies bRa. 5. Asymmetric if aRb implies that bRa is false. 6. Anti-symmetric if aRb and bRa implies a = b. → Equivalence Relation: A relation is said to be equivalence relation if it satisfies the following properties. 1. Reflexive 2. Symmetric 3. Transitive → An important property of equivalence relation 'R' on set 'S' is that R partitions 'S' into disjoint nonempty 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 SjaRb 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 R is 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. 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 3 TERM DEFINITION prefix of s A string obtained by removing zero or more trailing symbols 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 s is 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 not necessarily contiguous symbols from s; e.g., baaa is a subsequence of banana.
  • 9. 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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 component of 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, automatic traffic 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 always is 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 in one 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 is exhausted, 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) where Q : Finite set of states ∑ : Finite set of input symbols called the alphabet. δ : Q X ∑ ⇨ Q (δ is a transition function from Q X ∑ to Q) q0 : A start state, one of the states in Q F : 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 string consisting 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 . Suppose this state is p; that is. ̂( , ) . Then ̂( , )is what we get by making a transition from state p on 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}
  • 10. 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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 number of l's seen so far is even or odd. There are thus four states, which can be given the following interpretations: : 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, because before 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 how each 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 cross the vertical, dashed line. Thus, after seeing an even number of l's. we are always to the left, in state q0 or 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 a mutual induction with respect to example. We can also represent this DFA by a transition table. Figure 2.2 shows this table. However, we are 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
  • 11. 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,  info@thegateacademy.com © Copyright reserved. Web: www.thegateacademy.com Page 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 in increasing 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 for some 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 1 1 111 111 1 1 1 1 111 111 1 q1 1 1 111 111 1 q2 1 1 111 111 1 q3 1 1 111 111 1 q0 1 1 111 111 1 1 1 1 111 111 1 0/1 0 Start 0 0