TOC
TOC
Topics
Formal languages
automata
computability and related matters
Purposes
To know the foundations and principles of computer science
To learn the material that is useful in subsequent course
Prerequisites
Fundamentals of data structures and algorithms
Discrete mathematics that includes set, functions, relations,
logic, and mathematical reasoning
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}.
Set Operations:
A B {x | x A or x B}
Intersection A B {x | x A and x B}
Difference A B {x | x A and x B}
Example 8
{1,3,5} {1,2,3} {1,2,3,5}.
{1,3,5} {1,2,3} {1,3}.
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
Set Identities
Table 1
Identity
A A
Set Identities
A U A
A U U
A
A A A
A A A
( A) A
A B B A
A B B A
A ( B C ) ( A B) C
A ( B C ) ( A B) C
A ( B C ) ( A B) ( A C )
A ( B C ) ( A B) ( A C )
A B A B
A B A B
Name
Identity laws
Domination laws
Idempotent laws
Complementation laws
Commutative laws
Associative laws
Distributive laws
De Morgans law
Cartisian product of A and B, denoted by A B, is the set of all ordered paris (a,b),
where a A and b B. Hence, A B {(a,b)| a A b B}.
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
z
A function
Not a function
Example 1
Chou
Goodfriend
Rodriguez
Stevens
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.
Definition 2
Let f(n) and g(n) be functions whosedomain is a subset of the positive integers.
(1) If there exists a positive constantc such thatfor all n
if |f(n)| c|g(n)|, wesay 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 constantsc1and c2 , such thatc1|g (n) || f (n) | c2 | g (n) |, f and g
have the same orderof magnitude, denoted as f(n) (g(n)).
Example 2
Let f (n) 2n 2 3n, g (n) n3 , h(n) 10n 2 100
Then f(n) O(g(n)), g(n) (h(n)), f(n) (n)
Definition 3
Let A and B be the sets. A relation R from A to B is a subset of A B .
From the definition , relation R is a set of pairs.
If (a, b) R, we say a has a relation R with b, denoted as aRb.
Definition 4
R is an equivalence relation if for any pair (x,y) of R
(reflexivity)
(symmetry)
(transitivity)
We usually use
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 R5, 12 R 0, and 0 R36.
It is an equivalence relation, as it satisfies reflexity, symmetry,and transitivity.
Example 7
Definition 4
R is an equivalence relation if for any pair (x,y) of R
(reflexivity)
(symmetry)
(transitivity)
We usually use
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 R5, 12 R 0, and 0 R36.
It is an equivalence relation, as it satisfies reflexity, symmetry,and transitivity.
Example 7
Example 2
Example 1
e1
v1 e4
v2 e3
v7
e10
v5 e5
v3
e7
e1
e8
e6
v8
v9 e2 v4 e9
A directed graph
(digraph)
v1 e4
v2 e3
v7
e10
v5 e5
v3
e7
e8
e6
v8
v9 e2 v4 e9
An undirected graph
Definition 2
(1) A sequenceof edges (vi ,v j ),(vj ,vk ),...,(vm ,vn ) is a walk.
(2) The length of a walk is the total number of edges traversed
in going from the intial vertex to the final one.
(3) A walk with no repeated is said to be a path.
(4) A path is simple if no vertex is repeated.
(5) A walk from vi to itself with no repeated edges is called as a cycle with base vi .
(6) An edge from a vertex toitself is called a loop.
Example 3
e1
v1 e4
v2 e3
v7
e10
v5 e5
v3
e7
e8
e6
v8
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.
v1
Level 0
Level 1
Height=3
Level 2
Level 3
v2
root
v3 Parent of v6
v4
v8
v5
v7
v6
v9
Child of v3
Example 1
A binary tree (no parent has more then twochidren) of height n has at most 2n 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.
InductiveAssumption : l(i) 2i , for i 0,1,...,n.
InductiveStep : 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 ) 2l(n).
Using the inductive assumption, we get l(n 1 ) 2 l(n) 2 n 1 .
Example 2
n
Show that Sn i
i 0
n(n 1)
.
2
Proof :
1
Basis :
S1 i 1
i 0
1( 1 1 )
2
n
n 1
InductiveStep : S n 1 i S n n 1
i 0
n(n 1 )
for all n 1.
2
n(n 1 )
(n 1)(n 2)
n 1
.
2
2