0% found this document useful (0 votes)
34 views

Complexity Classes

Uploaded by

Bidhan Barai
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)
34 views

Complexity Classes

Uploaded by

Bidhan Barai
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/ 7

Pseudo-polynomial Algorithms

What is a pseudo-polynomial algorithm?

A pseudo-polynomial algorithm is an algorithm whose worst-case time complexity is polynomial in the


numeric value of input (not number of inputs).

For example, consider the problem of counting frequencies of all elements in an array of positive numbers.
A pseudo-polynomial time solution for this is to first find the maximum value, then iterate from 1 to
maximum value and for each value, find its frequency in array. This solution requires time according to
maximum value in input array, therefore pseudo-polynomial. On the other hand, an algorithm whose time
complexity is polynomial in the number of elements in array (not value) is considered as polynomial time
algorithm.

Pseudo-polynomial and NP-Completeness

Some NP-Complete problems have pseudo-polynomial time solutions. For example, Dynamic
Programming Solutions of 0-1 Knapsack, Subset-Sum and Partition problems are Pseudo-Polynomial. NP
complete problems that can be solved using a pseudo-polynomial time algorithms are called weakly NP-
complete.

Types of Complexity Classes


P, NP, CoNP, NP hard and NP complete
In computer science, there exist some problems whose solutions are not yet found, the problems are
divided into classes known as Complexity Classes (Computability Classes). In complexity theory, a
Complexity Class is a set of problems with related complexity. These classes help scientists to group
problems based on how much time and space they require to solve problems and verify the solutions. It
is the branch of the theory of computation that deals with the resources required to solve a problem.

The common resources are time and space, meaning how much time the algorithm takes to solve a
problem and the corresponding memory usage.

The time complexity of an algorithm is used to describe the number of steps required to solve a
problem, but it can also be used to describe how long it takes to verify the answer.

The space complexity of an algorithm describes how much memory is required for the algorithm to
operate.

Complexity classes are useful in organizing similar types of problems.


Types of Complexity Classes
This article discusses the following complexity classes:
1. P Class
2. NP Class
3. CoNP Class
4. NP-hard
5. NP-complete

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:

1. The solution to P problems is easy to find.

2. 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. But the problems that can be
solved in theory but not in practice are known as intractable.

This class contains many natural problems:

1. Calculating the greatest common divisor.


2. Finding a maximum matching.
3. Decision versions of linear programming.

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:

1. 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.

2. 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.

This class contains many problems that one would like to be able to solve effectively:

1. Boolean Satisfiability Problem (SAT).


2. Hamiltonian Path Problem.
3. Graph coloring.

Co-NP Class

Co-NP stands for the complement of NP Class. It means if the answer to a problem in Co-NP is No, then
there is proof that can be checked in polynomial time.

Features:

1. If a problem X is in NP, then its complement X’ is also in CoNP.

2. For an NP and CoNP problem, there is no need to verify all the answers at once in polynomial
time, there is a need to verify only one particular answer “yes” or “no” in polynomial time for a
problem to be in NP or CoNP.

Some example problems for C0-NP are:

1. To check prime number.


2. Integer Factorization.
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:

1. All NP-hard problems are not in NP.

2. 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.

3. 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.
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:

1. NP-complete problems are special as any problem in NP class can be transformed or reduced into
NP-complete problems in polynomial time.

2. 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. Decision version of 0/1 Knapsack.


2. Hamiltonian Cycle.
3. Satisfiability.
4. Vertex cover.
Complexity
Characteristic feature
Class

P Easily solvable in polynomial time.

NP Yes, answers can be checked in polynomial time.

Co-NP No, answers can be checked in polynomial time.

All NP-hard problems are not in NP and it takes a long time


NP-hard
to check them.

NP-complete A problem that is NP and NP-hard is NP-complete.

Polynomial Time Verification


Before talking about the class of NP-complete problems, it is essential to introduce the notion of a
verification algorithm.

Many problems are hard to solve, but they have the property that it easy to authenticate the solution if
one is provided.

Hamiltonian cycle problem: -

Consider the Hamiltonian cycle problem. Given an undirected graph G, does G have a cycle that visits each
vertex exactly once? There is no known polynomial time algorithm for this dispute.

Note: - It means you can't build a Hamiltonian cycle in a graph with a polynomial time
even if there is no specific path is given for the Hamiltonian cycle with the particular
vertex, yet you can't verify the Hamiltonian cycle within the polynomial time

Fig:Hamiltonian Cycle
Let us understand that a graph did have a Hamiltonian cycle. It would be easy for someone to convince of
this. They would similarly say: "the period is hv3, v7, v1....v13i.

We could then inspect the graph and check that this is indeed a legal cycle and that it visits all of the
vertices of the graph exactly once. Thus, even though we know of no efficient way to solve the Hamiltonian
cycle problem, there is a beneficial way to verify that a given cycle is indeed a Hamiltonian cycle.

Note:-For the verification in the Polynomial-time of an undirected Hamiltonian cycle


graph G. There must be exact/specific/definite path must be given of Hamiltonian cycle
then you can verify in the polynomial time.

Definition of Certificate: - A piece of information which contains in the given path of a vertex is known
as certificate.

Relation of P and NP classes


1. P contains in NP
2. P=NP

1. Observe that P contains in NP. In other words, if we can solve a problem in


polynomial time, we can indeed verify the solution in polynomial time. More
formally, we do not need to see a certificate (there is no need to specify the
vertex/intermediate of the specific path) to solve the problem; we can explain it in
polynomial time anyway.
2. However, it is not known whether P = NP. It seems you can verify and produce an
output of the set of decision-based problems in NP classes in a polynomial time
which is impossible because according to the definition of NP classes you can verify
the solution within the polynomial time. So this relation can never be held.

Reductions:
The class NP-complete (NPC) problems consist of a set of decision problems (a subset of
class NP) that no one knows how to solve efficiently. But if there were a polynomial
solution for even a single NP-complete problem, then every problem in NPC will be
solvable in polynomial time. For this, we need the concept of reductions.

Suppose there are two problems, A and B. You know that it is impossible to solve problem
A in polynomial time. You want to prove that B cannot be explained in polynomial time.
We want to show that (A ∉ P) => (B ∉ P)
Consider an example to illustrate reduction: The following problem is well-known to be
NPC:

3-color: Given a graph G, can each of its vertices be labeled with one of 3 different colors
such that two adjacent vertices do not have the same label (color).

Coloring arises in various partitioning issues where there is a constraint that two objects
cannot be assigned to the same set of partitions. The phrase "coloring" comes from the
original application which was in map drawing. Two countries that contribute a common
border should be colored with different colors.

It is well known that planar graphs can be colored (maps) with four colors. There exists a
polynomial time algorithm for this. But deciding whether this can be done with 3 colors
is hard, and there is no polynomial time algorithm for it.

Fig: Example of 3-colorable


and non-3-colorable
graphs.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy