1 theory of computation 計算理論 2 instructor: 顏嗣鈞 e-mail: [email protected] web: yen...
TRANSCRIPT
![Page 1: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/1.jpg)
1
Theory of Computation
計算理論
![Page 2: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/2.jpg)
2
Instructor: 顏嗣鈞
E-mail: [email protected]
Web: http://www.ee.ntu.edu.tw/~yen
Time: 2:20-5:10 PM, Tuesday
Place: BL 112
Office hours: by appointment
Class web page: http://www.ee.ntu.edu.tw/~yen/courses/TOC-2006.htm
![Page 3: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/3.jpg)
3
• :
Introduction to Automata Theory, Languages, and Computation
John E. Hopcroft, Rajeev Motwani,
Jeffrey D. Ullman,
(2nd Ed. Addison-Wesley, 2001)
textbook
![Page 4: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/4.jpg)
4
1st Edition
Introduction to Automata Theory, Languages, and Computation John E. Hopcroft,
Jeffrey D. Ullman,
(Addison-Wesley, 1979)
![Page 5: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/5.jpg)
5
Grading
HW : 0-20%
Midterm exam.: 35-45%
Final exam.: 45-55%
![Page 6: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/6.jpg)
6
Why Study Automata Theory?
Finite automata are a useful model for important kinds of hardware and software:
• Software for designing and checking digital circuits.
• Lexical analyzer of compilers. • Finding words and patterns in large bodies of
text, e.g. in web pages.• Verification of systems with finite number of
states, e.g. communication protocols.
![Page 7: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/7.jpg)
7
Why Study Automata Theory? (2)
The study of Finite Automata and Formal Languages are intimately connected. Methods for specifying formal languages are very important in many areas of CS, e.g.:
• Context Free Grammars are very useful when designing software that processes data with recursive structure, like the parser in a compiler.
• Regular Expressions are very useful for specifying lexical aspects of programming languages and search patterns.
![Page 8: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/8.jpg)
8
Why Study Automata Theory? (3)
Automata are essential for the study of the limits of computation. Two issues:
• What can a computer do at all? (Decidability)
• What can a computer do efficiently? (Intractability)
![Page 9: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/9.jpg)
9
Applications
Theoretical Computer ScienceAutomata Theory, Formal Languages,
Computability, Complexity …
Com
pile
r
Pro
g.
lan
gu
ag
es
Com
m.
pro
toco
ls
circuits
Patte
rn
reco
gn
ition
Sup
erv
isory
co
ntro
l
Qu
an
tum
co
mpu
ting
Com
pu
ter-
Aid
ed
V
erifi
catio
n ...
![Page 10: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/10.jpg)
10
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
![Page 11: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/11.jpg)
11
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?
![Page 12: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/12.jpg)
12
Studying the Theme
• How do we prove something CAN be done by SOME program?
• How do we prove something CANNOT be done by ANY program?
![Page 13: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/13.jpg)
13
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;}
}
![Page 14: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/14.jpg)
14
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
In fact, for all numbers that have been tried
(a lot!), it does terminate . . .
. . . but in general?
![Page 15: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/15.jpg)
15
Example: The Halting Problem (3)Then the following important undecidability
result should perhaps not come as a total surprise:
It is impossible to write a program that decides if another, arbitrary, program terminates (halts) or not.
What might be surprising is that it is possible to prove such a result. This was first done by the British mathematician Alan Turing.
![Page 16: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/16.jpg)
16
Our focus
AutomataComputability
Complexity
![Page 17: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/17.jpg)
17
Topics1. 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.
3.
![Page 18: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/18.jpg)
18
Topics (cont’d)3. Linear bounded automata, Context-
sensitive languages, Context-sensitive grammars.
4. Turing machines, Recursively enumerable sets, Type 0 grammars: variants of Turing machines, halting problem, undecidability, Post correspondence problem, valid and invalid computations of TMs.
![Page 19: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/19.jpg)
19
Topics (cont’d)5. Basic recursive function theory 6. Basic complexity theory: Various
resource bounded complexity classes, including NLOGSPACE, P, NP, PSPACE, EXPTIME, and many more. reducibility, completeness.
7. Advanced topics: Tree Automata, quantum automata, probabilistic automata, interactive proof systems, oracle computations, cryptography.
![Page 20: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/20.jpg)
20
Who should take this course?
YOU
![Page 21: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/21.jpg)
21
Languages
The terms language and word are used in a strict technical sense in this course:
A language is a set of words.
A word is a sequence (or string) of symbols.
(or ) denotes the empty word, the sequence of zero symbols.
![Page 22: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/22.jpg)
22
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.
![Page 23: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/23.jpg)
23
Computation
CPU memory
![Page 24: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/24.jpg)
24
CPU
input memory
output memory
Program memory
temporary memory
![Page 25: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/25.jpg)
25
CPU
input memory
output memoryProgram memory
temporary memory
3)( xxf
compute xx
compute xx 2
Example:
![Page 26: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/26.jpg)
26
CPU
input memory
output memoryProgram memory
temporary memory
3)( xxf
compute xx
compute xx 2
2x
![Page 27: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/27.jpg)
27
CPU
input memory
output memoryProgram memory
temporary memory3)( xxf
compute xx
compute xx 2
2x
42*2 z82*)( zxf
![Page 28: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/28.jpg)
28
CPU
input memory
output memoryProgram memory
temporary memory3)( xxf
compute xx
compute xx 2
2x
42*2 z82*)( zxf
8)( xf
![Page 29: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/29.jpg)
29
Automaton
CPU
input memory
output memory
Program memory
temporary memory
Automaton
![Page 30: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/30.jpg)
30
Different Kinds of Automata
Automata are distinguished by the temporary memory
• Finite Automata: no temporary memory
• Pushdown Automata: stack
• Turing Machines: random access memory
![Page 31: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/31.jpg)
31
input memory
output memory
temporary memory
Finite
Automaton
Finite Automaton
Example: Vending Machines
(small computing power)
![Page 32: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/32.jpg)
32
input memory
output memory
Stack
Pushdown
Automaton
Pushdown Automaton
Example: Compilers for Programming Languages
(medium computing power)
Push, Pop
![Page 33: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/33.jpg)
33
input memory
output memory
Random Access Memory
Turing
Machine
Turing Machine
Examples: Any Algorithm
(highest computing power)
![Page 34: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/34.jpg)
34
Finite
Automata
Pushdown
Automata
Turing
Machine
Power of Automata
Less power More power
Solve more
computational problems
![Page 35: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/35.jpg)
35
Mathematical Preliminaries
![Page 36: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/36.jpg)
36
Mathematical Preliminaries
• Sets
• Functions
• Relations
• Graphs
• Proof Techniques
![Page 37: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/37.jpg)
37
}3,2,1{AA set is a collection of elements
SETS
},,,{ airplanebicyclebustrainB
We write
A1
Bship
![Page 38: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/38.jpg)
38
Set Representations
C = { a, b, c, d, e, f, g, h, i, j, k }
C = { a, b, …, k }
S = { 2, 4, 6, … }
S = { j : j > 0, and j = 2k for some k>0 }
S = { j : j is nonnegative and even }
finite set
infinite set
![Page 39: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/39.jpg)
39
A = { 1, 2, 3, 4, 5 }
Universal Set: all possible elements U = { 1 , … , 10 }
1 2 34 5
A
U
6
78
910
![Page 40: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/40.jpg)
40
Set Operations
A = { 1, 2, 3 } B = { 2, 3, 4, 5}
• Union
A U B = { 1, 2, 3, 4, 5 }
• Intersection
A B = { 2, 3 }
• Difference
A - B = { 1 }
B - A = { 4, 5 }
U
A B
A-B
![Page 41: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/41.jpg)
41
A
• Complement
Universal set = {1, …, 7}
A = { 1, 2, 3 } A = { 4, 5, 6, 7}
12
3
4
5
6
7
A
A = A
![Page 42: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/42.jpg)
42
024
6
1
3
5
7
even
{ even integers } = { odd integers }
odd
Integers
![Page 43: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/43.jpg)
43
DeMorgan’s Laws
A U B = A B
U
A B = A U BU
![Page 44: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/44.jpg)
44
Empty, Null Set:= { }
S U = S
S =
S - = S
- S =
U= Universal Set
![Page 45: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/45.jpg)
45
Subset
A = { 1, 2, 3} B = { 1, 2, 3, 4, 5 }
A B
U
Proper Subset: A B
UA
B
![Page 46: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/46.jpg)
46
Disjoint Sets
A = { 1, 2, 3 } B = { 5, 6}
A B =
UA B
![Page 47: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/47.jpg)
47
Set Cardinality
• For finite sets
A = { 2, 5, 7 }
|A| = 3
![Page 48: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/48.jpg)
48
Powersets
A powerset is a set of sets
Powerset of S = the set of all the subsets of S
S = { a, b, c }
2S = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }
Observation: | 2S | = 2|S| ( 8 = 23 )
![Page 49: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/49.jpg)
49
Cartesian ProductA = { 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|
Generalizes to more than two sets
A X B X … X Z
![Page 50: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/50.jpg)
50
FUNCTIONSdomain
123
a
bc
range
f : A -> B
A B
If A = domain
then f is a total function
otherwise f is a partial function
f(1) = a
![Page 51: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/51.jpg)
51
RELATIONS R = {(x1, y1), (x2, y2), (x3, y3), …}
xi R yi
e. g. if R = ‘>’: 2 > 1, 3 > 2, 3 > 1
In relations xi can be repeated
![Page 52: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/52.jpg)
52
Equivalence Relations
• Reflexive: x R x
• Symmetric: x R y y R x
• Transitive: x R y and y R z x R z
Example: R = ‘=‘
• x = x
• x = y y = x
• x = y and y = z x = z
![Page 53: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/53.jpg)
53
Equivalence ClassesFor 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) }
Equivalence class of 1 = {1, 2}
Equivalence class of 3 = {3, 4}
![Page 54: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/54.jpg)
54
GRAPHSA directed graph
• Nodes (Vertices)
V = { a, b, c, d, e }
• Edges
E = { (a,b), (b,c), (b,e),(c,a), (c,e), (d,c), (e,b), (e,d) }
node
edge
a
b
c
d
e
![Page 55: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/55.jpg)
55
Labeled Graph
a
b
c
d
e
1 35 6
26
2
![Page 56: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/56.jpg)
56
Walk
a
b
c
d
e
Walk is a sequence of adjacent edges
(e, d), (d, c), (c, a)
![Page 57: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/57.jpg)
57
Path
a
b
c
d
e
Path is a walk where no edge is repeated
Simple path: no node is repeated
![Page 58: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/58.jpg)
58
Cycle
a
b
c
d
e
12
3
Cycle: a walk from a node (base) to itself
Simple cycle: only the base node is repeated
base
![Page 59: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/59.jpg)
59
Euler Tour
a
b
c
d
e1
23
45 6
78 base
A cycle that contains each edge once
![Page 60: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/60.jpg)
60
Hamiltonian Cycle
a
b
c
d
e1
23
4
5 base
A simple cycle that contains all nodes
![Page 61: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/61.jpg)
61
Treesroot
leaf
parent
child
Trees have no cycles
![Page 62: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/62.jpg)
62
root
leaf
Level 0
Level 1
Level 2
Level 3
Height 3
![Page 63: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/63.jpg)
63
Binary Trees
![Page 64: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/64.jpg)
64
PROOF TECHNIQUES
• Proof by induction
• Proof by contradiction
![Page 65: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/65.jpg)
65
Induction
We have statements P1, P2, P3, …
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
![Page 66: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/66.jpg)
66
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
Show that Pk+1 is true
![Page 67: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/67.jpg)
67
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
![Page 68: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/68.jpg)
68
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
![Page 69: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/69.jpg)
69
Induction Step
From Inductive hypothesis: L(k) <= 2k
Level
k
k+1
![Page 70: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/70.jpg)
70
L(k) <= 2k
Level
k
k+1
L(k+1) <= 2 * L(k) <= 2 * 2k = 2k+1
Induction Step
![Page 71: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/71.jpg)
71
Remark
Recursion is another thing
Example of recursive function:
f(n) = f(n-1) + f(n-2)
f(0) = 1, f(1) = 1
![Page 72: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/72.jpg)
72
Proof by Contradiction
We want to prove that a statement P is true
• we assume that P is false
• then we arrive at an incorrect conclusion
• therefore, statement P must be true
![Page 73: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/73.jpg)
73
Example
Theorem: is not rational
Proof:
Assume by contradiction that it is rational
= n/m
n and m have no common factors
We will show that this is impossible
2
2
![Page 74: 1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 E-mail: yen@ee.ntu.edu.tw Web: yen Time: 2:20-5:10 PM, Tuesday Place: BL 112](https://reader035.vdocuments.site/reader035/viewer/2022062515/56649f485503460f94c6a507/html5/thumbnails/74.jpg)
74
= n/m 2 m2 = n2
Therefore, n2 is evenn is even
n = 2 k
2 m2 = 4k2 m2 = 2k2m is even
m = 2 p
Thus, m and n have common factor 2
Contradiction!
2