Professional Documents
Culture Documents
CS4 Slides - 1
CS4 Slides - 1
Theory of Computation
1
Why Study Automata Theory?
Finite automata are a useful model for
important kinds of hardware and software:
Computer-Aided
Automata Theory, Formal Languages,
Verification
Computability, Complexity …
Quantum
computing
Applications
Supervisory
control
Pattern
recognition
circuits
Comm.
protocols
Prog. languages
Compiler
Aims of the Course
• To familiarize you with key Computer Science
concepts in central areas like
- Automata Theory
- Formal Languages
- Models of Computation
- Complexity Theory
• To equip you with tools with wide applicability
in the fields of CS and EE, e.g. for
- Complier Construction
- Text Processing
- XML
6
Fundamental Theme
• What are the capabilities and
limitations of computers and computer
programs?
– What can we do with
computers/programs?
– Are there things we cannot do with
computers/programs?
7
Studying the Theme
• How do we prove something CAN be done
by SOME program?
8
Example: The Halting Problem (1)
Consider the following program. Does it
terminate for all values of n 1?
while (n > 1) {
if even(n) {
n = n / 2;
} else {
n = n * 3 + 1;
}
} 9
Example: The Halting Problem (2)
Not as easy to answer as it might first seem.
Say we start with n = 7, for example:
7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5,
16, 8, 4, 2, 1
. . . but in general?
10
Example: The Halting Problem (3)
Then the following important undecidability
result should perhaps not come as a total
surprise:
Computability
Automata
Complexity
12
Topics
1. Finite
automata, Regular languages, Regular
grammars: deterministic vs. nondeterministic,
one-way vs. two-way finite automata,
minimization, pumping lemma for regular sets,
closure properties.
2. Pushdown automata, Context-free languages,
Context-free grammars: deterministic vs.
nondeterministic, one-way vs. two-way PDAs,
reversal bounded PDAs, linear grammars, counter
machines, pumping lemma for CFLs, Chomsky
normal form, Greibach normal form, closure
properties. 13
Topics (cont’d)
3. Linearbounded automata, Context-
sensitive languages, Context-sensitive
grammars.
16
Symbols and Alphabets
• What is a symbol, then?
• Anything, but it has to come from an
alphabet which is a finite set.
• A common (and important) instance is
= {0, 1}.
, the empty word, is never an symbol
of an alphabet.
17
Computation
CPU memory
18
temporary memory
input memory
CPU
output memory
Program memory
19
3
Example: f ( x) x
temporary memory
input memory
CPU
output memory
Program memory
compute xx
2
compute x x 20
3
f ( x) x
temporary memory
input memory
x2
CPU
output memory
Program memory
compute xx
2
compute x x 21
3
temporary memory f ( x) x
z 2*2 4
f ( x) z * 2 8
input memory
x2
CPU
output memory
Program memory
compute xx
2
compute x x 22
3
temporary memory f ( x) x
z 2*2 4
f ( x) z * 2 8
input memory
x2
CPU
f ( x) 8
Program memory output memory
compute xx
2
compute x x 23
Automaton
temporary memory
Automaton
input memory
CPU
output memory
Program memory
24
Different Kinds of Automata
Automata are distinguished by the temporary memory
25
Finite Automaton
temporary memory
input memory
Finite
Automaton
output memory
input memory
Pushdown
Automaton
output memory
input memory
Turing
Machine
output memory
30
Mathematical Preliminaries
• Sets
• Functions
• Relations
• Graphs
• Proof Techniques
31
SETS
A set is a collection of elements
A {1, 2, 3}
B {train, bus, bicycle, airplane}
We write
1 A
ship B
32
Set Representations
C = { a, b, c, d, e, f, g, h, i, j, k }
C = { a, b, …, k } finite set
S = { 2, 4, 6, … } infinite set
U
6 A
2 3 8
1
7 4 5
9
10
U = { 1 , … , 10 }
34
Set Operations
A = { 1, 2, 3 } B = { 2, 3, 4, 5}
A B
• Union
A U B = { 1, 2, 3, 4, 5 }
• Intersection
U
A B = { 2, 3 }
• Difference
A-B={1}
A-B
B - A = { 4, 5 }
35
• Complement
Universal set = {1, …, 7}
A = { 1, 2, 3 } A = { 4, 5, 6, 7}
4
A
A 3 6
1
2
5 7
A=A
36
{ even integers } = { odd integers }
Integers
1 odd
even 5
2 6
0
4
3 7
37
DeMorgan’s Laws
U
AUB=A B
U
A B=AUB
38
Empty, Null Set:
={}
SU =S
U
S = = Universal Set
S- =S
-S=
39
Subset
A = { 1, 2, 3} B = { 1, 2, 3, 4, 5 }
A B
U
Proper Subset: A B
U
B
A
40
Disjoint Sets
A = { 1, 2, 3 } B = { 5, 6}
U
A B=
A B
41
Set Cardinality
• For finite sets
A = { 2, 5, 7 }
|A| = 3
42
Powersets
A powerset is a set of sets
S = { a, b, c }
2S = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }
Observation: | 2S | = 2|S| ( 8 = 23 )
43
Cartesian Product
A = { 2, 4 } B = { 2, 3, 5 }
A X B = { (2, 2), (2, 3), (2, 5), ( 4, 2), (4, 3), (4, 5) }
|A X B| = |A| |B|
AXBX…XZ 44
FUNCTIONS
domain range
A B
f(1) = a a
1
2 b
3 c
f : A -> B
If A = domain
then f is a total function
otherwise f is a partial function
45
RELATIONS
R = {(x1, y1), (x2, y2), (x3, y3), …}
xi R yi
Example: R = ‘=‘
•x=x
•x=y y=x
• x = y and y = z x=z
47
Equivalence Classes
For equivalence relation R
equivalence class of x = {y : x R y}
Example:
R = { (1, 1), (2, 2), (1, 2), (2, 1),
(3, 3), (4, 4), (3, 4), (4, 3) }
50
Walk
e
b
a d
51
Path
e
b
a d
base e
b
3
a 1 d
2
c
54
Hamiltonian Cycle
5 base
e
b 1
4
a 2 d
3
c
55
Trees
root
parent
leaf
child
56
root
Level 0
Level 1
leaf Height 3
Level 2
Level 3
57
Binary Trees
58
PROOF TECHNIQUES
• Proof by induction
• Proof by contradiction
59
Induction
If we know
• for some b that P1, P2, …, Pb are true
• for any k >= b that
P1, P2, …, Pk imply Pk+1
Then
Every Pi is true
60
Proof by Induction
• Inductive basis
Find P1, P2, …, Pb which are true
• Inductive hypothesis
Let’s assume P1, P2, …, Pk are true,
for any k >= b
• Inductive step
61
Show that Pk+1 is true
Example
Theorem: A binary tree of height n
has at most 2n leaves.
Proof by induction:
let L(i) be the number of leaves at level i
L(0) = 1
L(1) = 2
L(2) = 4
L(3) = 8 62
We want to show: L(i) <= 2i
• Inductive basis
L(0) = 1 (the root node)
• Inductive hypothesis
Let’s assume L(i) <= 2i for all i = 0, 1, …, k
• Induction step
we need to show that L(k + 1) <= 2k+1 63
Induction Step
Level
k
k+1
64
Induction Step
Level
k L(k) <= 2k
k+1
65
Remark
Recursion is another thing
f(0) = 1, f(1) = 1
66
Proof by Contradiction
67
Example
Theorem: 2 is not rational
Proof:
Assume by contradiction that it is rational
2 = n/m
n and m have no common factors
n is even
Therefore, n2 is even
n=2k
m is even
2 m2 = 4k2 m2 = 2k2
m=2p
Contradiction! 69