Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

TOC - UNIT – 5

P, NP Problems
P, NP, NP-Complete, NP-Hard

P Problems
As the name says these problems can be solved in polynomial time, i.e.; O(n), O(n2) or
O(nk), where k is a constant.

P is the set of all the decision problems solvable by deterministic algorithms in polynomial
time.

It contains all decision problems that can be solved by a deterministic Turing machine using a
polynomial amount of computation time, or polynomial time.

Cobham's thesis holds that P is the class of computational problems that are "efficiently
solvable" or "tractable". This is inexact: in practice, some problems not known to be in P
have practical solutions, and some that are in P do not, but this is a useful rule of thumb.

Example:

P is known to contain many natural problems, including the decision versions of linear
programming, calculating the greatest common divisor, and finding a maximum matching.

Kruskal’s Algorithm:
Kruskal's algorithm is a minimum-spanning-tree algorithm which finds an edge of the least
possible weight that connects any two trees in the forest. It is a greedy algorithm in graph theory
as it finds a minimum spanning tree for a connected weighted graph adding increasing cost arcs at
each step.

The solution is
NP Problems

NP is the set of all the decision problems that are solvable by non - deterministic algorithms
in polynomial time.

The class NP consists of those problems that are verifiable in polynomial time. NP is the
class of decision problems for which it is easy to check the correctness of a claimed answer,
with the aid of a little extra information. Hence, we aren’t asking for a way to find a solution,
but only to verify that an alleged solution really is correct.

Every problem in this class can be solved in exponential time using exhaustive search.

Since deterministic algorithms are just the special case of non - deterministic ones, so we can
conclude that P is the subset of NP.

Example of NP Class Problem:


Travelling Sales Person Problem:

Travelling Salesman Problem (TSP): Given a set of cities and distance between every pair of
cities, the problem is to find the shortest possible route that visits every city exactly once and
returns to the starting point

Examples:

Shortest total path length spanning tree


Hamiltonian completion
Knapsack problem, quadratic knapsack problem
Bottleneck traveling salesman
Quadratic programming (NP-hard in some cases, P if convex)
Subset sum problem

NP Hard Problem

A problem L is the NP hard if and only if satisfiability reduces to L. A problem is NP


complete if and only if L is the NP hard and L belongs to NP.

Only a decision problem can be NP complete. However, an optimization problem may be the
NP hard. Furthermore if L1 is a decision problem and L2 an optimization problem, then it is
possible that L1 α L2. One can trivially show that the knapsack decision problem reduces to
knapsack optimization problem. For the clique problem one can easily show that the clique
decision problem reduces to the clique optimization problem. In fact, one can also show that
these optimization problems reduce to their corresponding decision problems.

Graph theory
■ 1.1 Covering and partitioning
■ 1.2 Subgraphs and supergraphs
■ 1.3 Vertex ordering
■ 1.4 Iso- and other morphisms
■ 1.5 Miscellaneous
■ 2 Network design
■ 2.1 Spanning trees
■ 2.2 Cuts and connectivity
■ 2.3 Routing problems
■ 2.4 Flow problems
■ 2.5 Miscellaneous
■ 2.6 Graph Drawing
■ 3 Sets and partitions
■ 3.1 Covering, hitting, and splitting
■ 3.2 Weighted set problems
■ 3.3 Set partitions
■ 4 Storage and retrieval
■ 4.1 Data storage
■ 4.2 Compression and representation
■ 4.3 Database problems
■ 5 Sequencing and scheduling
■ 5.1 Sequencing on one processor
■ 5.2 Multiprocessor scheduling
■ 5.3 Shop scheduling
■ 5.4 Miscellaneous
■ 6 Mathematical programming
■ 7 Algebra and number theory
■ 7.1 Divisibility problems
■ 7.2 Solvability of equations
■ 7.3 Miscellaneous
■ 8 Games and puzzles
■ 9 Logic
■ 9.1 Propositional logic
■ 9.2 Miscellaneous
■ 10 Automata and language theory
■ 10.1 Automata theory
■ 10.2 Formal languages
■ 11 Computational geometry
■ 12 Program optimization
■ 12.1 Code generation
■ 12.2 Programs and schemes

You might also like