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

DAA Unit 5 Part 2

The document discusses the theory of NP completeness, explaining the classes of problems including P (solvable in polynomial time), NP (verifiable in polynomial time), NP-Hard (at least as hard as NP problems but not necessarily verifiable), and NP-Complete (both NP and NP-Hard). It also covers approximation algorithms, which provide near-optimal solutions to NP-Complete problems in polynomial time, and details the vertex cover problem as an example of such algorithms. Key features and characteristics of each class of problems are outlined, emphasizing their computational complexities.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

DAA Unit 5 Part 2

The document discusses the theory of NP completeness, explaining the classes of problems including P (solvable in polynomial time), NP (verifiable in polynomial time), NP-Hard (at least as hard as NP problems but not necessarily verifiable), and NP-Complete (both NP and NP-Hard). It also covers approximation algorithms, which provide near-optimal solutions to NP-Complete problems in polynomial time, and details the vertex cover problem as an example of such algorithms. Key features and characteristics of each class of problems are outlined, emphasizing their computational complexities.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Theory of NP Completeness

P(Polynomial Time)
• Problems in the class P can be solved by a deterministic algorithm in polynomial time.
This means there exists an algorithm that can find a solution efficiently (in time
proportional to a polynomial of the input size, nk, where k is a constant).
• 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.
• Key Idea: Problems that are "easy" or "efficiently solvable" on a standard computer.
Examples:
• Sorting numbers (e.g., merge sort, O(nlogn)).
• Finding the shortest path in a graph (e.g., Dijkstra's algorithm).
• Multiplying two matrices.
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.
NP (Nondeterministic Polynomial Time)
• Problems in the class NP have solutions that can be verified in polynomial time by a
deterministic algorithm. However, finding the solution may not necessarily be efficient.
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.
• Key Idea: Problems for which verifying a solution is "easy," but finding it may be "hard."
Examples:
• The Travelling Salesman Problem (TSP): Given cities and distances between them, find
the shortest route visiting all cities exactly once.
• Verifying a given solution (e.g., total route length) is quick.
• Finding the shortest route is challenging.
• The Subset Sum Problem: Does a subset of numbers add up to a target value?
• 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.
NP-Hard Problem
• An NP-Hard problem is a type of computational problem that is at least as hard as the
hardest problems in NP. However, an NP-Hard problem does not necessarily belong
to NP, meaning:
• It might not have a verifiable solution in polynomial time.
• Solving any NP-Hard problem efficiently (in polynomial time) would imply that every
problem in NP can also be solved efficiently.
Characteristics of NP-Hard Problems
• At least as hard as NP problems:
• Every NP problem can be reduced to an NP-Hard problem in polynomial time.
• May not belong to NP:
• NP problems require solutions to be verifiable in polynomial time. NP-Hard problems
may not meet this criterion.
• No guaranteed polynomial-time solution:
• There is no known polynomial-time algorithm for NP-Hard problems unless P=NPP =
NPP=NP.
NP-Hard Problem
Examples of NP-Hard Problems
1. Traveling Salesman Problem (TSP)
• Description: Given a list of cities and the distances between them, find the shortest
possible route that visits each city exactly once and returns to the origin city.
• Why NP-Hard:
• Finding the shortest route is computationally difficult.
• Even approximate solutions are computationally intensive for large instances.

2. Hamiltonian Cycle Problem


• Description: Determine if there exists a cycle in a graph that visits each vertex exactly
once.
• Why NP-Hard:
• It generalizes the TSP but without the requirement of minimizing the distance.
NP-Hard Problem
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.
NP-Complete Problem
• A problem is NP-complete if it is both NP and NP-hard. NP-complete problems are the
hard problems in NP.
• NP-Complete problems are a special subset of computational problems that are both in
NP and as hard as the hardest problems in NP.
• They serve as a bridge between the complexity classes P and NP.
Characteristics of NP-Complete Problems
• Belong to NP:
• The solution can be verified in polynomial time by a deterministic Turing machine.
• NP-Hard:
• Solving one NP-Complete problem efficiently would allow us to solve all problems in
NP efficiently.
• Polynomial-Time Reduction:
• Any problem in NP can be reduced to an NP-Complete problem in polynomial time.
This means that if you can solve an NP-Complete problem, you can also solve any
problem in NP.
NP-Complete Problem
NP-Complete Problem
NP-Complete Problem
Approximation Algorithms
• An Approximate Algorithm is a way of approach NP-COMPLETENESS for the
optimization problem.
• This technique does not guarantee the best solution.
• The goal of an approximation algorithm is to come as close as possible to the optimum
value in a reasonable amount of time which is at the most polynomial time.
• Such algorithms are called approximation algorithm or heuristic algorithm.

Features of Approximation Algorithm :

• An approximation algorithm guarantees to run in polynomial time though it does not


guarantee the most effective solution.
• An approximation algorithm guarantees to seek out high accuracy and top quality
solution(say within 1% of optimum)
• Approximation algorithms are used to get an answer near the (optimal) solution of an
optimization problem in polynomial time
Approximation Algorithms
This leads to the concept of performance ratios of an approximation problem.
• The main idea behind calculating the performance ratio of an approximation algorithm,
which is also called as an approximation ratio, is to find how close the approximate
solution is to the optimal solution.
• The approximate ratio is represented using ρ(n) where n is the input size of the algorithm,
C is the near-optimal solution obtained by the algorithm, C* is the optimal solution for the
problem. The algorithm has an approximate ratio of ρ(n) if and only if −

• The algorithm is then called a ρ(n)-approximation algorithm.


Approximation Algorithms
• Approximation Algorithms can be applied on two types of optimization problems:
minimization problems and maximization problems.
• If the optimal solution of the problem is to find the maximum cost, the problem is known
as the maximization problem; and if the optimal solution of the problem is to find the
minimum cost, then the problem is known as a minimization problem.
• For maximization problems, the approximation ratio is calculated by C*/C since 0 ≤ C ≤
C*.
• For minimization problems, the approximation ratio is calculated by C/C* since 0 ≤ C* ≤ C.
Approximation Algorithms
Vertex Cover Problem

• A vertex-cover of an undirected graph G = (V,E) is the subset of vertices of the graph


such that, for all the edges (u,v) in the graph,u and v ∈ V.
• A Vertex Cover of a graph G is a set of vertices such that each edge in G is incident to at
least one of these vertices.

Algorithm
• Step 1 − Select any random edge from the input graph and mark all the edges that are
incident on the vertices corresponding to the selected edge.
• Step 2 − Add the vertices of the arbitrary edge to an output set.
• Step 3 − Repeat Step 1 on the remaining unmarked edges of the graph and add the
vertices chosen to the output until there’s no edge left unmarked.
• Step 4 − The final output set achieved would be the near-optimal vertex cover.
Approximation Algorithms
Psuedocode
APPROX-VERTEX_COVER (G: Graph)
c←{}
E’ ← E[G] while E’ is not empty do
Let (u, v) be an arbitrary edge of E’
c ← c U {u, v}
Remove from E’ every edge incident on either u or v
return c
Approximation Algorithms

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