Week 1
Week 1
Acknowledgement
Books
• Introduction to Theory of Computation,
Michael Sipser, 3rd Edition
• Introduction to Computer Theory, Danial I. A.
Cohen
• Introduction to Automata Theory,
Languages, and Computations, John Hopcroft
and Jeffery Ullman, 3rd Edition
• An Introduction to Formal Languages and
Automata, Peter Linz
• Introduction to Languages and the Theory of
Computation, John C. Martin. Fourth Edition
Context-Free Languages
• Context-free grammars, parse trees.
• Derivations and ambiguity.
• Relation to pushdown automata.
• Properties of such languages and techniques for
showing that a language is not context-free.
Turing Machines
• Basic definitions and relation to the notion of an
algorithm or program.
• Power of Turing Machines.
Computation
CPU memory
temporary memory
input
CPU
output
Program memory
Example: f ( x) x 3
temporary memory
input
CPU
output
Program memory
compute xx
compute x x
2
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
f ( x) x 3
temporary memory
input
x2
CPU
output
Program memory
compute xx
compute x x
2
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
temporary memory
z 2*2 4 f ( x) x 3
f ( x) z * 2 8
input
x2
CPU
output
Program memory
compute xx
compute x x
2
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
temporary memory
z 2*2 4 f ( x) x 3
f ( x) z * 2 8
input
x2
CPU
f ( x) 8
Program memory output
compute xx
compute x x
2
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Automaton
temporary memory
Automaton
input
CPU
output
Program memory
Automaton
temporary memory
Automaton
input
output
transition
state
Finite Automaton
temporary memory
input
Finite
Automaton
output
Temp.
Pushdown Automaton
memory Stack Push, Pop
Pushdown input
Automaton
output
Turing Machine
Temp.
memory Random Access Memory
input
Turing
Machine
output
Power of Automata
Simple More complex Hardest
problems problems problems
Set
• A set is a group of objects represented as a unit.
• Sets may contain any type of object, including
numbers, symbols, and even other sets.
• The objects in a set are called its elements or
members.
Languages
• Example:
• Strings: cat, dog, house
• Language: {cat, dog, house}
102345 567463386
String Operations
w a1a2 an abba
v b1b2 bm bbbaaa
Concatenation
Reverse
w an a2a1
R
bbbaaababa
String Length
w a1a2 an
• Length: w n
• Examples: abba 4
aa 2
a 1
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
String Length
Length of Concatenation
uv u v
• Example:u aab, u 3
v abaab, v 5
uv aababaab 8
uv u v 3 5 8
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Empty String
• A string with no letters is denoted:
or
• Observations: 0
w w w
Substring
• Substring of string:
– a subsequence of consecutive
characters
• String Substring
abbab ab
abbab abba
abbab b
abbab bbab
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Another Operation
n
w ww
w
n
• Definition: w
0
–
abba 0
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
The * Operation
a, b
* , a, b, aa, ab, ba, bb, aaa, aab,
Example
Example 2
Closure of Null
a, b
* , a, b, aa, ab, ba, bb, aaa, aab,
*
a, b, aa, ab, ba, bb, aaa, aab,
a, b
* , a, b, aa, ab, ba, bb, aaa,
Language:
Language: a, aa, aab
Language: { , abba, baba, aa, ab, aaaaaa}
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
ab
L abb L
aabb
aaaaabbbbb
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Prime numbers
Language:
PRIMES {2,3,5,7,11,13,17,}
EVEN { 0,2,4,6, }
ODD {1,3,5,7, }
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Unary Addition
Alphabet: {1,, }
Language:
ADDITION {x y z : x 1n , y 1m , z 1k ,
nm k}
Squares
Alphabet: {1, # }
Language:
SQUARES {x # y : x 1 , y 1 , m n } n m 2
11#1111 SQUARES
111#1111 SQUARES
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Note that:
Sets { } {}
Set size {} 0
Operations on Languages
• The usual set operations
Reverse
• Definition: L {w : w L}
R R
L {a b : n 0}
n n
L {b a : n 0}
R n n
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Concatenation
Concatenation (cont..)
• Concatenation does not always produce word in
same language.
Another Operation
• Definition: L
n
LL L
n
L {a b : n 0}
n n
L {a b a b : n, m 0}
2 n n m m
2
aabbaaabbb L
Star-Closure (Kleene *)
• All strings that can be constructed from L
• Definition: L* L L L
0 1 2
• Example:
,
a, bb,
a, bb*
aa , abb, bba , bbbb,
• aaa, aabb, abba, abbbb,
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Positive Closure
• Definition: L L L
1 2
a, bb,
a, bb aa, abb, bba, bbbb,
aaa, aabb, abba, abbbb,
Government College University, Faisalabad
Week 1-Introduction Advanced Theory of Computation
Palindrome
Theorem
• S* = S**
• S* != S+
• When S* == S+ ?
Exercise