Professional Documents
Culture Documents
NP COMPLETENESS
AND PROBLEM
REDUCIBILITY (cooks
theorem without proof,
Proof of np
completeness includes
CNF-SAT ,vertex cover
Approximation
and Subset sum
Algorithms
problem)
Concept and application
of Vertex cover Problem
, Subset sum problem
TRACTABLE AND INTRACTABLE PROBLEMS
• Complexity classes are sets of problems that are categorized based on the
amount of resources (time and space) required to solve them. These classes
help to quantify the difficulty of solving a particular problem and provide an
understanding of which types of problems are tractable or intractable within a
certain amount of resources
• There are several complexity classes, such as P, NP, NP-hard, and NP-
complete, that are used to classify problems based on their difficulty and the
possibility of solving them efficiently.
SOME POPULAR COMPLEXITY
CLASSES INCLUDE:
• 1. P (Polynomial Time): Problems that can be solved in polynomial time (i.e., the time required
for the algorithm to solve the problem is proportional to a polynomial function).
• 2. NP (Nondeterministic Polynomial Time): Problems that can be solved in polynomial time by
a nondeterministic algorithm. These problems are generally harder to solve than those in P.
• 3. NP-hard: Problems that are at least as hard as the hardest problems in NP. This means that
any problem in NP can be reduced (transformed) to an NP-hard problem in polynomial time. 4.
NP-complete: Problems that are both in NP and NP-hard. They are some of the most
challenging problems to solve.
• 5. EXP (Exponential Time): Problems that require an exponential amount of
POLYMIAL TIME AND SUPER POLYMIAL
TIME COMPLEXITY
• Tractable and intractable problems refer to the difficulty of solving a problem within a reasonable amount of time. A problem
is considered tractable if it can be solved in a reasonable amount of time by an algorithm. In contrast, an intractable problem
cannot be solved in a reasonable amount of time.
• The complexity of a problem is measured in terms of the time and resources required to solve it. Polynomial time complexity
refers to problems that can be solved in polynomial time, meaning that the time required to solve them grows at most as a
polynomial function of the size of the input.
• Super polynomial time complexity refers to problems that cannot be solved in polynomial time, meaning that the time
required to solve them grows faster than any polynomial function of the size of the input. These problems are considered
intractable and are often associated with hard computational problems such as factoring large integers and solving the
traveling salesman problem.
TYPES OF COMPLEXITY CLASSES
1.P Class
2.NP Class
4.NP-hard
5.NP-complete
CLASSES AND CHARACTERISTICS
FEATURES
P CLASS
• The P in the P class stands for Polynomial Time. It is the collection of decision problems(problems with a “yes” or “no”
answer) that can be solved by a deterministic machine in polynomial time.
• Features:
• The solution to P problems is easy to find.
• P is often a class of computational problems that are solvable and tractable. Tractable means that the problems can be solved
in theory as well as in practice. However, the problems that can be solved in theory but not in practice are known as
intractable.
• This class contains many problems:
1. Calculating the greatest common divisor.
2. Finding a maximum matching.
3. Merge Sort
PROGRAM TO FIND GCD OR HCF OF TWO
NUMBERS
• Given two numbers a and b, the task is to find the GCD of the two numbers.
• Note: GCD (Greatest Common Divisor) or HCF (Highest Common Factor)
of two numbers is the largest number that divides both of them.
EXAMPLE
• Input: a = 20, b = 28
• Output: 4
• Explanation: The factors of 20 are 1, 2, 4, 5, 10 and 20. The factors of 28 are 1, 2, 4, 7, 14
and 28. Among these factors, 1, 2 and 4 are the common factors of both 20 and 28. The
greatest among the common factors is 4.
• Input: a = 60, b = 36
• Output: 12
NP CLASS
• The NP in NP class stands for Non-deterministic Polynomial Time. It is the collection of decision problems that can be solved by
a non-deterministic machine in polynomial time.
• Features:
• The solutions of the NP class are hard to find since they are being solved by a non-deterministic machine but the solutions are easy
to verify.
• Problems of NP can be verified by a Turing machine in polynomial time.
• Example:
• Let us consider an example to better understand the NP class. Suppose there is a company having a total of 1000 employees having
unique employee IDs. Assume that there are 200 rooms available for them. A selection of 200 employees must be paired together,
but the CEO of the company has the data of some employees who can’t work in the same room due to personal reasons.
This is an example of an NP problem. Since it is easy to check if the given choice of 200 employees proposed by a coworker is
satisfactory or not i.e. no pair taken from the coworker list appears on the list given by the CEO. But generating such a list from
scratch seems to be so hard as to be completely impractical.
• It indicates that if someone can provide us with the solution to the problem, we can find the correct and incorrect pair in polynomial
time. Thus for the NP class problem, the answer is possible, which can be calculated in polynomial time.
NP-HARD CLASS
• An NP-hard problem is at least as hard as the hardest problem in NP and it is a class of problems such that every problem in
NP reduces to NP-hard.
• Features:
• All NP-hard problems are not in NP.
• It takes a long time to check them. This means if a solution for an NP-hard problem is given then it takes a long time to
check whether it is right or not.
• A problem A is in NP-hard if, for every problem L in NP, there exists a polynomial-time reduction from L to A.
• Some of the examples of problems in Np-hard are:
1. Halting problem.
2. Qualified Boolean formulas.
3. No Hamiltonian cycle.
A HALTING PROBLEM
• An example of writing the Halting Problem is as
follows
• INPUT − Program P and a string S.
• OUTPUT − if P stops on S, it returns 1.
• Otherwise, if P enters into an endless loop on S, it
returns 0.
• Let us consider the Halting Problem called H having
the solution.
• Now H takes the following two inputs −
• Program P
• Input S.
• If P stops on S, then H results in “halt”, otherwise H
gives the result “loop”.
• The diagrammatic representation of H is as follows
−
NP-COMPLETE CLASS
• A problem is NP-complete if it is both NP and NP-hard. NP-complete problems are the hard problems in NP.
• Features:
• NP-complete problems are special as any problem in NP class can be transformed or reduced into NP-complete
problems in polynomial time.
• If one could solve an NP-complete problem in polynomial time, then one could also solve any NP problem in
polynomial time.
• Some example problems include:
1. Hamiltonian Cycle.
2. Satisfiability.
3. Vertex cover.
NP COMPLETE PROBLEMS
• NP-complete problems are a subset of the larger class of NP (nondeterministic polynomial time)
problems. NP problems are a class of computational problems that can be solved in polynomial time by a non-
deterministic machine and can be verified in polynomial time by a deterministic Machine. A problem L in NP is NP-
complete if all other problems in NP can be reduced to L in polynomial time. If any NP-complete problem can be
solved in polynomial time, then every problem in NP can be solved in polynomial time. NP-complete problems are the
hardest problems in the NP set.
• A decision problem L is NP-complete if it follows the below two properties:
1. L is in NP (Any solution to NP-complete problems can be checked quickly, but no efficient solution is known).
2. Every problem in NP is reducible to L in polynomial time (Reduction is defined below).
• A problem is NP-Hard if it obeys Property 2 above and need not obey Property 1. Therefore, a problem is NP-
complete if it is both NP and NP-hard.
CONT.….
• What is Reduction?
• Let L1 and L2 be two decision problems. Suppose algorithm A2 solves L2.
That is, if y is an input for L2 then algorithm A2 will answer Yes or No
depending upon whether y belongs to L2 or not.
The idea is to find a transformation from L1 to L2 so that algorithm A2 can
be part of algorithm A1 to solve L1.
CONCEPT OF COOKS THEOREM
Given a 3-SAT formula with n variables and m clauses, we can convert it into a CNF-SAT formula by introducing a new
variable for each literal in the 3-SAT formula. For each clause (x ∨ y ∨ z), we create a new clause (x' ∨ y' ∨ z'), where
x', y', and z' are the new variables corresponding to literals x, y, and z respectively
This reduction can be done in polynomial time, and it preserves the "satisfiability" property of the original formula.
Therefore, if we can solve CNF-SAT in polynomial time, we can solve 3-SAT in polynomial time as well. Since 3-SAT is
NP-complete, CNF-SAT must also be NP-complete.
PROOF THAT VERTEX COVER IS NP
COMPLETENESS
a. NP class: The Vertex Cover problem belongs to the NP class because given a set of vertices that form a vertex cover, we can easily verify in
polynomial time if it covers all edges by checking each edge and finding if either of its endpoints is in the vertex cover.
b. NP-hardness: To prove NP-hardness, we can reduce a known NP-complete problem, such as 3-SAT, to Vertex Cover in polynomial time. The
reduction involves converting an instance of 3-SAT into an equivalent instance of Vertex Cover.
•Given a 3-SAT formula with n variables and m clauses, we can construct a graph G with 3n vertices and m edges as follows:
- Create three vertices for each variable x, representing its three possible truth values (x, ¬x, and unassigned).
- Create a clause gadget for each clause, consisting of three connected vertices representing the literals in the clause.
- Connect each clause gadget to the corresponding variable vertices.
•This reduction can be done in polynomial time, and it preserves the "satisfiability" property of the 3-SAT formula. Therefore, if we can solve
Vertex Cover in polynomial time, we can solve 3-SAT in polynomial time as well. Since 3-SAT is NP-complete, Vertex Cover must also be NP-
complete.
PROOF THAT SUBSET-SUM IS NP
COMPLETENESS
a. NP class: The Subset-Sum problem belongs to the NP class because given a set of numbers and a target sum, we can easily
verify in polynomial time if there is a subset that sums up to the target sum by checking each possible subset and calculating
its sum.
b. NP-hardness: To prove NP-hardness, we can reduce a known NP-complete problem, such as 3-SAT, to Subset-Sum in
polynomial time. The reduction involves converting an instance of 3-SAT into an equivalent instance of Subset-Sum.
•Given a 3-SAT formula with n variables and m clauses, we can construct a set of numbers including all possible clause
satisfactions and negations. For each clause, we create a number satisfying the clause (e.g., 1) and a number negating the
clause (e.g., -1). We also create a number for each variable (e.g., 0).
•We set the target sum as the number of clauses, m. Now, if there is a subset of numbers from our constructed set that sums
up to the target sum m, it means that there is a satisfying assignment for the 3-SAT formula.
•This reduction can be done in polynomial time, and it preserves the "satisfiability" property of the 3-SAT formula. Therefore,
if we can solve Subset-Sum in polynomial time, we can solve 3-SAT in polynomial time as well. Since 3-SAT is NP-complete,
Subset-Sum must also be NP-complete.
APROXIMATION ALGORITHMS