notes - Cal State L.A.

advertisement
CLASS NOTES CS312
There are five different classes of algorithms.
1.P is a class of algorithm that is solvable in polynomial time.
P = solvable in O(nk) k is a constant.
2.The second class is a super polynomial class.In this class the problems are not solvable in
polynomial time.These algorithms are also proved that they are not solvable in polynomial time.
SP = not solvable in polynomial time.
3.The third class is NP class. It is called non -deterministic polynomial time algorithm. In NP class
if given a certificate, the algorithm can be verified in polynomial time.
4.NP-Complete class is the forth one.NP-complete class of algorithms has two properties.
1.It is a part of NP class.
2.Any problem is as “hard” as any other problem in NP-Complete problem set.
The second property states that if we can solve one problem in polynomial time we can solve all
problems in NP-Complete class in polynomial time.
5.The fifth one is UNSOLVABLE problems. Famous example of unsolvable problem is halting
problem, it cannot be solved no matter how much time is given.
How these classes are related to one another is shown below.
Case1:If we believe that NP-Complete is a part of P class then they look like below one.
Case2:If we believe that none of the NP-complete class is solvable in polynomial time .
.
NP-COMPLETE problems and Reducibility:
If one NP-Completeness problem can be solved in polynomial time then all other NP-Complete
problems can be solved in polynomial time.
Polynomial time Reducibility: Transforming one algorithm to another in polynomial time.
L
p
If L (
L’
) = true iff L’(
) = true;
NP-Compete Problems :
1.CIRCUIT-SAT problem :Given a circuit, it is satisfiable only if output is one .
In the above circuit there are 32 different inputs i.e (2 5).There is a solution for this circuit but it is
solvable in exponential time i.e. in 2 n .
We can verify it in polynomial time.
2.SAT (Satisfiability problem) :
SAT = {
|
is satisfiable boolean formula}
In SAT there will be some arrangement of input and produce one output. In SAT we deal with
formula where as in CIRCUIT-SAT we deal with circuit.
Z = x1
x2
x3
x4
In this formula the number of possible inputs are 2 n i.e. (2 4).
This algorithm can be verified in polynomial time. The SAT formula can be reduced to
CIRCIUT-SAT. The
sign can be converted to AND gate.
The above circuit is the conversion of the SAT formula to the CIRCUIT-SAT.
Both these are problems in NP – Complete class.
SAT
p CIRCUIT-SAT
3. 3-CNF SAT: CNF stands for conjunctive normal form
Z = ( x1 x2 x3) ( x1 x2 x3) (x1 x2 x3)
In 3 CNF there are exactly three distinct literals. They are in groups of there.
This algorithm can be verifiable in polynomial time.
3-CNF can be reduced to SAT in constant time .This also belongs to NP-C.
4. CLIQUE : clique is a complete sub graph of your graph. A complete graph is one which forms
complete cycle of k nodes. The clique problem is the optimization problem of finding a clique of
maximum size in a graph.
In the above graph there a complete sub graph if k = 4
And k = 6
The clique problem can be converted to SAT problem.
(x1 x2 x3 x4)
(x1 x2 x3 x4 x5 x6)
Given a certificate we can verify this algorithm in polynomial time.
5.VERTEX-COVER: vertex cover of a graph is the set of vertices that covers all the edges.
The vertex cover problem is to find a vertex cover of minimum size in a given graph.
In this problem k = 4 is the minimum. This can be converted to clique problem.
6.HAM-CYCLE :It is a simple cycle that doesn’t repeat any vertex such that we hit every vertex
of the graph exactly once.
This can be modified to VERTEX-COVER problem.
7. TRAVELLING SALESMAN PROBLEM: It is closely related to HAM-CYCLE problem but
has weights on the cycles that have to be minimized. This can also be verified in polynomial time
if we are given a certificate.
8. SUBSET-SUM: In a subset problem we are given a finite set of numbers and we have to find if
there is a subset of that problem whose elements sum to value k.
{13,21,7,5,10,30,105}
We can optimize this by sorting the list.
Suppose we have to find 140
First sort the list 5,7,10,13,21,30,105
105+35 = 140
Worst case time of this algorithm is n!.
The structure of NP-C problems is
These are the eight famous NP-C problems.
Another NP-C problem is Register allocation. The number of variables in a typical program is
much larger than the number of available registers in a processor .There will be only finite number
of registers in a CPU and allocation of registers to the variables is the problem.
Suppose we have
four registers R1,R2,R3,R4
8 variables x1
X2
X3 = X1 + X2
X3
X4
X5 = X3 – X4
X5
X6
X6 = X1 + X5
X7
X8
The variables that are longest in the registers are pulled out first, which is not good because we
may need them.
This problem is also related to vertex-cover problem.
Download