0% found this document useful (0 votes)
25 views4 pages

Advanced Algorithms and Complexity: The Complexity Class P: August 3, 2018

The document provides an introduction to complexity classes P and Co-P. It defines strings and languages as sets of strings. Turing machines are introduced as a model of computation, with examples of deterministic and non-deterministic machines. The class P is defined as problems solvable by a deterministic Turing machine in polynomial time. Examples like integer multiplication are shown to be in P. The class Co-P is also introduced and shown to be equivalent to P, as the complement of any problem in P can be solved in polynomial time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Advanced Algorithms and Complexity: The Complexity Class P: August 3, 2018

The document provides an introduction to complexity classes P and Co-P. It defines strings and languages as sets of strings. Turing machines are introduced as a model of computation, with examples of deterministic and non-deterministic machines. The class P is defined as problems solvable by a deterministic Turing machine in polynomial time. Examples like integer multiplication are shown to be in P. The class Co-P is also introduced and shown to be equivalent to P, as the complement of any problem in P can be solved in polynomial time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Advanced Algorithms and Complexity :

Lecture 1
The Complexity Class P

August 3, 2018

Alphabets are finite sets of symbols. Examples: the binary alphabet {0, 1}
Strings are concatenation of zero or more symbols from alphabet. Examples
are :  (string of length 0),0, 10, 00, 000, 101, 100, 110, .... Length of a string
w is denoted by |w|. For example || = 0 and |110| = 3.
Languages are sets of strings. For example, we can define a language Le as
the set of all binary strings ending in 0: Le = {0, 10, 00, 000, 010, 100, 110, ...}
Turing Machines are a formal model of computation.
Example of a TM: We will design a TM for accepting the language Le as
follows: TM’s have a tape which is divided into cells. For simplicity we are
considering a single-tape TM. We can also have multi-tape TMs having more
than one tape. Again, for simplicity we are assuming that the tape is semi-
infinite tape which starts from a cell having a special start symbol which we
denote by .. We can also have 2−way infinite tape, and also 2−dimensional
tapes. TM has a head that scans a single cell at a time. Initially it scans
the start symbol. In any move of the TM, the head can either move Left
(L), Right (R) or Stay (S) at the current cell. TMs can be in one of possible
(finite) states. Initially, the TM is in the start state which we denote by qs .
With each move TMs can change the state. There is a state called halting
state which we denote by qh . When TM is in qh state, then there is no further
move possible and we say that the TM has accepted its input. If the TM
halts in any other state other than qh , then we say that the TM has rejected

1
its input. TMs can be thought of as an algorithm that takes some input on
its tape and gives some output (yes if it accepts, no if it rejects). The ‘code’
of a TM is the transition function δ which specifies how the TM changes its
state, moves its head, and modifies the current cell on a particular state and
the current cell content. For the example language Le we have:

Le = {0, 00, 10, 000, 010, 100, 110, ...} Initially the TM on input 100 will be:

We can easily design the transition function δ for this TM as follows:


δ(q0 , .) = (q1, ., R)
δ(q1 , 0) = (q1 , 0, R)
δ(q1 , 1) = (q1 , 1, R)
δ(q1 , B) = (q2 , 0, L)
δ(q2 , 0) = (qn , 0, S)
We can run this TM with input 100 and see that it halts in state qh . Therefore
the TM accepts the input 100. On input 101, it will halt in state q2 . Therefore
the TM accepts the language Le .
The example TM that we have considered is a deterministic TM (DTM)
because each transition function specifies exactly one possible move. We can
also have a Non-Deterministic TM (NTM) in which the transition function
specifies more than one possible moves.
Formally we can define a DTM (one-tape) as a 3−tuple (Γ, Q, δ) where Γ
is the finite set of possible tape symbols (including the input alphabet and

2
the symbols . and B). Q is the finite set of states (including qs and qh ).
δ : Q×Γ → (Q, Γ, {L, R, S}) is the transition function specifying the moves of
the DTM. We say that the DTM accepts a language L if for any x, x ∈ L =⇒
DTM halts in state qh when started with input x with initial state qs and
head scanning the . symbol. x ∈ / L =⇒ DTM halts in state q ∈ Q − qh
when started with input x with initial state qs and the head scanning the .
symbol.

Time Complexity of DTMs: For the example DTM, we observe that it


makes Θ(n) moves on input of size n. We say that its time-complexity is
Θ(n). Time-complexity of a DTM is independent of the input (whether it
belongs to the language on not). It only depends on the input size n.

The time complexity class DTime: Let T : N → N be some function.


A Language L ∈ Dtime(T (n)) ⇐⇒ ∃ DTM that runs in time O(T (n)) and
accepts L.

The time complexity class P : P = ∪c≥1 DTime(nc )


The time complexity class P is defined for languages (decision problems with
Yes/No as output).

Some examples of problems in P : Given two integers x and y of n bits


each, we can multiply them in O(n2 ) time on a RAM TM (TM with RAM:
Random Access Memory). A T (n)− time RAM TM can be simulated in
T (n2 ) time by a multitape DTM. This will not change the time complexity
class P whether we define it by using a multitape DTM or by using a RAM
TM. So for proving that a given language belongs to the class P , it is sufficient
to give a polynomial time algorithm (RAM TM) for the language.
The multiplication probelm is: given x and y (integers) find an integer z such
that z = xy. This is not a decision problem. We create a language Lmult as
follows: Lmult = {(x, y, z) | x, y, z are binary integers such that z = xy}.
For example (10, 11, 110) ∈ Lmult and
(10, 11, 111) ∈
/ Lmult
because (10)2 × (11)2 = (110)2 and
(10)2 × (11)2 6= (111)2
A RAMTM for accepting Lmult : calculate z 0 = xy in time O(n2 ) and check

3
whether z 0 = z in time O(n) with total time complexity as O(n2 )
=⇒ Lmult ∈ P .

P is closed under complementation (P = Co − P ): Co − P is defined


as a time complexity class as follows:
We say that a language L ∈ Co − P if L ∈ P , Co − P is not the complement
of the class P (P ).
For example: Lmult ∈ P =⇒ Lmult = {(x, y, z) | x, y, z are integers such that z 6=
xy} ∈ Co − P ⇐⇒ L ∈ P . L ∈ P =⇒ ∃ DTM T accepting L in poly-
nomial time. We modify T as follows: convert qh into a new non-halting
state q 0 . When T halts on an input in a non-halting state (original states),
then add a move so that T halts in qh state. Now the new DTM T 0 has the
property that it has the same time-complexity as T and also that whenever
T accepts an input, T 0 rejects it, and whenever T rejects an input, T 0 accepts
it
=⇒ T 0 accepts L in polynomial time =⇒ L ∈ P .

Co − P ⊆ P : Let L ∈ Co − P . We will prove that L ∈ P as follows:


L ∈ Co − P ⇐⇒ L ∈ P =⇒ ∃ DTM T accepting L in polynomial time.
Now we modify T to get a DTM T 0 as before that accepts L in polynomial
time =⇒ L ∈ P .
Example RAM TM for Lmult : On input (x, y, z), calculate z 0 = xy in time
O(n2 ). Compare z with z 0 in time O(n) and accept the input if z 6= z 0 ,
otherwise reject the input. The total time complexity of the RAM TM is
O(n2 ) =⇒ Lmult ∈ P .

You might also like