You are on page 1of 44

1

Complexity Theory
Computer problems come in different varieties;
some are easy, and some are hard.
e.g. sorting an array of large numbers is easy
even for a simple computer.
Scheduling of a time table for a no. of classes
might be too complex and hard for a simple
computer.
central question of complexity theory is What
makes some problems computationally hard and
others easy
Dr. Muhammad Asif
2
Complexity Theory
So far researchers have discovered the elegant scheme
for classifying problems according to their
computational difficulty.
You have several options when you confront a problem
that appears to be computationally hard.
1) by understanding which aspect of the problem is at
the root of the difficulty, alter it so that problem is
easily solvable.
2) you may be able to settle for less than a perfect
solution to the problem.
3) Some problems are hard only in the worst case
situation, but easy most of the time.

Dr. Muhammad Asif
3
Computability Theory
During the first half of the twentieth century, some
mathematicians discovered that certain basic problems
cannot be solved by computers.

e.g. problem of determining whether a mathematical
statement is true or false.

Computability theory deals with the classification of
problems that those are solvable and those that are not.
Dr. Muhammad Asif
4
Automata Theory
Automata theory deals with the definitions and
properties of mathematical models of computation.

These models play a role in several applied areas of
computer science.

e.g. Finite automaton, is used in text processing
compilers and hardware design.

Another model, called the context-free grammar, is
Used in programming languages and artificial intelligence.

Dr. Muhammad Asif
5
Mathematical Notions and
Terminology
Sets:
A set is a group of objects represented as a unit. Sets
may contain any type of object including numbers,
symbols and even other sets.
The objects in a set are called its elements or member.
Formal description of a set is as follows.
{ 34, 44, 98, 21}
The symbols and . Denotes the membership
and nonmember ship.
We write 7 {7,34, 44, 98, 21 } and 8 . {7, 34, 44, 98,
21 }


Dr. Muhammad Asif
6
Mathematical Notions and
Terminology
SubSet:
For two sets A and B, we say that A is a subset of B, if
every member of A also is a member of B.

We say that A is a proper subset of B, if A is a subset
of B and not equal to B.

The order of describing a set doesn't matter, nor does
repetition of its members.

We get the same set as in previous slide by writing
{44,44,7,34, 44, 98, 21 }.

Dr. Muhammad Asif
7
Mathematical Notions and
Terminology
Multi set.
If we do want to take the number of occurrences of
members into account we call the group a multi set
instead of a set.
Thus {7} and {7,7} are different as multi sets but
identical as sets
Infinite Set.
contains infinitely many elements. We cannot write a list
of all the elements of an infinite set instead we write
notion to represent infinite set.
e.g. set of natural numbers N can be written as
{1,2,3,...}
Dr. Muhammad Asif
8
Mathematical Notions and
Terminology
Empty set.
The set with 0 members is called the empty set and is
written .

When we want to describe a set containing elements
according to some rule, we write {nl rule about n}.
Thus {nl n = m
2
for some element m belongs to N } means
the set of perfect squares.
Union.
If we have two sets A and B, the union of A and B,
written AU B, is the set we get by combining all the
elements in A and B into a single set.

Dr. Muhammad Asif
9
Mathematical Notions and
Terminology
Intersection.
The intersection of A and B is the set of elements that
are in both A and B.

Complement.
The complement of A, written A , is the set of all
elements under consideration that are not in A.

Venn diagram.
It represents sets as regions enclosed by circular lines.
Let the set START-t be the set of all English words
that start with the letter "t"
Dr. Muhammad Asif
10
Mathematical Notions and
Terminology
Venn diagram.
Venn diagram for the set of English words starting with "t
Dr. Muhammad Asif
11
Mathematical Notions and
Terminology
Venn diagram.
Venn diagram for the set of English words End with z.
Dr. Muhammad Asif
12
Mathematical Notions and
Terminology
Venn diagram.
Venn diagram for indicating common elements.
To represent both sets in the same Venn diagram we
must draw them so that they overlap, indicating that
they share some elements. E.g.
Dr. Muhammad Asif
13
Mathematical Notions and
Terminology
Venn diagram.
Venn diagram for indicating union and intersection.
Venn diagram for union and intersection. E.g.
Dr. Muhammad Asif
14
Mathematical Notions and
Terminology
Sequence and Tuples.

A sequence of objects is a list of these objects in some
order.
We usually designate a sequence by writing the list
within parentheses. E.g. the sequence 7, 21,57 would be
written (7,21,57)
In a set the order doesn't matter, but in a sequence it
does, hence (7,21,57) is not the same as (57,7, 21).
Similarly, repetition does matter in a sequence, but
it doesn't matter in a set. E.g. (1,4,5) is different from
(1,1,4,5)
Dr. Muhammad Asif
15
Mathematical Notions and
Terminology
Sequence and Tuples.
Sequences may be finite or infinite like sets.
Finite sequences often are called tuples.
A sequence with k elements is a k-tuple.
Thus (7,21,57) is a 3-tuple.
A 2-tuple is also called a pair.
Cartesian or Cross product
A and B, written A x B, is the set of all pairs wherein the
first element is a member of A and the second element
is a member of B.
Dr. Muhammad Asif
16
Mathematical Notions and
Terminology
Cartesian or Cross product.

If A = {1,2} and B = {x, y, z},

A x B= {(1,x), (1,y), (1,z),(2,x),(2,y),(2,z)}

We can also take the Cartesian product of k set

A x B x A == {(1,x,1),(1,x,2),(1,y, 1),(1,y, 2),(1,z, 1),(1,z, 2),
(2,x,1),(2,x,2), (2,y, 1),(2,y, 2), (2, z, 1),(2,z, 2) }
Dr. Muhammad Asif
17
Mathematical Notions and
Terminology
Functions and Relations.
A function is an object that sets up an input-output
relationship.
A function takes an input and produces an output.
If f is a function whose output value is b when the input
value is a, we write
f(a) = b.

A function is also called a mapping, and, if f(a)= b, we say
that f maps a to b.
Dr. Muhammad Asif
18
Mathematical Notions and
Terminology
Functions Mapping.

For example Addition is an example of a function,
written add.
The input to the addition function is a pair of numbers,
and the output is the sum of those numbers.

Functions Domain and Range.
The set of possible inputs to the function is called its
domain.
The outputs of a function come from a set called its
range.


Dr. Muhammad Asif
19
Mathematical Notions and
Terminology
Functions Domain and Range.

The notation for saying that f is a function with domain
D and range R is
f:D R

In the case of the addition function for integers.
The domain is the set of pairs of integers Z x Z and the
range is Z, so we write
add:Z x Z Z.
Dr. Muhammad Asif
20
Mathematical Notions and
Terminology
Functions Domain and Range.

Note that a function may not necessarily use all the
elements of the specified range.

e.g. the function abs never takes on the value -1 even
though -1 belongs to Z.

A function that does use all the elements of the range
is said to be onto the range.


Dr. Muhammad Asif
21
Mathematical Notions and
Terminology
Functions Description
We may describe a specific function in several ways.
One way is with a procedure for computing an output
from a specified input.
Another way is with a table that lists all possible inputs
and gives the output for each input.
e.g. one way is
Consider the function f: {O,1,2,3,4} {O,1,2,3,4}.)
Tabular way

Dr. Muhammad Asif
22
Mathematical Notions and
Terminology
Graphs
An undirected graph, or simply a graph, is a set of points
with lines connecting some of the points.
The points are called nodes or vertices and the lines are
called edges.

Dr. Muhammad Asif
23
Mathematical Notions and
Terminology
Degree of Nodes
The number of edges at a particular node is the degree
of that node.
In a graph G that contains nodes i and j, the pair (i,j)
represents the edge that connects i and j.
The order of i and j does not matter in undirected
graphs so (i,j) and (j,i) represents same edge.

Dr. Muhammad Asif
24
Mathematical Notions and
Terminology
Degree of Nodes

( {1,2,3,4,5}, {(1,2),(2, ,3),(3,4), (4,5),(5,1)})

and a formal description of the graph in second figure
({1,2,,3,4},({1,2}, {1, ,3)(,1,4)(,2,3)(,2,4),(3,4)})).

Dr. Muhammad Asif
25
Mathematical Notions and
Terminology
Usage of Graphs
Graphs are normally used to represent data
Nodes might be cities and edges the connecting
highways
or nodes might be electrical components and edges the
wires between them.
Labeled Graph
Some time we use labeling to represent node and edges,
this is called a labeled graph.
Dr. Muhammad Asif
26
Mathematical Notions and
Terminology
Sub-Graphs
A graph G is a sub-graph of graph H if the nodes of G
are a subset of the nodes of H, and the edges of G are
the edges of H on the corresponding nodes.
Dr. Muhammad Asif
27
Mathematical Notions and
Terminology
Path
A path in a graph is a sequence of nodes connected by
edges.

Simple Path
A simple path is a path that doesn't repeat any nodes.
Connected graph

A graph is connected if every two nodes have a path
between them.
Cycle
A path is a cycle if it starts and ends in the same node


Dr. Muhammad Asif
28
Mathematical Notions and
Terminology
Tree graph

A graph is a tree if it is connected and has no simple
cycles.
Dr. Muhammad Asif
29
Mathematical Notions and
Terminology
Directed graph

If a graph has arrows instead of lines, the graph is a
directed graph.
The number of arrows pointing from a particular node is
the out-degree of that node
the number of arrows pointing to a particular node is the
in-degree.
Dr. Muhammad Asif
30
Mathematical Notions and
Terminology
Formal description of Directed graph
The tuple (i,j) and different from (j,i) in directed graph.

({1,2,3,4,5,6}, {(1,2),(1,5),(2,1),
(2,4),(5,4),(5,6),(6,1),(6,3)})
Dr. Muhammad Asif
31
Strings and Languages
Strings of characters are fundamental building blocks in
computer science.
An alphabet can be any nonempty finite set.
The members of the alphabet are the symbols of the
alphabet.
We generally use capital Greek letter designate
alphabets.
e.g.
= {0,1}
= {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}
Dr. Muhammad Asif
32
Strings and Languages
A string over an alphabet is a finite sequence of symbols
from that alphabet
= {0,1}
String over the alphabet above: 010001010

= {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}
String: abbcdrrraa.
Length of a string
If w is a string over , the length of w, written |w|, is
the number of symbols that it contains.

Dr. Muhammad Asif
33
Strings and Languages
The string of length zero is called the empty string and
is written as .
Reversal of a string
The reverse of w, written w
R
, is the string obtained by
writing w in the opposite order(i.e. if a string s=abc then
reversal of s=cba)

Substring
String z is a sub string of W if z appears consecutively
with in w.
e.g. cad is a substring of abracadabra
Dr. Muhammad Asif
34
Strings and Languages
String Concatenation
If we have string x of length m and string y of length n,
the concatenation of x and y, written xy, is the string
obtained by appending y to the end of x

Lexicographic ordering of a string
is the same as the familiar dictionary ordering, except
that shorter strings precede longer strings.
e.g. Lexicographic ordering of all strings over the
alphabet { 0,1} is
(e,0,10,0,01,10,11,000, ,..)..
Dr. Muhammad Asif
35
Strings and Languages
Dr. Muhammad Asif
36
Another Operation



Example:


Definition:

( ) abbaabba abba =
2
=
0
w
( ) =
0
abba
Dr. Muhammad Asif
37
The * Operation
: the set of all possible strings from
alphabet






* E
E
{ }
{ } , , , , , , , , , *
,
aab aaa bb ba ab aa b a
b a
= E
= E
Dr. Muhammad Asif
38
The + Operation
: the set of all possible strings from
alphabet except






+
E
E
{ }
{ } , , , , , , , , , *
,
aab aaa bb ba ab aa b a
b a
= E
= E
E = E
+
*
{ } , , , , , , , , aab aaa bb ba ab aa b a = E
+

Dr. Muhammad Asif


39
Example of Languages
A language over alphabet
is any subset of
Examples:





* E
{ }
{ } , , , , , , , , *
,
aaa bb ba ab aa b a
b a
= E
= E
{ }
{ }
} , , , , , {
, ,
aaaaaa ab aa baba abba
aab aa a

Language:
Language:
Language:
E
Dr. Muhammad Asif
40
More Language Examples


An infinite language
} 0 : { > = n b a L
n n
aaaaabbbbb
aabb
ab

L e
L abbe
} , { b a = E
Alphabet
Dr. Muhammad Asif
41
prime} is and : {
*
x x x PRIMES E e =
} 9 , , 2 , 1 , 0 { = E
} , 17 , 13 , 11 , 7 , 5 , 3 , 2 { = PRIMES
Prime numbers
Alphabet
Language:
Dr. Muhammad Asif
42
even} is and : {
*
x x x EVEN E e =
} 9 , , 2 , 1 , 0 { = E
Even and odd numbers
Alphabet
odd} is and : {
*
x x x ODD E e =
} , 6 , 4 , 2 , 0 { = EVEN
} , 7 , 5 , 3 , 1 { = ODD
Dr. Muhammad Asif
43
Reverse

Definition:

Examples:
} : { L w w L
R R
e =
{ } { } abab baa ba baba aab ab
R
, , , , =
} 0 : {
} 0 : {
> =
> =
n a b L
n b a L
n n R
n n
Dr. Muhammad Asif
44
Concatenation

Definition:



Example:
{ }
2 1 2 1
, : L y L x xy L L e e =
{ }{ }
{ } baaa bab abaa abb aaa ab
aa b ba ab a
, , , , ,
, , ,
=
Dr. Muhammad Asif

You might also like