You are on page 1of 50

Theory of Computer Science

SCJ 3203
Programme Educational Objectives
• Ability to acquire and apply theory and principles of Computer Science and equip
with social science and personal development knowledge.
• Ability to design and construct computer programs using standard approaches
• Ability to identify, formulate and solve real world problems through software
engineering principles and methodologies, and to creatively produce software
artifacts using current tools and techniques
• Ability to present technical solutions to a range of audience
• Ability to think critically and creatively in order to solve real world problem
• Ability to work effectively in a team
• Ability to undertake lifelong learning and actively participate in change
• Ability to identify business opportunity and develop entrepreneurship skill
• Ability to function effectively and with responsibility as a leader to achieve
common goals
• Ability to demonstrate behaviors that are consistent with the Code of
Professional Ethics and Responsibilities

Sept2011 Theory of Computer Science 3


Course Learning Outcomes
• Describe the theory of Computer Science.
• Apply and explain the theory in solving the
given problems.
• Discuss and make decision to solve
problems related to computer science
theory.
• Work collaboratively in a team to solve
problems using current information
related to computer science theory.
Sept2013 Theory of Computer Science 4
Reference Books
• Main Text:
– Thomas Sudkamp 2005, Language and machine,
Pearson Int.Edition
• Others:
– John Martin, Introduction to Languages and the Theory
of Computation.
– Dea Kelly, Automata and Formal Languages - an
Introduction, Prentice Hall, 1995.
– John E. Hopcroft, Rajeev Motwani, Jeffrey D. Ullman,
Introduction to automata theory, languages, and
computation, Pearson/Addison Wesley, 2007.

Sept2011 Theory of Computer Science 6


Grading
No. Assessment Number % each % total
1 Assignments 2 5% 10
2 Quizzes 4 of 5 2.5% 10
3 Tutorials 10 of 12 2% 20

4 Mid-Semester Exam 1 25% 25

5 Final Exam 1 35% 35


Overall Total 100

Sept2011 Theory of Computer Science 7


UTM Attendance Policy
• To be allowed to sit for final exam, a
student must have an attendance more
than 80%.
• First warning letter will be issued for the
first 4 hours not attending the class.
• Second warning letter for the subsequent 4
hours.
• Letter to forbid seating for final exam will
be issued for the subsequent 3 hours.

Sept2011 Theory of Computer Science 10


Teaching Method
• 3 Hours :
1. Lecture 50 minutes
2. Break 10 minutes, Tutorial
30 minutes
3. Discussions – students share
the answer in front of the
class.
Sept2011 Theory of Computer Science 11
How to do well…
• This is essentially a math course:
– you must learn the concepts well; if you don’t there’s almost no chance of
success
– if you do learn the concepts, there is very little else (facts, etc.) to learn;
you can do really well!
– You must do problems. There’s no replacement for this.
– Attending lectures is highly advised!
• It will be very hard to learn the concepts by yourself or from textbook.
• – Don’t postpone learning; you will not be able to “make up” later.
• Topics get quickly hard.
• – Come regularly to discussion sections; you will learn a lot by working
out problems and learn from fellow students

Sept2011 Theory of Computer Science 12


• Homeworks every week;
• handed out on Monday,
• due in class by 5:50pm on Monday.
• • Write each problem on a separate sheet of paper.
• (allows distributed grading)
• • Homework can be done in groups of at most three people.
• • However, each student must hand in their own homework
• (no group submissions; must clearly write your group
members)
• • There may be additional “quizzes” (15min tests) at
discussion sections as well.

Sept2011 Theory of Computer Science 13


Academic dishonesty:
• Many students find it helpful to consult their peers while doing
assignments. This practice is legitimate and to be expected. However, it
is not acceptable practice to pool thoughts and produce common
answers. To avoid this situation, it is suggested that students not write
anything down during such talks, but keep mental notes for later
development of their own.
• Students who allow their files or assignments to be copied are as guilty
of academic dishonesty as those who copy and will be treated
accordingly. Each student is responsible for taking reasonable
precautions to ensure that his/her work is not available for unauthorized
use.
• Copying solutions from the Internet or books or any other public sources
is prohibited!

Theory of Computer Science 14


Introduction & Mathematics
Preliminaries
Important Notes
• No programming in this course
• It is assumed that you are familiar
with:
–programming and basic
algorithms
–notation “big-oh”
–sets
Sept2011 Theory of Computer Science 16
Motivation to this course
• What are the capabilities and limitations
of computer?
• What is computation?
– Consists of executing an algorithm.
– Starting with some input and following a
step by step procedure that will produce a
result
– A computation is simply a sequence of steps
that can be performed by a computer
Sept2011 Theory of Computer Science 17
Motivation to this course
• What type of computer?
–Abstract machines or model of
computation, which will be defined
mathematically.
–Language that can be accepted by this
machine

Sept2011 Theory of Computer Science 18


Motivation to this course

Sept2011 Theory of Computer Science 19


Why do we talk about Theory of
Computation?
• Techniques of computer theory are
necessary in the teaching of courses on
computer design, Artificial Intelligence,
the analysis of algorithms, and so forth.
• They can be applied in compiler design,
natural language processing as well.

Sept2011 Theory of Computer Science 20


What is Theory of Computation?

• Divide into 3 parts


–Automata Theory
–Computability Theory
–Complexity Theory

Sept2011 Theory of Computer Science 21


Languages and Automata
• Regular Languages
• Nondeterminism
• Regular Expressions
• Nonregular Expressions
• Context-free Grammars
• Pushdown Automata
• Context-sensitive Languages
Sept2011 Theory of Computer Science 22
Computability Theory
• The Church-Turing Thesis
• Decidability
• Reducibility
• Advanced Topics in Computational
Theory

Sept2011 Theory of Computer Science 23


Complexity Theory
• Time Complexity
• Space Complexity
• Intractability
• Advanced Topics in
ComplexityTheory

Sept2011 Theory of Computer Science 24


Introduction
• What are the fundamental
capabilities and limitations of
computers ?
–Time has increased our ability to
compute and have brought this
question out.
–What are the answers in Complexity
Theory, Computability Theory and
Automata Theory ?
Sept2011 Theory of Computer Science 25
Complexity Theory
• Computer problems :
– easy  sorting
– hard  scheduling
• What makes some problems computationally hard
and others easy ?
• We don’t know what make them easy and hard but
we know how to classify each problems with an
elegant scheme.
– Cryptography is supposed to be a hard problem.

Sept2011 Theory of Computer Science 26


Computability Theory

• There are some problems which can’t


be solved by computers, e.g.,
determining whether a mathematical
statement is true or false.
• The object of the Computability Theory
is to classify the problems whether
they are solvable by computers or not.

Sept2011 Theory of Computer Science 27


Automata Theory
• deals with the definitions and
properties of mathematical models
of computation.
–Finite Automata (FA) used in text
processing, compilers and hardware
design.
–Context-free Grammar (CFG) used in
programming languages and artificial
intelligence.
Sept2011 Theory of Computer Science 28
Mathematical Notions and
Terminology Used
• Sets
• Functions and Relations
• Sequences and Tuples
• Trees
• Boolean Logic

Sept2011 Theory of Computer Science 29


Sets
• Importance: languages are sets
• Sets are a collection of well defined objects
E.g. : A = {set all items in kitchen} = {utensils,
stove, spoons.....}
B = {set all natural numbers} = {1, 2, 3, ...}
• Sets are denoted by capital letters - A, B, C, etc.
& the objects by small letters - a, b, c, etc.
• The objects called the elements or members of
the set.

Sept2011 Theory of Computer Science 30


Sets
• Sets can be finite or infinite.
• Finite sets are sets with a small number of members
can defined explicitly; that is, their members can be
listed. . E.g.: X = 1, 2, 3, Y = a, b, c, d, e
• An infinite set contains infinitely many elements.
• Sets having a large finite or infinite number of
members must be defined implicitly. E.g.: set of
natural numbers = N = {0, 1, 2, 3, ...}, set of integers
= Z = { ... , -2, -1, 0, 1, 2, ... }.
• Note: ". . .” means "continue the sequence forever".
Theory of Computer Science 31
Sets
• There are two common ways of
listing the members of a set:
–Explicitly - List all the elements, e.g.
{a, e, i, o, u}.
–Implicitly - Provide some sort of an
algorithm or rule, such as a grammar,
e.g. {set of vowel letters}, { x | x  A
or x  B }.
Sept2011 Theory of Computer Science 32
Sets
• Notation:
– If x is a member of set S, we write x  S
– We denote the empty set (the set with no
members) as {} or 
– If every element of set A is also an element of
set B, we say that A is a subset of B (A  B)
– If every element of set A is also an element of
set B, but B also has some elements not
contained in A, we say that A is a proper
subset of B (A  B)
Sept2011 Theory of Computer Science 33
Sets
• If a set has 3 elements.
a) how many subsets does it have?
b) how many proper subsets does it have?
• The number of subsets is always 2 raised to the
power of the number of elements in the set. In
this case, the answer is 23 = 2 x 2 x 2 = 8.
• The number of proper subsets is always 1 less
than the number of subsets, since a proper
subset is any subset except the set itself! In this
case, the answer is 23 – 1 = 8 - 1 = 7.

Theory of Computer Science 34


Set operations: Union
• The union of sets A and B, written A  B, is a set that
contains everything that is in A, or in B, or in both.

A B

A U B
Sept2011 Theory of Computer Science 35
Set operations: Union
• Formal definition for the union of two
sets:
A U B = { x | x  A or x  B }
• Further examples
– {1, 2, 3} U {3, 4, 5} = {1, 2, 3, 4, 5}
– {Johor, Melaka} U {3, 4} = {Johor, Melaka,
3, 4}
– {1, 2} U  = {1, 2}
Sept2011 Theory of Computer Science 36
Set operations: Intersection
• The intersection of sets A and B, written A  B, is a set that
contains all the elements in both A and B.

A B

A ∩ B
Sept2011 Theory of Computer Science 37
Set operations: Intersection
• Formal definition for the intersection of
two sets: A ∩ B = { x | x  A and x  B }
• Further examples
– {1, 2, 3} ∩ {3, 4, 5} = {3}
– {Johor, Melaka} ∩ {3, 4} = 
• No elements in common
– {1, 2} ∩  = 
• Any set intersection with the empty set yields
the empty set

Theory of Computer Science 38


Disjoint sets
• Two sets are disjoint if they have no elements
in common, that is, if AB = .
• E.g.: The set of the even numbers and the
set of the odd numbers

A B

Sept2011 Theory of Computer Science 39


Disjoint sets
• Formal definition for disjoint sets: two sets are
disjoint if their intersection is the empty set
• Further examples
– {1, 2, 3} and {3, 4, 5} are not disjoint
– {Johor, Melaka} and {3, 4} are disjoint
– {1, 2} and  are disjoint
• Their intersection is the empty set
–  and  are disjoint!
• Their intersection is the empty set

Theory of Computer Science 40


Set operations: Difference
• The set difference of set A and set B, written A - B, is a
set that contains everything that is in A but not in B.
A - A
B B

A B

Theory of Computer Science 41


Set operations: Difference
• Formal definition for the difference of two
sets:
A - B = { x |_x  A and x  B }
A-B=A∩B
• Further examples
– {1, 2, 3} - {3, 4, 5} = {1, 2}
– {Johor, Melaka} - {3, 4} = {Johor, Melaka}
– {1, 2} -  = {1, 2}
• The difference of any set S with the empty set will
be the set S Theory of Computer Science 42
Set operations: Symmetric Difference
• A symmetric difference of the sets contains all the elements
in either set but NOT both
• Formal definition for the symmetric difference of
two sets:
A  B = { x | (x  A or x  B) and x  A ∩ B}
A  B = (A U B) – (A ∩ B)
• Further examples
– {1, 2, 3}  {3, 4, 5} = {1, 2, 4, 5}
– {Johor, Melaka}  {3, 4} = {Johor, Melaka, 3, 4}
– {1, 2}   = {1, 2}
• The symmetric difference of any set S with the empty set will be
the set S Theory of Computer Science 43
Complement sets
• The complement of a set A, written as A’ or -A or
(better) A with a bar drawn over it, is the set containing
everything that is not in A. _
A
B
U

A B

Theory of Computer Science 44


Complement sets
• Formal definition for the complement of a set: Ā = {
x|xA}
• Or U – A, where U is the universal set that contains
"everything" (meaning "everything we are
interested in at the moment").
• Then, Ā or –A or A’ is shorthand for U - A.
• Further examples:
– {1, 2, 3} = { …, -2, -1, 0, 4, 5, 6, … }
– {Johor, Melaka} - {3, 4} = {Johor, Melaka}
– {1, 2} -  = {1, 2}
• The difference of any set S with the empty set will be the set S

Theory of Computer Science 45


Additional terminology
• The cardinality of a set A, written |A|, is the
number of elements in a set A.
• The powerset of a set A, written P(A) or 2A, is
the set of all subsets of A. The notation
suggests the fact that a set containing n
elements has a powerset containing 2n
elements, including empty set.
– Example: 2{a,b,c} = {, {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c}}
– Note that the empty set and the set A itself are in
A’s power set

Sept2011 Theory of Computer Science 47


Sequences and Tuples
• A sequence of objects is a list of
those objects in some order.
• Usually designate by writing the list
within parenthesis, e.g. (3, 2, 5).
• May be finite or infinite.
• Finite sequences called tuples.
• Sequence with k elements is a k-
tuple, e.g., (3,2,5) is a 3-tuple.
Theory of Computer Science 48
Cartesian product (Cross product)
• The Cartesian product of two sets A and B, denoted A  B,
is the set of all ordered pairs with first element from A
and second element from B
– A  B = {(a, b) | a  A and b  B}
– A = {1,2}; B = {3,4}
A × B = {1,2} × {3,4} = {(1,3), (1,4), (2,3), (2,4)}
B × A = {3,4} × {1,2} = {(3,1), (3,2), (4,1), (4,2)}
– {1, 2} × {red, white} = {(1, red), (1, white), (2, red), (2,
white)}.
– We can generalize this to ordered k-tuples:
A1  A2  …  Ak = {(a1, a2, … , ak | ai  Ai for each i}

Sept2011 Theory of Computer Science 49


Boolean Logic
• AND (conjunction) 
• OR (disjunction) 
• NOT (negation) 
• XOR (exclusive or) 
• Equality  : 1 if both of its operands have
the same value.
• Implication  : 0 if its first operand is 1
and the second operand is 0; otherwise 1.
Sept2013 Theory of Computer Science 54
Computer representation of sets 1
• Assume that U is finite (and reasonable!)
– Let U be the alphabet

• Each bit represents whether the element in U is in the set

• The vowels in the alphabet:


abcdefghijklmnopqrstuvwxyz
10001000100000100000100000

• The consonants in the alphabet:


abcdefghijklmnopqrstuvwxyz
01110111011111011111011111
Computer representation of sets 2
• Consider the union of these two sets:
10001000100000100000100000
01110111011111011111011111
11111111111111111111111111

• Consider the intersection of these two sets:


10001000100000100000100000
01110111011111011111011111
00000000000000000000000000
Exercises
Describe the following statements in your own
words:
• X = { x | x  A or x  B } = A U B
• X = { x | x  A and x  B } = A ∩ B
• X = { x | x  A and x  B } = A - B
• X = { x | (x  A or x  B) and x  A ∩ B} 
• X = { x | x  A } or U – A Ā
• |A| = cardinatility of set A.
• P(A) or 2A or 2n
Videos on Set Theory
• http://www.youtube.com/watch?v=vGelH
3Jibt4&feature=related
• http://www.youtube.com/watch?v=mfB1
3y4y0oA&feature=related
• http://www.youtube.com/watch?v=c0-
X79njWwk&feature=related
• http://nlvm.usu.edu/en/nav/frames_asid
_153_g_2_t_1.html?open=instructions&fr
om=topic_t_1.html

Sept2011 Theory of Computer Science 58


Self Tests
• All - Fundamental
http://www.math.ucla.edu/~tao/java/
MultipleChoice/MultipleChoice.html
• Set Theory
http://www.okcupid.com/quizzy/take
• Logic
http://faculty.washington.edu/smcohe
n/120/TheoryQuizMQ.htm
Sept2011 Theory of Computer Science 59

You might also like