Professional Documents
Culture Documents
CH 4 - 1
CH 4 - 1
Decidable
Languages
“Easy” Problems
“Hard” Problems
Time Complexity
The most critical computational resource is often time, so the most
useful complexity measure is often time complexity
The time complexity of an algorithm quantifies the amount of time
taken by an algorithm to run as a function of the length of the input.
Note that the time to run is a function of the length of the input and
not the actual execution time of the machine on which the algorithm
is running on.
If we take Turing Machine as our model of computation, then we can
give a precise measure of the time resources used by a computation
Definition
Definition The
The time
timecomplexity
complexity ofofaaTuring
TuringMachine
Machine TT isisthe
the
function such that Time T ( x ) isisthe
suchthat thenumber
numberofof
Time
function T
steps
stepstaken
takenby
bythe
thecomputation
computation T(x)
T(x)
Space Complexity
Another important computational resource is amount of “memory”
used by an algorithm, that is space. The corresponding complexity
measure is space complexity
Problem-solving using computer requires memory to hold temporary
data or final result while the program is in execution.
The amount of memory required by the algorithm to solve given
problem is called space complexity of the algorithm.
The space complexity of an algorithm quantifies the amount of space
taken by an algorithm to run as a function of the length of the input.
As with time, if we take Turing Machine as our model of
computation, then we can easily give a measure of the space resources
used by a computation
Definition
Definition The The space
spacecomplexity
complexity ofofaaTuring
TuringMachine
Machine TT isisthe
the
function Space T such
function suchthat isisthe
thenumber
numberofof
Space ( x )
that T
distinct
distincttape
tapecells
cellsvisited
visitedduring
duringthe
thecomputation
computation T(x)
T(x)
Complexity Classes
It is Deterministic in nature
Solved by conventional computers in polynomial time
O(1) Constant
O(log n) Sub-linear
O(n) Linear
O(n log n) Nearly Linear
O(n2) Quadratic
Consists Polynomial upper and lower bounds
Polynomial Equivalence of RAM algorithms and
Turing Machine algorithms
P EXP R
NP
Complexity class NP will serve as our formal model for the class of
problems having efficiently verifiable solutions.
A decision problem / language is in NP if given an input x, we can
easily verify that x is a YES instance of the problem (or equivalently,
x is in the language) if we are given the polynomial-size solution for
x, that certifies this fact.
NP is not the same as non-polynomial complexity/running time.
NP does not stand for not polynomial.
NP = Non-Deterministic polynomial time
NP means verifiable in polynomial time
Verifiable?
If we are some how given a ‘certificate’ of a solution we can verify
the legitimacy in polynomial time
What happened to automata?
P is a subset of NP
“P = NP”?
Language L is in NP, complement of L is in co-NP
co-NP ≠ NP
P ≠ co-NP
Relation of P and NP
Un decidable problems
Given a polynomial with integer coefficients, does it have
integer roots
Hilbert’s nth problem
Impossible to check for all the integers
Even a non-deterministic TM has to have a finite number of
states!
More on decidability later
Tautology
A Boolean formula that is true for all possible assignments
Here just one ‘verifier’ will not work. You have to try all
possible values
Polynomial-Time Reducibility
Language L is polynomial-time reducible to language M if there
is a function computable in polynomial time that takes an input
x of L and transforms it to an input f(x) of M, such that x is a
member of L if and only if f(x) is a member of M.
Shorthand, LpolyM means L is polynomial-time reducible to M
NP - hard
Need to be in NP
Need to be in NP-Hard
A decision problem D is NP-complete iff
D NP
every problem in NP is polynomial-time reducible to D
If both are satisfied then it is an NP complete problem
Reducibility is a transitive relation.
If we know a single problem in NP-Complete that helps when we are asked to
prove some other problem is NP-Complete
NP-Hard problems(say X) can be solved if and NP-Complete problems can be solved by a non-
only if there is a NP-Complete problem(say Y) deterministic Algorithm/Turing Machine in
that can be reducible into X in polynomial time. polynomial time.
To solve this problem, it do not have to be in To solve this problem, it must be both NP and
NP . NP-hard problems.
Not all NP-hard problems are NP-complete. All NP-complete problems are NP-hard