Theory of Computation Lect1-2
description
Transcript of Theory of Computation Lect1-2
![Page 1: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/1.jpg)
Formal Languages
Models of Computation
![Page 2: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/2.jpg)
2
Computation
CPU memory
![Page 3: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/3.jpg)
3
CPU
input memory
output memory
Program memory
temporary memory
![Page 4: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/4.jpg)
4
CPU
input memory
output memoryProgram memory
temporary memory
3)( xxf
compute xx
compute xx 2
Example:
![Page 5: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/5.jpg)
5
CPU
input memory
output memoryProgram memory
temporary memory
3)( xxf
compute xx
compute xx 2
2x
![Page 6: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/6.jpg)
6
CPU
input memory
output memoryProgram memory
temporary memory3)( xxf
compute xx
compute xx 2
2x
42*2 z82*)( zxf
![Page 7: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/7.jpg)
7
CPU
input memory
output memoryProgram memory
temporary memory3)( xxf
compute xx
compute xx 2
2x
42*2 z82*)( zxf
8)( xf
![Page 8: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/8.jpg)
Automata theory
Automata theory studies the laws of computation.
In reality, the laws of computation are not quite understood, but automata theory is a good start.
![Page 9: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/9.jpg)
A simple computer
BATTERY
SWITCH
input: switch
output: light bulb
actions: flip switch
states: on, off
![Page 10: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/10.jpg)
A simple “computer”
BATTERY
SWITCH
off onstartf
f
input: switch
output: light bulb
actions: f for “flip switch”
states: on, off
bulb is on if and only if there was an odd number of flips
![Page 11: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/11.jpg)
Another “computer”
BATTERY
off offstart1
inputs: switches 1 and 2
actions: 1 for “flip switch 1”actions: 2 for “flip switch 2”
states: on, off
bulb is on if and only if both switches were flipped an odd number of times
1
2
1
off on1
1
2 2 2 2
![Page 12: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/12.jpg)
12
Automaton
CPU
input memory
output memory
Program memory
temporary memory
Automaton
![Page 13: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/13.jpg)
13
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 14: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/14.jpg)
14
input memory
output memory
temporary memory
Finite
Automaton
Finite Automaton
Example: Vending Machines
(small computing power)
![Page 15: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/15.jpg)
15
input memory
output memory
Stack
Pushdown
Automaton
Pushdown Automaton
Example: Compilers for Programming Languages
(medium computing power)
Push, Pop
![Page 16: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/16.jpg)
16
input memory
output memory
Random Access Memory
Turing
Machine
Turing Machine
Examples: Any Algorithm
(highest computing power)
![Page 17: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/17.jpg)
17
Finite
Automata
Pushdown
Automata
Turing
Machine
Power of Automata
Less power More power
Solve more
computational problems
![Page 18: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/18.jpg)
18
Languages
![Page 19: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/19.jpg)
19
A language is a set of strings
String: A sequence of letters
Examples: “cat”, “dog”, “house”, …
Defined over an alphabet: zcba ,,,,
![Page 20: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/20.jpg)
20
Alphabets and StringsWe will use small alphabets:
Strings
abbaw
bbbaaav
abu
ba,
baaabbbaaba
baba
abba
ab
a
![Page 21: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/21.jpg)
21
String Operations
m
n
bbbv
aaaw
21
21
bbbaaa
abba
mn bbbaaawv 2121
Concatenation
abbabbbaaa
![Page 22: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/22.jpg)
22
12aaaw nR
naaaw 21 ababaaabbb
Reverse
bbbaaababa
![Page 23: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/23.jpg)
23
String Length
Length:
Examples:
naaaw 21
nw
1
2
4
a
aa
abba
![Page 24: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/24.jpg)
24
Length of Concatenation
Example:
vuuv
853
8
5,
3,
vuuv
aababaabuv
vabaabv
uaabu
![Page 25: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/25.jpg)
25
Empty StringA string with no letters:
Observations:
abbaabbaabba
www
0
![Page 26: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/26.jpg)
26
SubstringSubstring of string:
a subsequence of consecutive characters
String Substring
bbab
b
abba
ab
abbab
abbab
abbab
abbab
![Page 27: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/27.jpg)
27
Prefix and Suffix
Prefixes Suffixesabbab
abbab
abba
abb
ab
a
b
ab
bab
bbab
abbab uvw
prefix
suffix
![Page 28: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/28.jpg)
28
Another Operation
Example:
Definition:
n
n wwww
abbaabbaabba 2
0w
0abba
![Page 29: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/29.jpg)
29
The * Operation : the set of all possible strings from alphabet
*
,,,,,,,,,*
,
aabaaabbbaabaaba
ba
![Page 30: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/30.jpg)
30
The + Operation : the set of all possible strings from alphabet except
,,,,,,,,,*
,
aabaaabbbaabaaba
ba
*
,,,,,,,, aabaaabbbaabaaba
![Page 31: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/31.jpg)
31
LanguagesA language is any subset of
Example:
Languages:
*
,,,,,,,,*
,
aaabbbaabaaba
ba
},,,,,{
,,
aaaaaaabaababaabba
aabaaa
![Page 32: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/32.jpg)
32
Note that:
}{}{
0}{
1}{
0
Sets
Set size
Set size
String length
![Page 33: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/33.jpg)
33
Another Example
An infinite language }0:{ nbaL nn
aaaaabbbbb
aabb
ab
L Labb
![Page 34: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/34.jpg)
34
Operations on LanguagesThe usual set operations
Complement:
aaaaaabbbaaaaaba
ababbbaaaaaba
aaaabbabaabbbaaaaaba
,,,,
}{,,,
},,,{,,,
LL *
,,,,,,, aaabbabaabbaa
![Page 35: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/35.jpg)
35
Reverse
Definition:
Examples:
}:{ LwwL RR
ababbaabababaaabab R ,,,,
}0:{
}0:{
nabL
nbaL
nnR
nn
![Page 36: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/36.jpg)
36
Concatenation
Definition:
Example:
2121 ,: LyLxxyLL
baaabababaaabbaaaab
aabbaaba
,,,,,
,,,
![Page 37: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/37.jpg)
37
Another OperationDefinition:
Special case:
n
n LLLL
bbbbbababbaaabbabaaabaaa
babababa
,,,,,,,
,,,, 3
0
0
,, aaabbaa
L
![Page 38: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/38.jpg)
38
More Examples
}0:{ nbaL nn
}0,:{2 mnbabaL mmnn
2Laabbaaabbb
![Page 39: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/39.jpg)
39
Star-Closure (Kleene *)
Definition:
Example:
210* LLLL
,,,,
,,,,
,,
,
*,
abbbbabbaaabbaaa
bbbbbbaabbaa
bbabba
![Page 40: Theory of Computation Lect1-2](https://reader036.fdocuments.in/reader036/viewer/2022081419/5571f82249795991698cb64a/html5/thumbnails/40.jpg)
40
Positive Closure
Definition:
*
21
L
LLL
,,,,
,,,,
,,
,
abbbbabbaaabbaaa
bbbbbbaabbaa
bba
bba