Professional Documents
Culture Documents
Lecture 1
Lecture 1
Lecture 1
THEORY OF COMPUTING 1
1
Theory of Computing
(CPS422)
09/01/2022
THEORY OF COMPUTING 2
2 Jabbi
Preview
Review
Mathematical Notions and Terminology
Alphabet, Strings & Languages
THEORY OF COMPUTING 6
6 Jabbi
Preview
Sets
Functions
Relations
Graphs
Proof Techniques
oC = { a, b, c, d, e, f, g, h, i, j, k }
finite set
oC = { a, b, …, k }
infinite set
oS = { 2, 4, 6, … }
oUnion
X Y = {z | z X or z Y} = {1,2,3,4}
oIntersection
X Y = {z | z X and z Y} = {2}
oDifference
X - Y = {z | z X and z Y} = {1,3}
09/01/2022 THEORY OF COMPUTING 11
Sets
Set Operations
oComplement
Let X be a subset of Y
The complement of X ( X ) with respect to Y is the set of elements in Y but not in X
X = { z | z Y and z X } = Y - X
oAssume X = {1,2,3} is a subset of Y = {1,2,3,4}
o X = {4}
DeMorgan’s Laws
o (X Y) = X Y
o (X Y) = X Y
o|A| = 3
(set size)
A X B = { (2, 2), (2, 3), (2, 5), ( 4, 2), (4, 3), (4, 5) }
|A X B| = |A| |B|
xi R yi to denote (a,b) R
•Proof by induction
• Proof by contradiction
•Construction
•Contradiction
•If-And-Only-If Proofs
• 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
L(k) <= 2k
Proof:
Assume by contradiction that it is rational
2 = n/m
n and m have no common factors
We will show that this is impossible
n is even
Therefore, n is even
2
n=2k
m is even
2 m2 = 4k2 m2 = 2k2
m=2p
Remember:
oThe if and only-if parts are converses of each other
One part, say “if X then Y” says nothing about whether Y is true when
X is false.
An equivalent form to “if X then Y” is “if not Y then not X”; the latter
is the contra-positive of the former.
09/01/2022 THEORY OF COMPUTING 34
Alphabet, Strings & Languages
THEORY OF COMPUTING 35
35 Jabbi
Alphabet, Strings & Languages
A SYMBOL is an abstract entity.
oLetters (a-z) and digits (0-9) are examples of frequently used symbols.
Alphabet: Finite, nonempty set of symbols
oExamples:
1 = {0, 1}: binary alphabet
2 = {a, b, c, …, z}: the set of all lower case letters
3 = {0, 1, x , y , z }.
The set of all ASCII characters
Reverse : wR
o If w = abc, wR = cba
09/01/2022 THEORY OF COMPUTING 37
Strings and Languages
Substring: any string of consecutive characters in some string w
◦ If w = abc
◦ e, a, ab, abc, c, bc are substrings of w
THEORY OF COMPUTING 38
Strings and Languages
THEORY OF COMPUTING 39
Alphabet, Strings & Languages
Concatenation: if x and y are strings, then xy is the string obtained by placing a copy of y
immediately after a copy of x
o x = a1a2 …ai,
o y = b1b2 …bj
o xy = a1a2 …aib1b2 …bj
o Example:
x = 01101,
y = 110,
xy = 01101110
Note that |xy | = |x | + |y |. Hence the length of the concatenation of two strings is the sum of their
individual lengths.
The empty string is the identity for the concatenation operator. That is:
◦ w = w = w.
09/01/2022 THEORY OF COMPUTING 40
Alphabet, Strings & Languages
Concatenation:
oLet x be a string. We let xk denote the concatenation of x with itself k times.
◦ 010113 = 010110101101011
◦ 5 =
◦ 110 = 1111111111
◦ Abc4 = abcabcabcabc.
oNote that |xk| = k |x |.
Let Σ be an alphabet. Then Σk is the set of all strings of length k over the alphabet Σ.
If Σ = {a, b, c , . . . , z } then Σ7 is the set of all possible strings of length 7, one can make out
of these characters. There are 267 of them. That is a lot of strings!
S = {a, b}
S* = ?
THEORY OF COMPUTING 44 44
The + Operation
+ the set of all possible strings from alphabet except e
S+ = S1 S2 S3 …
S = {a, b}
S* = S+ {e}
S+ = S* - {e}
S+ = ?
09/01/2022 THEORY OF COMPUTING 45
Strings and Languages
Language: set of strings chosen from some alphabet
A language is a subset of *
◦ Example of languages:
◦ The set of valid Arabic words
◦ The set of strings consisting of n 0’s followed by n 1’s
◦ {e, 01, 0011, 000111, …}
◦ The set of strings with equal number of 0’s and 1’s
◦ {e, 01, 10, 0011, 0101, 1010, 1001, 1100, …}
Empty language: = { }
The language {e} consisting of the empty string
Note: {e}
THEORY OF COMPUTING 46
Strings and Languages
We Can concatenate languages
◦ L1L2 = {xy | x L1, y L2}
◦ Ln = L concatenated with itself n times
◦ L0 = {e}; L1 = L
Star-closure
◦ L* = L0 L1 L2 ...
◦ L+ = L* - L0
Positive-closure
◦ L+ = L* - L0
Languages can be finite or infinite
◦ L = {a, aba, bba}
◦ L = {an | n > 0}
THEORY OF COMPUTING 47
Strings and Languages
OPERATION DEFINITION
union of L and M L M = {s | s is in L or s is in M}
written L M
concatenation of L LM = {st | s is in L and t is in M}
and M written LM
Kleene closure of L L* = Li , i=0,..,
written L*
L* denotes “zero or more concatenations of “ L
positive closure of L +
written L + L = L i
, i=1,..,
L+ denotes “one or more concatenations of “ L
L+ = LL*
THEORY OF COMPUTING 48
Strings and Languages
Summary L = {A, B, …, Z, a, b, …z} D = {1, 2, …, 9}
L D = the set of letters and digits
LD = all strings consisting of a letter followed by a digit
L2 = the set of all two-letter strings
L4 = L2 L2 = the set of all four-letter strings
L* = { All possible strings of L plus }, L+ = L* -
D+ = set of strings of one or more digits
L (L D ) = set of all strings consisting of a letter followed
by a letter or a digit
L (L D )* = set of all strings consisting of letters and
digits beginning with a letter
THEORY OF COMPUTING 49
Strings and Languages
Example:
The language L consists of strings over {a,b} in which each string begins with an a
should have an even length
◦ aa, ab L
◦ aaaa,aaab,aaba,aabb,abaa,abab,abba,abbb L
◦ baa L
◦ aL
THEORY OF COMPUTING 50
Strings and Languages
Example:
The language L consists of strings over {a,b} in which each occurring of b is
immediately preceded by an a
◦eL
◦aL
◦ abaab L
◦ bb L
◦ bab L
◦ abb L
THEORY OF COMPUTING 51
Strings and Languages
Example:
THEORY OF COMPUTING 52
Strings and Languages
Example:
The language L = {a,b}*{bb}{a,b}* = *{bb}*
◦ consists of the strings over {a,b} that contain the substring bb
◦ bb L
◦ abb L
◦ bbb L
◦ aabb L
◦ bbaaa L
◦ bbabba L
◦ abab L
◦ bab L
◦bL
THEORY OF COMPUTING 53
Strings and Languages
Let L be the language that consists of all strings that begin
with aa or end with bb
◦ L1 = {aa}{a,b}*
◦ L2 = {a,b}*{bb}
◦ L = L1 L2 = {aa}{a,b}* {a,b}*{bb}
◦ bb L
◦ abb L
◦ bbb L
◦ aabb L
◦ bbaaa L
◦ bbabba L
◦ abab L
◦ bab L
◦ ba L
THEORY OF COMPUTING 54
Strings and Languages
Example:
The languages L1* and L2* both contain precisely the strings consisting of an even
number of b’s.
THEORY OF COMPUTING 55
Strings and Languages
??????
What is the language of all even-length strings over {a,b}
◦ L = {aa, bb, ab, ba}* = (aa|bb|ab|ba)*
THEORY OF COMPUTING 56
Any Question?