Beruflich Dokumente
Kultur Dokumente
LABORATORY MANUAL
in
Theory of Computation
Preface
This laboratory manual includes a collection of experiments and exercises
suitable for learning the topics contained in Theory of Computation. It starts with a
discussion and application of Mathematical Notations and Terminologies, an essential
part to being introduced to the Computational Theory.
The concepts discussed in this course focuses on Automata and Languages, as
well as, Computability Theory. Hence, most, if not all, experiments are directed towards
applying the theories of these concepts in various kinds of computing problems.
The manual intends to make learning Theory of Computation more meaningful.
Thus, a learners success in accomplishing the experiments and exercises in this
manual will lead to better results in the quizzes and examinations for this course.
Any error or modification in this manual may be reported to my email address so
that the material can be improved accordingly.
Table of Contents
Functions ..
Relations ...
TOPIC : SETS
The branch of mathematics that studies sets, which are collections of objects.
It is used in the definitions of nearly all mathematical objects.
Set theory deals with operations between, relations among, and statements
about sets.
x is a member of A is written xA
A member of a set is also known as its element
The basic binary relation between two sets is the subset relation, also called
set inclusion. Subset means every element of S is also an element of T.
Subset Principles
o A B if and only if whenever xA it follows that xB
o AB if and only if AB and AB
o For any set A, AU
o AA
o If AB and BA then A=B
o If AB and BC then AC
o ABA and AAB
Basic Set Operations
o Union - of the sets A and B, denoted , is the set whose members are
members of at least one of A or B.
o Intersection - of the sets A and B, denoted , is the set whose members
are members of both A and B.
o Complement - of set A relative to set U, denoted Ac, is the set of all
members of U that are not members of A. This is also known as set
difference.
o Symmetric Difference - of sets A and B is the set whose members are
members of exactly one of A and B.
EXPERIMENTS:
I. True or False?
_________1.
{a,a,b} {a,b}
_________2.
{c, a, b} = {c, b, a}
_________3.
{x,y,z} =
_________4.
{1,2,3,4} = {1,2,3}
_________5.
_________6.
{a,b,c,c,d} {a,b,c,d,e,f,g}
_________7.
{a,b,b} {a,b,c}
{2,3,5} {3,5,7}
__________2.
{a,b,c} {2,3}
__________3.
{a,b,c} {2,3}
__________4.
{2,4,6} {3,4,5}
__________5.
{1,2,3,4,5,6} {2,3,5,7,9,11}
__________6.
P({1,2})
Let A={a, b, {c, d}, e}. How many elements does A contain?
__________2.
5 is an element of A.
{5} is an element of A.
{4, 5} is an element of A.
{5} is a subset of A.
__________3.
{x | x is even}
{x | x < 5}
{1, 2, 3,...}
{1, 2, 3,...,999,1000}
__________4.
__________5.
__________6.
D
D
E
D
b) B
c) C
d) D
e) E
__________7.
Let S = {a, b}. How many elements does the power set 2S contain?
__________8.
Which set S does the power set 2S = { , {1}, {2}, {3}, {1, 2}, {1, 3},
{2, 3}, {1, 2, 3}} come from?
a) {{1},{2},{3}}
b) {1, 2, 3}
c) {{1, 2}, {2, 3}, {1, 3}}
d) {{1, 2, 3}}
__________9.
B = {v, w, x, y, z}
B = {v, w, y, z}
B = {v, w, x, y}
B = {x, w, x, y, z}
__________10. Let A = {1, 2, 3, ..., 8, 9} and B = {3, 5, 7, 9}. Which of the following
statements is correct?.
a) A
b) A
c) A
d) A
B = {2, 4, 6}
B = {1, 2, 3, 4, 5, 6, 7, 8, 9}
B = {1, 2, 4, 6, 8}
B = {2, 4, 6, 8}
__________11. Let C = {1, 2, 3, 4} and D = {1, 3, 5, 7, 9}. How many elements does
the set C D contain?
How many elements does the set C
D contain?
B, B
a) B D
b) A C
c) A = B
b) B D =
C and D
and B
A = {2, 4, 5, 3, 1, 6, 8}
B = {3, 5, 4, 7, 9, 12}
C = {4, 7, 10}
D = {11,14, 9, 7}
E = {1, 23, 25}
2.
In an interview of 50 students,
12 liked Proposition 8 and Proposition 13
18 liked Proposition 8, but not Proposition 5
4 like Proposition 8, Proposition 13 and Proposition 5
25 liked Proposition 8
15 liked Proposition 13
10 liked Proposition 5, but not Proposition 8 or Proposition 13
1 liked Proposition 13 and Proposition 5, but not Proposition 8
3.
TOPIC : FUNCTIONS
EXPERIMENT:
Answer the following:
1.
2.
3.
4.
5.
6.
7.
TOPIC : RELATIONS
EXPERIMENT:
1. What is the domain and range of the following relation?
{ (-1,2), (2, 51), (1, 3), (8, 22), (9, 51) }
2. The relation R is given by the set of ordered pairs, R = {(2, 4), (3, 4), (1,3),
(3, 5), (2, 3) }. Which of the following is the domain of R?
a) {2, 3, 1, 5}
b) {1, 2, 3}
c) {1, 2, 3, 4, 5}
d) {2, 4, 3, 5}
3. The relation R is given by the set of ordered pairs, R = {(2, 4), (3, 4), (1,3),
(3, 5), (2, 3) }. What should the range of R be?
a) {3, 4, 5}
b) {1, 2, 3}
c) {1, 2, 3, 4, 5}
d) {4, 4, 2, 5}
4. Find the inverse of the relation
R = {(2, 4), (3, 4), (1,3), (3, 5), (2, 3)}
a) {(2, 4), (3, 4), (1, 3), (3, 5), (2, 3)}
b) {(4, 2), (4, 3), (3, 1), (5, 3), (3, 2)}
c) {5, 4, 3, 2, 1}
d) {(4, 4), (3, 3), (1, 1), (5, 5), (2, 2)}
5. Two sets are given by E = {2, 4, 5, 6} and F = {1, 3, 6}. Let R be a relation
from set E to set F, which is defined by the open sentence "x is greater than
y". How many elements does the solution set of R contain?
6. Which relations below are functions?
Relation #1 { (3,4), (4,5), (6,7), (8,9) }
Relation #2 { (3,4), (4,5), (6,7), (3,9) }
Relation #3 { (-3,4), (4,-5), (0,0), (8,9) }
Relation #4 { (8, 11), (34,5), (6,17), (8,19) }
EXPERIMENT:
Create a Deterministic Finite Automata (DFA) for the following problems. State
the 5 Tuples of the DFA. Construct the Transition Diagram for the DFA as well.
Create DFAs accepting 0 and 1 as input and recognizes all strings that:
1. ends in a 1
2. have odd number of 1s
3. contain even number of 0s and any number of 1s
4. have a sequence 11 somewhere in the string
5. contain at least one 1 and an even number of 0s follow the last 1
6. contain even number of zeroes and even number of ones
7. that start and end with the same number (either 1 or 0).
8. starts with 101 and succeeded by any number of 1s and 0s
9. is preceded by any number of 1s and 0s but ends with 101
10. contain two consecutive 0s followed by two consecutive 1s.
EXPERIMENTS
Simplify the following Regular Expressions:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
(A + B + B) + + 1
N + M + K + N + M +
(AB) (B+B)
C(A+A+A+B)
C(A+A+A+)
( + D) + D
(L + M) + N
B + B + B +
C+C+D+D+
R + L
Z + Z + X
S + S + R
(B + B)C
(E + D + E + D)
(AB)C+C
D+C+B=?
BE = ?
DC = ?
AB = ?
AD = ?
B+B=?
(CD) B =?
(C + D) + (C + D) =?
D(C + B) = ?
E(A + B) = ?
9
Contest free grammars (CFGs) are formal notations for expressing recursive
definition of languages.
There is a finite set of symbols that form the strings of the language being
defined. The alphabet are called TERMINALS or TERMINAL SYMBOLS.
There is a finite set of variables also called NONTERMINALS or SYNTACTIC
CATEGORIES.
One of the variables represents the language being defined, it is called the
START SYMBOL. Other variables represent auxiliary classes of strings that are
used to help define the language of the start symbol.
There is a finite set of productions or rules that represent the recursive definition
of a language.
Production Composition: Each production consists of:
A. a variable that is being defined by the production, called the HEAD.
B. the production symbol
C. a string of zero or more terminals called the BODY.
CFG = (V,T,P,S) where
V = set of variables
T = the terminals
P = set of productions
S = start symbol
EXPERIMENT:
Using the grammar, show the derivations of the following sentences
EI
I Ib
EE+E
I I0
EE*E
I I1
E(E)
Ia
Ib
I Ia
1.
2.
3.
4.
5.
Using the grammar, construct the parse tree of the following sentences
E E+E | EE |
E*E | E/E |
-E
E (E)
E id
id a | b | c
1.
2.
3.
4.
5.
(a + b) * (b c)
c * (a + b)
a+b*ca/c+b
(c / a) + a + b
a + c / a b + (c * a + b)
11
a pushdown automaton (PDA) is a finite automaton that can make use of a stack
containing data.
They can use the top of the stack to decide which transition to take.
They can manipulate the stack as part of performing a transition.
A PDA is formally defined as a 7-tuple:
Where :
Q is a finite set of states
is a finite set known as input alphabet
is a finite set known as stack alphabet
is the transition function, that denotes the power set of S.
qo Q is the start state
Z is the initial stack symbol
F Q is the set of accepting states
Transitions:
Let ((p, a, ), (q, )) be a transition.
It means that we
o Move from state p.
o Read a from the tape,
o Pop the string from the stack,
o Move to state q,
o Push string onto the stack.
The first three (p, a, ), are input.
The last two (q, ) are output.
a, ;
12
EXPERIMENT:
State the language that is accepted by the following PDAs. Give at least five strings
that can be accepted and five strings that are not.
PDA 1:
PDA 2:
PDA 3
13
COMPUTABILITY THEORY
OBJECTIVES
1. Be familiar with the application of Turing Machine in the design of computing
resources;
2. Appreciate computability theory as part of the foundations of computer
science.
3. Create Turing machines that will implement specific problems;
14
EXPERIMENT:
Using the following Turing Machines, show the configuration of the following strings.
Likewise, state the language that is accepted by the Turing machine.:
1.
2.
00
3.
000
4.
0000
5.
000000
15
Consider the following Turing Machines, then state the language that they accept:
TM 1:
TM 2:
(q0,0) = (q0,B,R)
(q0,0) = (q1, 1, R)
(q0,1) = (q1,B,R)
(q1,1) = (q0, 0, R)
(q1,1) = (q1,B,R)
(q1,B) = (qf, B, R)
(q1,B) = (qf,B,R)
TM 3:
(q0,0) = (q1,1,R)
(q1,1) = (q2,0,L)
(q2,1) = (q0,1,R)
(q1,B) = (qf,B,R)
Using the following transition table, construct the transition diagram for the following
Turing Machines:
Table No. 1
State
q0
(q1, B, R)
(q5, B, R)
q1
(q1, 0, R)
(q2,1, R)
q2
(q3, 1, L)
(q2, 1, R)
(q4, B, L)
q3
(q3, 0, L)
(q3, 1, L)
(q0, B, R)
q4
(q4, 0, L)
(q4, B, L)
(q6, 0, R)
q5
(q5, B, R)
(q5, B, R)
(q6, B, R)
q6
16
Table No. 2
State
q0
(q1, X,R)
(q3,Y,R)
q1
(q1,Y,R)
q2
(q2, 0, L)
(q0,X,R)
(q2,Y,L)
q3
q4
17