You are on page 1of 27

NP COMPLETENESS

ENITA MUDZINGENYAMA M222934


KUDAKWASHE MATAMBANADZO M215892
TAKURANASHE SITHOLE M224488
SMILE SINYOLO M171044
CONTENTS
TRACTABLE AND
INTRACTABLE
PROBLEMS
COMPLEXITY
CLASSES
POLYMIAL TIME
AND SUPER
POLYMIAL TIME
COMPLEXITY
P,NP,
COMPLETE ,HARD
COMPLETE
NP COMPLETE
PROBLEMS

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

• Tractable problems are those that can be solved efficiently, generally in


polynomial time. In other words, the time it takes to solve the problem increases
proportionally with the size of the problem. Examples of tractable problems
include sorting, searching, and matrix multiplication.
• Intractable problems, on the other hand, cannot be solved efficiently, especially
as the size of the problem grows. They often require exponential time or worse,
meaning that the time it takes to solve the problem increases exponentially with
the size of the input. Examples of intractable problems include the traveling
salesman problem, the knapsack problem, and the graph coloring problem.
COMPLEXITY CLASSES

• 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.….

• Decision vs Optimization Problems


• NP-completeness applies to the realm of decision problems. It was set up this way because it’s
easier to compare the difficulty of decision problems than that of optimization problems. In reality,
though, being able to solve a decision problem in polynomial time will often permit us to solve the
corresponding optimization problem in polynomial time (using a polynomial number of calls to the
decision problem). So, discussing the difficulty of decision problems is often really equivalent to
discussing the difficulty of optimization problems.
For example, consider the vertex cover problem (Given a graph, find out the minimum sized vertex
set that covers all edges). It is an optimization problem. The corresponding decision problem is,
given undirected graph G and k, is there a vertex cover of size k?
PROBLEM REDUCIBILITY

• 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

• In computational complexity theory, the Cook–Levin theorem, also known as Cook’s


theorem, states that the Boolean satisfiability problem is NP-complete. That is, it is in NP,
and any problem in NP can be reduced in polynomial time by a deterministic Turing
machine to the Boolean satisfiability problem.
• NP= P if and only if the satisfiability problem is a P problem. The proof of the above
theorem consists of two parts. The first part is “If NP P, then the satisfiability problem is a P
problem”. This part is obvious because the satisfiability problem is an NP problem. The
second part is “If the satisfiability problem is a P problem, then NP P”. This is a crucial part
of Cook’s theorem.
PROOF OF NP COMPLETENESS
•To prove that CNF-SAT is NP-complete, we need to show two things: that it belongs to the NP class and that it is NP-
hard.
•a. NP class: CNF-SAT belongs to the NP class because given a satisfying assignment, we can easily verify its
correctness in polynomial time. We can simply substitute the assignment into the formula and check if it evaluates to
true.
•b. NP-hardness: To prove NP-hardness, we can reduce a known NP-complete problem, such as 3-SAT, to CNF-SAT in
polynomial time. The reduction involves converting an instance of 3-SAT into an equivalent instance of CNF-SAT.

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

• Approximation algorithms are a set of techniques used for solving


optimization problems when it is difficult or impossible to find an exact
solution in a reasonable amount of time. The idea behind approximation
algorithms is to find a feasible solution that is close to the optimal solution,
rather than finding the optimal solution itself.
APROXIMATION ALGORITHMS
EXAMPLES
• 1. Greedy Algorithms: Greedy algorithms build a solution step-by-step by making locally optimal choices at each stage. These algorithms are
simple, efficient, and often provide good solutions for many optimization problems.
• 2. Randomized Algorithms: Randomized algorithms use randomization to make decisions during the optimization process. These algorithms
can produce better solutions compared to deterministic algorithms, but their performance may vary depending on the quality of the random
choices made.
• 3. Linear Programming-Based Algorithms: Linear programming algorithms solve optimization problems by formulating them as linear
programming models. These algorithms provide provably optimal solutions, but their complexity can be very high.
• 4. Local Search Algorithms: Local search algorithms start with an initial solution and make small changes to it in an attempt to improve its
quality. These algorithms are efficient and can work well for problems with a large search space, but they do not guarantee an optimal solution.
• 5. Approximation Schemes: Approximation schemes are algorithms that provide solutions with a guaranteed approximation ratio, and this
ratio can be made arbitrarily small by increasing the computation time. These algorithms are useful for problems where a very accurate
solution is required.
• 6. Heuristic Algorithms: Heuristic algorithms use domain-specific knowledge and problem- specific rules to try different solutions and find the
best one. These algorithms can provide good solutions but do not guarantee an optimal
CONCEPT AND APPLICATION:

• The Vertex Cover Problem:


The Vertex Cover Problem is a classic problem in computer science and graph theory that seeks to find the smallest
possible subset of vertices in an undirected graph such that every edge in the graph is incident to at least one vertex
in the subset. In other words, it seeks to find a vertex cover that covers all the edges of the graph.
• Application:
One important application of the Vertex Cover Problem is in the field of network security. In this context, vertices
represent network nodes, and the edges represent connections between them. By finding the minimal vertex cover
of such a graph, network administrators can identify vulnerable nodes that must be secured against potential
security threats. The Vertex Cover Problem has also been applied in research into the optimization of network
design, to identify routing patterns and minimize the impact of hardware failures on the network performance.
CONCEPT AND APPLICATION:

• The Subset Sum Problem:


The Subset Sum Problem is a well-known problem in computer science that seeks to determine whether a
given set of integers has a subset that sums up to a specific target value. In other words, the Subset Sum
Problem asks whether there is a subset of the given set whose sum equals a given target value.
• Application:
The Subset Sum Problem has applications in cryptography, computer security, and computational biology. In
cryptography, the Subset Sum Problem is used as the basis for the development of public key encryption
schemes. In computer security, the Subset Sum Problem is used for generating random numbers and for
protecting sensitive information from unauthorized access. In computational biology, the Subset Sum
Problem is used to infer phylogenetic trees from DNA sequence data, among other application
THANK YOU
NEXT

You might also like