Cla 3, Ap23110010650
Cla 3, Ap23110010650
Cla 3, Ap23110010650
CLA-3
PRESENTED BY GROUP-5:
P V SAI KIRAN-AP23110010650
Understanding NP Problems
Introduction to NP, NP - Complete, and NP-Hard Problems
CONTEN
T:
1)NP Problems
2)P vs NP
3)NP-complete problems
4)NP-hard problems
5)Approaches
6)Real world applications
7)Summary
P VS NP
int main() {
vector<int> arr = {5, 3, 8, 6, 7, 2, 4};
int target = 6;
int result = linearSearch(arr, target);
if (result != -1) {
cout << "Element found at index " << result << endl;
} else {
cout << "Element not found" << endl;
}
return 0;
}
Advisory Argument
Advisory Argument for P (Polynomial Time)
int main() {
vector<int> nums = {3, 34, 4, 12, 5, 2};
int target = 9;
if (isSubsetSum(nums, target)) {
cout << "Subset with sum " << target << " exists." << endl;
} else {
cout << "Subset with sum " << target << " does not exist." << endl;
}
return 0;
}
Advisory Argument
Context: Evaluating whether a complex
problem is feasible for practical use.
Analysis: Problems in NP allow for efficient
verification of solutions, even if solving
them is difficult. Many real-world problems,
like scheduling or cryptography, fall into
this category.
Counterargument: Solving NP problems may
require exponential time unless specialized
heuristic methods or approximations are
used.
Recommendation: Use NP problems to model
complex scenarios (e.g., SAT problem,
Hamiltonian cycle) where verifying a solution
is critical. Invest in research for heuristics
or approximation techniques for practical
applications.
NP COMPLETE PROBLEM
Definition:
NP-Complete problems are the hardest problems in NP. If any NP-complete problem
can be solved in polynomial time, then all NP problems can be solved in polynomial time
(P = NP).
Characteristics:
In NP: Solution can be verified in polynomial time.
Hardest in NP: Solving one in polynomial time solves all NP problems.
Examples:
Traveling Salesman Problem: Shortest route visiting each city once.
Knapsack Problem: Optimal items within weight capacity.
3-SAT Problem: Boolean formula satisfiability with three literals per clause.
Significance:
Represent boundary of computational complexity.
Central to fields like optimization, cryptography, and AI.
Examples
Boolean Satisfiability Problem (SAT)
3-SAT Problem: A variant of SAT with clauses
containing 3 literals.
Clique Problem: Does a graph contain a
complete subgraph of size k?
Vertex Cover Problem: Is there a set of
vertices covering all edges of size k?
ALGORITHM
assignment[var] = true;
if (isSatisfiable(clauses, assignment, var + 1)) return true;
assignment[var] = false;
return isSatisfiable(clauses, assignment, var + 1);
}
Advisory Argument
Context: Evaluating problems for research or
high-stakes scenarios where exact solutions
are vital.
Analysis: NP-complete problems are both in NP
(verifiable) and NP-hard (as hard as any NP
problem). Solving even one NP-complete
problem in polynomial time would prove P = NP,
revolutionizing computational complexity.
Examples include SAT, 3-SAT, and Vertex Cover
problems.
Counterargument: Directly solving NP-complete
problems is often infeasible for large inputs
due to exponential time complexity.
Recommendation: Prioritize NP-complete
problems for theoretical research or
situations where exactness is paramount. Use
reductions to simplify problems or heuristic
approaches to manage complexity in practical
cases.
NP HARD PROBLEMS
Definition: NP-Hard problems are at least as difficult as the hardest problems in NP.
However, they don’t have to be in the NP class because they may not have solutions
verifiable in polynomial time.
Key Characteristics:
No Known Polynomial-Time Solution: NP-Hard problems can’t be solved efficiently with
any known algorithms.
May Not Have Verifiable Solutions: Unlike NP-complete problems, a solution to an NP-
Hard problem may not be verifiable in polynomial time.
Can Be Unsolvable or Undecidable: Some NP-Hard problems, like the Halting Problem,
can’t be solved or verified for all inputs.
Real-World Examples:
Bin Packing: Minimizing the number of bins needed to pack items of different sizes.
Halting Problem: Determining if a program will eventually halt, which is undecidable.
Examples
Travelling Salesman Problem (TSP): Find the
shortest route visiting all cities.
Knapsack Problem (Optimization version):
Maximize value within a weight limit.
Graph Coloring Problem: Can you color a graph
using at most k colors such that no two
adjacent vertices have the same color?
HEURISTIC ALGORITHMS