1 Introduction
1 Introduction
Slide 1
“Everybody in the country
should learn how to program a
computer... Because it teaches
you how to think.”
-Steve Jobs
2
Why do we study Theory of Computation ?
Slide 3
What is Computation ?
•Sequence of mathematical operations ?
– What are, and are not, mathematical operations?
– Which operations ?
• The simpler, the better.
Slide 5
Computation
Slide 6
Computation
Slide 7
Computation
Slide 8
Theory of Computation
Slide 9
Theory of Computation
Slide 10
Theory of Computation
Slide 11
Algorithm
• A finite sequence of simple instructions that is guaranteed to
halt in a finite amount of time.
Slide 12
Algorithm
• A finite sequence of simple instructions that is guaranteed to
halt in a finite amount of time.
• This is a very abstract definition, since:
– We didn’t specify the nature of this simple instructions.
• For example an instruction can be “increment a number
by one” or “Calculate the triple integral”
Slide 13
Algorithm
• A finite sequence of simple instructions that is guaranteed to
halt in a finite amount of time.
• This is a very abstract definition, since:
– We didn’t specify the nature of this simple instructions.
• For example an instruction can be “increment a number
by one” or “Calculate the triple integral”
– We didn’t specify the entity which can execute these instructions.
Slide 14
Algorithm
• A finite sequence of simple instructions that is guaranteed to
halt in a finite amount of time.
• This is a very abstract definition, since:
– We didn’t specify the nature of this simple instructions.
• For example an instruction can be “increment a number
by one” or “Calculate the triple integral”
– We didn’t specify the entity which can execute these
instructions.
• For example is this entity a person, a computer, …
• If it is a computer what is the processor type? How much
memory does it have? …. ?
Slide 15
What do we study in Theory of Computation ?
• What is computable, and • What a computer can and
what is not ? cannot do
• Are you trying to write a
non-existing program?
• Basis of
– Algorithm analysis – Can you make your program
more efficient?
– Complexity theory
Slide 25
Length
•Concatenation
•Substring
•Reversal
= i=0.. i - {}
• Let = {0, 1}. + = {0, 1, 00, 01, 10, 11, 000, 001, 010, 011,
… }.
* and + are infinite sets.
8/5/2019 Chapter 1 Introduction Slide 34
Languages
• Complementation
• Union
• Intersection
• Concatenation
• Reversal
• Closure
Example:
{ x{0,1}*| x begins with 0} { x{0,1}*| x ends with
0}
= { x{0,1}*| x begins and ends with 0}
8/5/2019 Chapter 1 Introduction Slide 39
Concatenation
Let L1 and L2 be languages over an alphabet Σ.
The concatenation of L1 and L2, denoted by L1L2, is
{w1w2| w1 is in L1 and w2 is in L2}.
Example
Slide 43
GRAMMARS
Slide 44
Type 0 ( Unrestricted Grammar )
• Type-0 grammars include all formal grammars. Type 0 grammar language are
recognized by turing machine.
• These languages are also known as the recursively enumerable languages.
• Grammar Production in the form of
Slide 45
Type 0 ( Unrestricted Grammar )
• Grammar: Unrestricted
• Language: Recursively Enumerable, Recursive
• Automaton: Turing machine
• Definition:(∑UV)*→(∑UV)* With at least one var in LHS
• Example:
• 1. S → Aa
• 2. sBb → abc
• 3. a → Acb (not type-0 as there is no variable on LHS)
• 4. aB → BabcS
Slide 46
Type 1 (Context Sensitive )
Slide 47
Type 1 (Context Sensitive )
• Grammar: context-sensitive
• Language: context-sensitive
• Automaton: linear-bounded automaton
• Definition: (∑UV)*→ (∑UV)* Size of LHS ≤ RHS
• i.e. if x→y then│x│≤ │y│ and αAβ → αBβ
• where-
• α = left context,
• β = right context,
• A = a Variable,
• B = anything (∑UV)* Slide 48
Type 1 (Context Sensitive )
Example:
1. abAbcd → abABbcd
Here ab is the left context, bcd is the right
context, B = AB
2. AC → A
Here A is the left context, Λ is the right context.
B = Λ. This production simply erases when the left
context is A and the right context is Λ
3. C→ Λ
Here the left and right contexts are ᴧ. And B = Λ.
This production simply erases C in any context.
Slide 49
Type 2 ( Context Free )
• In Type 2,
Slide 50
Type 2 ( Context Free )
Grammar: context-free
Language: context-free
Automaton: pushdown automaton
Definition: A → (∑UV)*
Example:
1. S → Aa
2. Sb → Aa (not type-2 as left hand side other than
a varible one terminal is also there)
3. B → bAa
Type 3 (Regular Grammar)
Slide 52
Type 3 (Regular Grammar)
Grammar: Regular
Language: Regular
Automaton: finite-state automaton
Definition:
A → a , A → aB --> Right linear Grammar
A → a , A → Ba --> Left linear grammar
Example:
1. A → aB/Ba/a
2. A → BAa (not type-3 as right hand side has more
than one i.e 2 variables which is not allowed in regular grammar )
3. Ab → aB (not type-3 as LHS has symbols other than a variable)
Slide 53
Null Production
Slide 54
Slide 55
Regular expression
Slide 56
Regular definition for recognizing identifiers in C
Slide 57
Regular expression
• Decimal = (sign)?(digit)+
• Identifier = (letter)(letter | digit)*
Slide 58
Regular expressions generating the languages
{w| w contains at least three 1s}
Σ∗1Σ∗1Σ∗1Σ∗
{w| w contains the substring 0101, i.e., w = x0101y for some x and
y}
Σ∗0101Σ∗
Σ Σ 0Σ ∗ Slide 59
Regular expressions generating the languages
Slide 60
Regular expressions generating the languages
Slide 61
Regular expressions generating the languages
• Write regular expressions for the following languages over the
alphabet Σ = {a, b}:
• All strings that do not end with aa.
ε + a + b + (a + b)* (ab + ba + bb)
• All strings that contain an even number of b’s.
a*(ba*ba*)*
• All strings which do not contain the substring ba.
a*b*
Slide 62
Languages and Problems
• Problem
– Example: What are prime numbers > 20?
• Decision problem
– Problem with a YES/NO answer
– Example: Given a positive integer n, is n a prime number >
20?
• Language
– Example: {n | n is a prime number > 20}
= {23, 29, 31, 37, …}
8/5/2019 Chapter 1 Introduction Slide 63
Language Recognition and Problem
• A problem is represented by a set of strings of the
input whose answer for the corresponding problem is
“YES”.
• a string is in a language = the answer of the
corresponding problem for the string is “YES”
– Let “Given a positive integer n, is n a prime number > 20?”
be the problem P.
– If a string represents an integer i in {m | m is a prime
number > 20} , then the answer for the problem P for n = i is
true.
8/5/2019 Chapter 1 Introduction Slide 64
Describing Problems
• Problems described by functions
functions assign ouputs to inputs
described by tables, formulae, circuits, math logic, algorithms
Example: TRAVELLING SALESPERSON Problem
Input: n(n-1)/2 distances between n cities
Output: order to visit cities that gives shortest tour (or length of tour)
• Problems described by languages
``yes/no’’ problems or decision problems
a language represents a problem or question
input strings in the language: answer is ``yes’’; else ``no”
Example: HALTING Problem
Input: a string w and a Turing Machine M
Output: ``yes” if w L(M ) ;``no” otherwise
equivalent to asking if string (e, w) LH
where LH {(e, w) | Turing Machine M e halts on input w}