Theory of Computation Welcome to a journey to Lecture1: Introduction Cairo University FCI Dr. Hussien Sharaf Computer Science Department [email protected]
Theory of Computation
Welcome to a journey to
Lecture1: Introduction
Cairo UniversityFCI
Dr. Hussien SharafComputer Science [email protected]
Part oneIntroduction
Dr. Hussien M. Sharaf
What is TC and how old?TC is an accumulation of mathematicians
work to make a model for a machine that can do thinking and calculations.
The concept of a machine at early 1900 was a device that does physical work.
Scientists effort started with a machine that can do specific calculations like encrypting text using specific set of steps.
Alan Turing believed he could invent a generic machine that can solve more than one type of problems.
Dr. Hussien M. Sharaf
Let s hear a StoryIt started before World War II, Germans
army used Enigma encryption.Alan Turing and many mathematicians
tried to break the Enigma encryption.Their efforts resulted in emergence of a
mechanical device that was dedicated for deciphering Enigma encrypted messages.
As a result many German submarines were attacked and destroyed.
Dr. Hussien M. Sharaf
Enigma machine
Dr. Hussien M. Sharaf
Enigma wiring
Dr. Hussien M. Sharaf
Back to TCVon Newman, Alan Turing and many
others continued working on creating a model for a generic machine that can solve different types of problems.
The accumulation of their work resulted in emergence of a collection of theorems called theory of computation.
Dr. Hussien M. Sharaf
What is TC?TC emerged to give answers for
“What are the fundamental capabilities and limitations of computing machines?”
Most powerful and modern super computers can NOT solve some problems!!
No matter how much processors get fast , no matter how much memory can be installed; the unsolved problems remain unsolved!
We might need life time of the universe to find prime factors of a 500-digits number!
Dr. Hussien M. Sharaf
Why we still need TC?Technologies become obsolete but basic
theories remain forever.TC provides tools for solving computational
problems like regular expressions for string parsing and pattern matching.
Studying different types of grammars like CFG would help in many other areas like compilers design and natural language processing.
Dr. Hussien M. Sharaf
Branches of TC
Dr. Hussien M. Sharaf
Branches of TCTC consists of:1. Automata theory: mathematical
models for computational problems such as pattern recognition and other problems.
2. Computability theory: computational models and algorithms for general purpose.
3. Complexity theory: classifying problems according to their difficulty.
Dr. Hussien M. Sharaf
Part twoMathematical notations and
Terminology
Dr. Hussien M. Sharaf
Sets-[1]A set is a group of elements
represented as a unit.For example
S ={a, b, c} a set of 3 elements
Elements included in curly brackets { }a S a belongs to S
f S f does NOT belong to S
Dr. Hussien M. Sharaf
Sets-[2]If S ={a, b, c} and
T = {a, b}Then
T ST is a subset of S
T S ={a, b}T intersects S ={a,
b}
T S ={a, b, c}T Union S ={a, b, c}
Venn diagram for S and T
Dr. Hussien M. Sharaf
Sequences and TuplesA sequence is a list of elements in some order.
(2, 4, 6, 8, ….) parentheses A finite sequence of K-elements is called k-
tuple.(2, 4) 2-tuple or pair(2, 4, 6) 3-tuple
A Cartesian product of S and P (S x P)is a set of 2-tuples/pairs (i, j)where i S and j P
Dr. Hussien M. Sharaf
Example for Cartesian ProductExample (1)If N ={1,2,…} set of integers; O ={+, -}
N x O ={(1,+), (1,-), (2,+), (2,-), …..}Meaningless?Example (2)
N x O x N={(1,+,1), (1,-,1), (2,+,1), (2,-,2), …..}
Does this make sense?
Dr. Hussien M. Sharaf
Continue Cartesian ProductExample (3)If A ={a, b,…, z} set of English alphabets;
A x A ={(a, a), (a, b), ..,(d, g), (d, h), …(z, z)}
These are all pairs of set A.Example (4)If U={0,1,2,3…,9} set of digits then U x U
x U ={(1,1,1), (1,1,2),...,(7,4,1), ….., (9,9,9)}
Dr. Hussien M. Sharaf
Example (5)If U={0, 1, 2, 3…, 9} set of digits then U x… x U ={(1,..,1), (1,..,2),...,(7,..,1), ...,
(9,..,9)}
Continue Cartesian Product
nCan be written as Un
Dr. Hussien M. Sharaf
Relations and functionsA relation is more general than a function.Both maps a set of elements called
domain to another set called co-domain.In case of functions the co-domain can be
called range.R : D CA relation has no restrictions.f : D RA function can not map one element to
two differnet elements in the range.
Dr. Hussien M. Sharaf
Surjective function
t1
T
t3
t2
P1
P2
Pn
P4
P3
s1
s3
s2t1
t3
t2
S T
Bijective function
Many planes fly at the same time
Only one plane lands on one runway at a time
Dr. Hussien M. Sharaf
What is the use of functions in TC?Helps to describe the
transition function that transfer the computing device from one state to another.
Any computing device must have clear states.
s1
s3
s2
Ds2
shalt
s3
R
Dr. Hussien M. Sharaf
GraphsIs a visual
representation of a set and a relation of this set over itself.
G = (V, E)V ={1, 2, 3, 4, 5}E = {(i, j) and (j, i)| i, j
belongs to V}E is a set of pairs ={(1,
3), (3, 1) …(5, 4), (4, 5)}
1
35
2 4
Dr. Hussien M. Sharaf
Graphs ConstructIs there a formal language
to describe a graph?G =(V, E)Where :V is a set of n vertices
={i| i < n-1}E is a set of edges. Each
edge is a pair of elements in V={(i, j), (j, i)|i, j V}
or={(i, j) |i, j V }
1
35
2 4
Dr. Hussien M. Sharaf
Definitions (S Alphabet) : a finite set of letters,
denoted SLetter: an element of an alphabet SWord: a finite sequence of letters from
the alphabet SL (empty string): a word without
letters.Language S * (Kleene ‘s Star): the set
of all words on SDr. Hussien M. Sharaf
Strings and languagesA string w1 over an alphabet Σ is a finite
sequence of symbols from that alphabet.1. Σ: is a set of symbols i.e. {a, b, c, …, z} English letters;{0,1, 2,…,9,.} digits of Arabic numbers{AM, PM}different clocking system{1, 2, …, 12}hours of a clock;
Dr. Hussien M. Sharaf
Strings -22.1 String: is a sequence of Σ (sigma) symbols
Σ Σ to the power?
Example Description
{a, b, c, …, z}
Σ5 apple English
string
{0,1, 2,…,9,.}
Σ2 35 the oldest
age for girls
{AM, PM} Σ1 PM clocking
system
{1, 2, …, 12}
Σ1 or Σ
2 12 a specific hour in the day
Dr. Hussien M. Sharaf
Strings - 32.2 Empty String is Λ (Lamda) is of
length zero
Σ0 = Λ
2.3 Reverse(xyz) =zyx2.4 Palindrome is a string whose
reverse is identical to itself.If Σ = {a, b} thenPALINDROME ={Λ and all strings x such thatreverse(x) = x }radar, level, reviver, racecar,madam, pop and noon.Dr. Hussien M. Sharaf
Strings - 42.5 Kleene star * or Kleene closureis similar to cross product of a set/string over itself.
If Σ = {x}, then Σ* = {Λ x xx xxx ….}
If Σ = {x}, then Σ+ = {x xx xxx ….}
If S = {w1 , w2 , w3 } then
S* ={Λ, w1 , w2 , w3 , w1w1 , w1w2 , w1w3 , ….}
S+ ={w1 , w2 , w3 , w1w1 , w1w2 , w1w3 , ….}
Note1: if w3 =Λ, then Λ S+
Note2: S* = S
**
Dr. Hussien M. Sharaf
Part ThreeExercises
Dr. Hussien M. Sharaf
Exercise 1 Assume Σ={0, 1}1. How many elements are there in Σ2?Length(Σ) X Length(Σ) = 2 X 2 = 23 =42. How many combinations of in Σ3?2 X 2 X 2 = 23 3. How many elements are there in Σn?(Length(Σ))n= 2n
Dr. Hussien M. Sharaf
Exercise 2 Assume A1={AM, PM}, A2 = {1, 2, …59}, A3 = {1, 2, …12}1. How many elements are there in A1 A3?Length(A1) X Length(A3) = 2 X 12 =24
2. How many elements are there in A1 A2 A3)?
Length(A1) X Length(A3) = 2 X 59 X 12 = 1416
Dr. Hussien M. Sharaf
Exercise 3 Assume L1={Add, Subtract},
DecimalDigits = {0,1, 2, …9} 1. Construct integer numbers out of L2.DecimalDigits +
-A number of any length of digits.2. Construct a language for assembly
commands from L1 and DecimalDigits .L1 DecimalDigits + {,} DecimalDigits + - Commands in form of Add 1000, 555
Dr. Hussien M. Sharaf
Exercise 4 Assume HexaDecimal = {0,1, …9,A,B,C,D,E,F}1. How many HexaDecimals of length 4?
164 2. How many HexaDecimals of length n?
16n 3. How many elements are there in
{0, 1}8 ?28 = 256
Dr. Hussien M. Sharaf
End of Lecture 1
Dr. Hussien M. Sharaf