CH 1
CH 1
CH 1
Example 1
The set of positive integers less than 100 can be denoted as { 1,2,3 , .. . , 99 } .
Example 2
A set can also consists of seemingly unrelated elements:{ a, 2 ,Fred,NewJersey } .
Definition 2. Two sets are equal if and only if they have the
same elements.
Example 3
Set { 1,3,3,3,5,5,5,5 } is the same as set { 1,3,5 } .
• A set can be described by using a set builder notation.
Example 3
O= { x | x is an odd positive integer less than 10 }
Example 4
N= { x|natural numbers }= { 1,2,3,. . . }
Z= { x| integers }= {. .. ,- 2 ,-1,0,1 ,. . . }
Z= { x|positive integers } ={ 1,2,3,. . . }
R= { x|real numbers }
• A set can be described by using a Venn diagram.
Example 5
Draw a Venn diagram that presents V, the set of vowels in English alphabet.
U
a,e,i,o,u
V
• The set that has no elements is called empty set, denoted by φ .
A ⊆ B if and only if ∀ x ( x ∈ A → x ∈ B)
For any set P , φ ⊆ P and P ⊆ P .
If A ⊆ B and B ⊆ A , then A=B .
Example 6
{ φ, { a } , { b } , { a,b } }= { x|x is a subset of the set { a,b } } .
If a set A is a subset of set B but that A ≠B, A is called to be a proper subset of B,
denoted as A ⊂ B .
A B
Definition 4. The power set of a set S is the set of all subsets of S,
S
denoted by P(S) or 2 .
Example 7
What is the power set of the set S= { 0,1,2 } ?
Solution : P( { 0,1,2 } )(or 2 S )={ φ, { 0 } , { 1 } ,|{ 2 } , { 0,1 } , { 0,2 } , {1,2 } , { 0,1,2 } } .
• Set Operations:
C omp lement
U nion A ∪ B= { x |x ∈ A or x ∈ B }
Intersection A ∩ B= { x |x ∈ A and x ∈ B }
Example 9
Let A= { a,e,i,o,u } and the universal set is the set of the letters of the English
alphabet . Then A= { b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z } .
U
A
A
• Set Identities Revision
Table 1 Set Identities
Identity Name
A ∪φ=A
Identity laws
A ∩U=A
A ∪U=U
Domination laws
A ∩φ=φ
A ∪ A=A
A ∩ A=A Idempotent laws
Example 10
Let A= { 1,2 } and B= { a,b,c } .
A×B= { (1 ,a ),(1 ,b ),(1 ,c ),(2 ,a ),(2 ,b),(2 ,c ) }
B× A= {(a, 1 ), (a, 2),(b, 1),( b,2 ),(c, 1),(c, 2 ) }
A×B≠B× A
Functions and Relations
Definition 1. Let A and B be sets. A function f from A to B is an assignment of
exactly one element of B to each element of A. We write f(a)=b if b is the
unique element of B assigned by the function f to the element a of A. If f is a
function from A to B, we write f : A → B.
x x
y
z
A function Not a function
Example 1
Let set A={Adams, Chou, Goodfriend, Rodriguez, Stevens} and B={A,B,C,D,F}.
Let G be the function that assigns a grade to a student in our theory of
computation. G
Adames A
Chou B
The domain of G is the set A={Adams,
Goodfriend C Chou, Goodfriend, Rodriguez, Stevens},
Rodriguez D and the range of G is the set {A,B,C,F}.
Stevens F
• Considering the function whose domain and range are in the set of
integers. We are often interested only in the behavior of these
functions as their arguments become very large.
Definition2
Let f (n)and g( n) be functions whose domain is a subset of the positive integers .
(1) If there exists a positive constant c such that for all n
if |f (n)|≤ c|g (n )|, we say that f has order at most g , denoted as f (n)=O( g (n)),
if |f (n)|≥c|g( n)|, then f has order at least g , denoted as f (n )=Ω(g(n )
(2) If there exist constants c 1 and c 2 ,such that c1|g(n )|≤|f (n)|≤c 2|g(n)|, f and g
have the same order of magnitude, denoted as f (n)=Θ(g (n)).
Example 2
Example 6
Let I be the integer set and let R be a relation from I to I,
where ( x,y )∈ R if and only if x mod 3=y mod 3.
Then 2 R 5, 12 R 0, and 0 R 36 .
It is an equivalence relation, as it satisfies reflexity, symmetry,and transitivity .
Example 7
‘=’ on the set of integers is an equivalence relation.
Graphs and Trees
Definition 1
A graph is a construct consisting of two sets, denoted as G=(V,E),
where V= {v 1 ,v 2 ,. . .,v n } is a set of vertices and E= {e 1 ,e 2 ,. . . ,e m } is a set of edges .
Each edge is a pair from V .
Example 1 Example 2
v3 v3
e1 v2 e3 e1 v2 e3
e7 e7
v1 e1 v7 e8 v1 e4 e1 v7 e8
e4
0
v5 e5 e6 v8 0
v5 e5 e6 v8
v9 e2 v4 e9 v9 e2 v4 e9
Example 3
v3 walk: ( v1,v 2),(v 2,v 9),( v 9,v 7),( v 7,v 2),( v 2,v9)
e1 v2 e3
e7 path: (v 1,v2),(v 2,v 9),(v 9,v 7),(v 7,v 2)
v1 e1 v7 e8
e4 cycle: ( v 2,v9),( v 9,v7),( v7 ,v 2)
0
v5 e5 e6 v8 loop: ( v 3,v 3)
v9 e2 v4 e9
Definition 3
A tree is a directed graph that has no cycles. There is a one distinct
vertex in tree, called the root.
root
Level 0 v1
Level 1 v2 v4 v3 Parent of v6
Height=3
Level 2 v8 v5 v6 Child of v3
Level 3 v7 v9
A Proof Technique - Mathematical Induction
Definition 1
Mathematical induction is a method we use to prove a sequence of statements
P1 ,P 2 , .. . to be true .
(i) Basis: Proving that for some k=1 , P1 is true .
(ii ) Inductive Assumption: Supposing for any n ≥k, Pn is true .
(iii ) Inductive Step: Proving that P n+1 is true .
Example 1
A binary tree (no parent has more than two chidren ) of height n has at most 2 n leaves.
Proof: We use l(n ) to denote the maximum number of leaves in a binary tree of height n.
Basis: Clealy l (0 )=1=20 .
Inductive Assumption: l(i)≤2i , for i= 0,1 ,. . .,n .
Inductive Step: To get a binary tree of height n+1 from one of height n , we can create, at most,
two leaves in place of each previous one .
Therefore, l(n+1 )=2 l(n ).
Using the inductive assumption, we get l(n+ 1)≤2×l(n )=2n+1 .
Example 2
n
n( n+ 1)
Show that Sn = ∑ i= .
i= 0 2
Proof:
1
1(1+1)
Basis: S1 =∑ i=1=
i=0 2
n
n(n+1 )
Inductive Assumption: Assuming that Sn =∑ i= for all n≥1.
i= 0 2
n+1
n (n+1 ) ( n+1)( n+2 )
Inductive Step: Sn+1 =∑ i =Sn +n+1= +n+ 1= .
i=0 2 2
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+ = Li, i=1,..,
L+ denotes “one or more concatenations of “ L
Example:
L = {dog, cat, fish}
L* = {, dog, cat, fish, dogdog,
dogcat, fishcatfish,
fishdogdogfishcat, …}
Summary Notes : Strings and Languages …
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
a letter or a digit
• L (L D )* = set of all strings consisting of letters and digits
beginning with a letter
Strings and Languages …
List 1 List 2
1 b bbb
2 babbb ba
3 ba a
4 bbbaa babbb
2
List 1 babbb
List 2 ba
Strings and Languages … Exercise
List 1 List 2
1 b bbb
2 babbb ba
3 ba a
4 bbbaa babbb
2 1
List 1 babbbb
List 2 babbb
Strings and Languages … Exercise
List 1 List 2
1 b bbb
2 babbb ba
3 ba a
4 bbbaa babbb
2 1 1
List 1 babbbbb
List 2 babbbbbb
Strings and Languages … Exercise
List 1 List 2
1 b bbb
2 babbb ba
3 ba a
4 bbbaa babbb
2 1 1 3
List 1 babbbbbba
List 2 babbbbbba
Strings and Languages … Exercise
List 1 List 2
1 11 011
2 01 0
3 001 110
Concatenation and Reverse of Languages
Proof:
x (y ((xy)R = yRxR)) Theorem 2.1
L Language
Grammar Accepts
Transducer Machine
Automata
Automata
• An automaton is an abstract model of a digital computer.
Current configuration
Input file
… ( current state, input and storage )
...
MOVE
Control unit ( using Transition function)
Next configuration
...
Interactive games as nondeterministic FSMs.
Programming languages, compilers, and context-free grammars.
Natural languages are mostly context-free. Speech understanding
systems use probabilistic FSMs.
Computational biology: DNA and proteins are strings.
The undecidability of a simple security model.
Artificial intelligence: the undecidability of first-order logic.
Applications ...
• Compiler design
• Pattern matching
• Example:
Applications ...
Example:
• In this grammar, the variables are id , letter , digit , undrscr ,
and rest .
• The letters, digits, and the underscore are terminals.
• A derivation of a0 is:
id ⇒(letter)(rest)
⇒ a(rest)
⇒ a(digit)(rest)
⇒ a0(rest)
⇒ a0.
Applications ...
• Example: Automata
a
1 2
An automaton can be represented by a graph in which the
vertices give the internal states and the edges transitions.
The labels on the edges show what happens (in terms of input
and output) during the transition.