Professional Documents
Culture Documents
2
Chapter Zero
Introduction
3
Models of Computation
Computation
CPU memory
4
temporary memory
input
CPU
output
Program memory
5
temporary memory Example: f ( x) = x 3
input
CPU
output
Program memory
compute xx
compute x x
2
6
temporary memory f ( x) = x 3
input
x=2
CPU
output
Program memory
compute xx
compute x x
2
7
temporary memory
z = 2*2 = 4
f ( x) = z * 2 = 8 f ( x) = x 3
input
x=2
CPU
output
Program memory
compute xx
compute x 2
x
8
temporary memory
z = 2*2 = 4
f ( x) = z * 2 = 8 f ( x) = x 3
input
x=2
CPU
f ( x) = 8
Program memory output
compute xx
compute x x
2
9
Automaton
temporary memory
Automaton
input
CPU
output
Program memory
10
Automaton
temporary memory
Automaton
input
output
transition
state
11
Different Kinds of Automata
12
Finite Automaton
temporary memory
input
Finite
Automaton
output
Pushdown input
Automaton
output
Temp.
memory Random Access Memory
input
Turing
Machine
output
NP-complete problems
Believed to take exponential
time to be solved
P problems
Solved in polynomial time
18
AUTOMATA, COMPUTABILITY, AND COMPLEXITY
20
COMPLEXITY THEORY
22
COMPLEXITY THEORY
23
COMPLEXITY THEORY
• There are several options when you confront a problem that
appears to be computationally hard.
• First, by understanding which aspect of the problem is at the root of
the difficulty, you may be able to alter it so that the problem is more
easily solvable.
• Second, you may be able to settle for less than a perfect solution to
the problem. In certain cases, finding solutions that only
approximate the perfect one is relatively easy.
• Third, some problems are hard only in the worst case situation, but
easy most of the time.
• Depending on the application, you may be satisfied with a
procedure that occasionally is slow but usually runs quickly.
• Finally, you may consider alternative types of computation, such as
randomized computation, that can speed up certain tasks.
24
COMPLEXITY THEORY
• There are several options when you confront a problem that
appears to be computationally hard.
• First, by understanding which aspect of the problem is at the root of
the difficulty, you may be able to alter it so that the problem is more
easily solvable.
• Second, you may be able to settle for less than a perfect solution to
the problem. In certain cases, finding solutions that only
approximate the perfect one is relatively easy.
• Third, some problems are hard only in the worst case situation, but
easy most of the time.
• Depending on the application, you may be satisfied with a
procedure that occasionally is slow but usually runs quickly.
• Finally, you may consider alternative types of computation, such as
randomized computation, that can speed up certain tasks.
25
COMPLEXITY THEORY
27
COMPUTABILITY THEORY
28
AUTOMATA THEORY
29
Languages
• Language: a set of strings
• Example:
• Strings: cat, dog, house
• Language: {cat, dog, house}
PRIMES = {2,3,5,7,11,13,17, }
EVEN = { 0,2,4,6, }
32
Decimal numbers alphabet = { 0,1,2, ,9}
102345 567463386
34
String Operations
w = a1a2 an abba
v = b1b2 bm bbbaaa
Concatenation
w = a1a2 an ababaaabbb
Reverse
w = an a2 a1
R
bbbaaababa
36
String Length
w = a1a2 an
• Length: w =n
• Examples: abba = 4
aa = 2
a =1
37
Length of Concatenation
uv = u + v
• Example: u = aab, u = 3
v = abaab, v = 5
uv = aababaab = 8
uv = u + v = 3 + 5 = 8
38
Empty String
• Observations: =0
w = w = w
39
Substring
• Substring of string:
• a subsequence of consecutive characters
• String Substring
abbab ab
abbab abba
abbab b
abbab bbab
40
Prefix and Suffix
abbab
• Prefixes Suffixes
abbab w = uv
a bbab
prefix
ab bab
suffix
abb ab
abba b
abbab
41
Another Operation
w = ww
n
w
n
• Definition: w =0
(abba ) = 0
42
The * Operation
= a, b
* = , a, b, aa, ab, ba, bb, aaa, aab,
43
The + Operation
+ : the set of all possible strings from
alphabet except
= a, b
* = , a, b, aa, ab, ba, bb, aaa, aab,
+
= * −
+
= a, b, aa, ab, ba, bb, aaa, aab,
44
Languages
Alphabet = {a , b }
• An infinite language L = {a b : n 0}
n n
ab abb L
L
aabb
aaaaabbbbb
46
Prime numbers
PRIMES = {2,3,5,7,11,13,17,}
47
Even and odd numbers
EVEN = { 0,2,4,6, }
ODD = {1,3,5,7, }
48
Unary Addition
Alphabet: = {1,+, =}
Language:
ADDITION = {x + y = z : x = 1 , y = 1 , z = 1 ,
n m k
n+m =k}
Alphabet: = {1, # }
Language:
SQUARES = {x # y : x = 1 , y = 1 , m = n }
n m 2
11#1111 SQUARES
111#1111 SQUARES
50
Note that:
Sets = { } {}
Set size {} = = 0
• Complement: L = * −L
• Definition: LR = {w R : w L}
L = {a b : n 0}
n n
LR = {b n a n : n 0}
53
Concatenation
54
Another Operation
• Definition: Ln =
LL L
n
0
a , bba , aaa =
55
Another Operation
L = {a b : n 0}
n n
L = {a b a b : n, m 0}
2 n n m m
aabbaaabbb L 2
56
Star-Closure (Kleene *)
• Definition: L = L L
+ 1 2
a, bb,
+
a, bb = aa, abb, bba, bbbb,
aaa, aabb, abba, abbbb,
58
Important Links:
• In The following links you can find an explanation for the entire
chapter:
▪ https://youtu.be/VpGe7c8EIT0
▪ https://youtu.be/nJWpANAClcI
▪ https://youtu.be/hh3qftQA6Ew
59
وصلّى اهلل وبارك على نبيّنا محمد
mskhayat@uqu.edu.sa
60