Chapter 1 Introduction To The Theory of Computation
Chapter 1 Introduction To The Theory of Computation
3
Representations of sets
There are two methods to represent a set.
1. Roster method (Tabular form): a set is represented by listing all its elements,
separating by commas and enclosing in curly bracket.
If
V be the set of vowels, it can be written as: V = { a, e, i, o, u}
If A be
the set of natural numbers less than 7.
Note : To write a set in Roster form elements are not to be repeated i.e. all elements
are taken as distinct. For example if A be the set of letters used in the word
4
Representations of sets
2. Set-builder form
In this form elements of the set are not listed but these are represented by some common property.
(i). Let V be the set of vowels of English alphabet then V can be written in the set builder form as: V =
5
set operations
The set operations are operations done on sets.
Union
The “union” of two sets is the set that has objects that are elements of at least one of
the two given sets, and possibly both.
That is, the union of sets A and B, written A ∪ B, is a set that contains everything in
A, or in B, or in both.
A∪B={x: x ∈ A or x ∈ B }
Example: A = {1, 3, 9} B = {3, 5}
Therefore, A ∪ B={1,3,5,9}
6
Intersection
The “intersection” of sets A and B, written A ∩ B,
is a set that contains exactly those elements that
are in both A and B.
A ∩ B = {x : x ∈ A and x ∈ B}
Example1:
Given A={1, 3, 9}, B = {3, 5}, C = {a, b, c}
A ∩ B = {3} Example 2. Consider the sets A =
{♣,♠} and B = {♣, ♦}. Then,
A∩C={} • A ∪ B = {♣, ♠, ♦};
7 • A ∪ A = A ∪ ∅ = {♣, ♠}.
Set Difference
The “set difference” of set A and set B, written as A–B, is
the set that contains everything that is in A but not in B.
A −B = {x : x ∈ A and x ∉ B}
Given A = {1 , 3 , 9} , B = {3 , 5}
A − B = {1 , 9 } .
8
Complement
The complement of a set, denoted A', is the set of all
elements in the given universal set U that are not in A.
In set- builder notation, A' = {x: x ∈ U : x ∉ A}.
Example:
Let U = {1, 2, 3, 4, 5, 6} and A = {1, 3, 5}.
Then A' = {2, 4, 6}.
U' = ∅ The complement of the universe is the empty set.
∅' = U The complement of an empty set is the universal set.
10
Example 1 :
Given, A = {1, 2, 3, 4, 5}, B = {3, 4, 5, 6} and C = {5, 6, 7, 8},
show that
(i) A U (B U C) = (A U B) U C. (ii) Verify (i) using Venn
diagram.
Solution :
Now, B U C = {3, 4, 5, 6} U {5, 6, 7, 8} = {3, 4, 5, 6, 7, 8}
= A U (B U C) = {1, 2, 3, 4, 5} U { 3, 4, 5, 6, 7, 8}
= {1, 2, 3, 4, 5, 6, 7, 8} ----- (1)
Now, (A U B) = {1, 2, 3, 4, 5} U {3, 4, 5, 6} = {1,2,3,4,5,6}
(A U B) U C = {1,2,3,4,5,6} U {5,6,7,8}
= {1, 2, 3, 4, 5, 6, 7, 8} ----- (2)
= (1) = (2)
11
Using venn diagram
12
Example 2 :
Let A = {a,b,c,d}, B = {a,c,e} and C = {a,e}.
(i) Show that A n (B n C) = (A n B) n C.
(ii)(ii) Verify (i) using Venn diagram
Solution :
Now, B n C = {a,c,e} n {a, e} = {a, e}
A n (B n C) = {a, b, c ,d} U {a, e}
= { a } ----- (1)
(A n B) = {a,b,c,d} n {a,c,e}
= {a, c}
(A n B) n C = {a, c} n {a,e}
= {a} ----- (2)
(1) = (2)
13
Example 3:
Use the Venn diagram to answer the following
questions
(i) List the elements of U, E', F', (E U F)' and (E n F)'
14
i. To find the elements of universal set U, we have to list out all the
elements that we find in the rectangular box.
U = {1, 2, 3, 4, 7, 9, 10, 11}
ii. To find the elements of the set E', we have to list out all the
elements other than the circle E.
E' = {3, 9, 10, 11 }
iii. To find the elements of the set F', we have to list out all the
elements other than the circle F.
F' = { 1, 2, 3, 4, 7, 10 }
iv. To find the elements of the set (E U F)', first we have to find the
elements of the set E U F
E U F = {1, 2, 4, 7, 9, 11}
(E U F)' = {3, 10}
v. To find the elements of the set (E n F)', first we have to find the
elements of the set E n F
E n F = {4, 7}
(E n F)' = {1, 2, 3, 9, 10, 11}
15
Properties of set operations
4. Distributive Laws: A U (B ∩ C) = (A U B) ∩ (A U C)
A ∩ (B U C) = (A ∩ B) U (A ∩ C)
Thus, union and intersection are distributive over
intersection and union respectively.
5. De Morgan’s Laws: A – (B U C) = (A – B) ∩ (A – C)
A - (B ∩ C) = (A – B) U (A – C)
De Morgan’s Laws can also we written as:
(A U B)’ = A' ∩ B’
containing 2n elements.
17
Con…
denoted by A x B , i.e.
A x B = {(x , y) : x ∈ A and y ∈ B}
18
Examples
1: Given A = {1, 2, 3} determine P(A) (powerset of A).
As the set A = {1, 2, 3} has 3 elements the powerset P(A) will have 2 3 = 8 elements.
AxB={(1,a),(1,b),(2,a),(2,b)}
3. Given A= {1,2}, B = {x, y, z} and C = {3, 4}, find A × B × C and
n (A × B × C ) .
19
Relations and Functions
Relation: A relation on sets S and T is a set of ordered pairs (s, t), where
(a) s∈ S (s is a member of S )
(b) t ∈T (t is a member of T )
(d) The set of all first elements is the domain of the relation,
(e) The set of all second elements is the range of the relation.
20
21
Equivalence Relation
A subset R of AxA is called an equivalence relation on
A if R satisfies the following conditions:
i (a, a ) ∈ R for all a ∈ A (R is reflexive)
ii If (a, b ) ∈ R, and (b, a ) ∈ R, then
(R is symmetric)
iii If (a, b ) ∈ R and (b, c) ∈ R, then
(a, c) ∈ R (R is transitive)
Example:
Given the relation R in A as
R = {(1,1), (2,2), (2,3), (3,2), (4,2), (4,4)}
(a) Is R (i) reflexive (ii) symmetric (iii) transitive?
No why ?
22
Functions as relations
A function f : A → B is a function from A to B i.e., a subset of A
b) in f.
Kinds of Functions
One-to-One Function (Injection):
A function f: A →B is said to be one-to-one if different elements
in the domain A have distinct images in the range.
23
Onto function (Surjection):
A function f : A→B is said to be an onto function if each
24
One-to-one onto Function (Bijection):
A function that is both one-to-one and onto is called a “Bijection”.
Such a function maps each and every element of A to exactly one element of
25
Examples
.
26
Boolean logic
Boolean logic is a system built with two values TRUE and FALSE.
“Boolean values” are represented by values 0 and 1.
There are many Boolean operations.
Negation: It means the NOT operation, represents by ¬. Example: ¬ 0 =1 and ¬1= 0.
Conjunction: It means the AND operation, represented by ∧.
Disjunction: It means the OR operation, represented by ∨
27
Boolean logic
Equality: The equality operation, written with the symbol ↔, is 1 if both its operands have the
same value.
Implication: This operation is designated by the symbol → and is 0 if its first operand is 1 and
denoted by ⊕.
28
Fundamental Proof Techniques
A proof is a sequence of steps that begins from some known facts
to reach the desired conclusions; Each step must be obviously
correct.
Techniques
Proof by contradiction
To prove some fact p, we show ‘not p’ is false.
Proof by Induction
We show that some fact is true for every natural number n, using
two arguments.
Base
Step
Pigeon hole principle
29
Principle of Mathematical Induction
30
Examples Mathematical induction
Let Pn be a proposition that depends on n Z+.
i. Pi is true
Three steps:
31
Solution:
Let Pn: 1+2+…+n = n(n+1)/2
Step1: for n = 1, P1 holds true
Step2: for some k Z+, assume Pk is true
i.e. Pk: 1+2+…+k = k(k+1)/2
Pk
Step3: WTS Pk+1 is true
Pk+1 : 1+2+…+k+(k+1) = (k+1)(k+2)/2
: Pk + (k+1) = (k+1)(k+2)/2
: k(k+1)/2 + (k+1) = (k+1)(k+2)/2
: [k(k+1) + 2(k+1)]/2 = (k+1)(k+2)/2
: (k+1)(k+2)/2 = (k+1)(k+2)/2
Therefore, Pn holds true for all nZ+
Ex.32Show that Pn = (i=1,n), i2 = (n)(n+1)(2n+1)/6 for all n
(b) Pigeon-hole Principle
If A and B are finite sets and |A| > |B|, then there is no one-to-
one function from A to B. i.e., If an attempt is made to pair off
the elements of A (the “pigeons”) with elements of B (the
“pigeonholes”), sooner or later we will have to put more than
one pigeon in a pigeonhole.
By induction, the pigeonhole principle can be proved.
33
Graphs and trees
A graph, is a collection of points connected by lines.
The points are called nodes or vertices, and the lines are
called edges
34
Graphs and trees: cont’d
A directed graph has arrows instead of lines, as shown in the
following figure.
The number of arrows pointing from a particular node is the out
degree of that node, and the number of arrows pointing to a
particular node is the in degree.
35
Graphs and trees: cont’d
The degree of a vertex v in a graph (directed or undirected) is the
number of edges with v as an end vertex.
A path may be directed (if all the edges in the path have the same
direction.)
36
Trees
A graph (directed or undirected) is called a tree if it is connected
and has no circuits.
Q. Are the previous two graphs trees?
Properties of trees:
In a tree there is one and only one path between every pair of
vertices (nodes)
A tree with n vertices has n-1 edges
A leaf in a tree can be defined as a vertex of degree one
37 Vertices other than leaves are called internal vertices
Graphs and trees: cont’d
38
Class work
39
Automata theory
.
40
Automaton
.
41
Con…
.
English mathematician
44
Con…
.
45
Con…
Halting— means that the program on certain input will accept
it and halt or reject it and halt.
Basically halting means terminating.
47
THE CENTRAL CONCEPTS OF AUTOMATA THEORY
.
49
String operations
.
Length of String
50
String
.
51
Substring:
.
yn .
“superscript” notation:
52
Substring:
.
strings over the alphabet {0, 1} is (∈, 0,1, 00, 01, 10, 11,
000, ...).
53
Summary
.
54
Language
.
denoted as Σ*.
Infinite languages L are denoted as: L={w∈ Σ*: has property P}
Examples:
a) L1 = {w ∈{0,1}* : has an equal number of 0's and 1's}
b) L2 = {w∈ Σ* : w= wR } where wR is the reverse string of w.
55
Language
.
strings from L.
57
Example
.
(b) Given L = {anbn : n ≥0 } , check if the strings aabb, aaaabbbb, abb are in the language L.
(i) aa bb → a string in L. (n = 2)
58
Summary
.
59
Grammars
.
60
Grammars
.
The set of all strings obtained by using production rules is the Language generated by
the Grammar.
If the grammar G = (V, T, S, P) then
L(G ) = {w∈T* :S w}
The string S, w1, w2, wn which contain variables as well as terminals, are called
61
.
Grammars
Example: Given a Grammar
G = ({S } , {a ,b}, S , P) with P defined as
S →aSb,
S→λ
62
.
Grammars
Applying the production rule S → aSb , we get
ai S bi ⇒ ai+1 S bi+1
This is true for all i.
In order to get a sentence we apply S → λ.
Therefore we get S an S bn ⇒an bn
There fore L(G) = {anbn ;n ≥ 0 }.
63
.
Grammars
64
Summary
.
65
Practical Examples
.
On/Off switch
action
state
66
Structural expressions
.
Grammars
Regular expressions
E.g. Unix style to capture city names such as “Palo Alto CA”:
[A-Z][a-z]*([ ][A-Z][a-z]*)*[ ][A-Z][A-Z]
67
Some Applications
.
68
Exercise
Given
L1={ab,bc,ca}, L2={aa,ac,cb} determine
a. L1L2
b. L1
c. L1- L2
d. L1L2
69
.
Questions ?
70