0% found this document useful (0 votes)
98 views13 pages

P, NP & Cook's Theorem

Uploaded by

maneeshgopisetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views13 pages

P, NP & Cook's Theorem

Uploaded by

maneeshgopisetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIT V

(Basic Concepts of NP Hard and NP Complete, Cook’s Theorem)

In the context of Design and Analysis of Algorithms (DAA), polynomial time refers to the time
complexity of an algorithm that can be expressed as a polynomial function of the size of the
input. An algorithm runs in polynomial time if its running time is O(n^k) for some constant k≥1.

Key Points:

1. Definition: An algorithm is said to have polynomial time complexity if the time it takes
to complete is upper-bounded by a polynomial expression in the size of the input. For
example, algorithms with time complexities like O(n2)O(n^2)O(n2), O(n3)O(n^3)O(n3),
or O(logn)O(n)O(nlogn) are considered polynomial time.
2. Significance: Polynomial time algorithms are generally regarded as efficient or feasible
for practical purposes. This is in contrast to exponential time algorithms (e.g. O(2^n) )
which grow much faster and become infeasible for large inputs.
3. P Class: Problems that can be solved by an algorithm in polynomial time are part of the
complexity class P (short for "Polynomial time"). This class is important in theoretical
computer science because it represents problems that are considered solvable efficiently.
4. Examples:
o Sorting algorithms like Merge Sort and Quick Sort have polynomial time
complexities of O(nlog⁡n)O(n \log n)O(nlogn).
o Searching algorithms like Binary Search run in O(log⁡n)O(\log n)O(logn) time.
o Algorithms for basic arithmetic operations like addition or multiplication have
time complexities that are polynomial in terms of the number of digits in the
input.

Understanding whether a problem can be solved in polynomial time helps in distinguishing


tractable (manageable) problems from intractable ones, which is crucial in algorithm design
and optimization.

Deterministic and non-deterministic algorithm:-

1. Deterministic Algorithm:

 Definition: A deterministic algorithm is one where the outcome of the algorithm is


completely determined by the input and the algorithm's logic. For any given input, a
deterministic algorithm will always produce the same output in a predictable amount of
time.
 Characteristics:
o Predictable Execution: Each step follows logically from the previous one
without any randomness or ambiguity.
o Single Path: The algorithm follows one clear path through its execution based on
the input.
o Examples:
 Binary Search: Given a sorted array, it follows a defined sequence of
steps to find an element.
 Sorting Algorithms: Algorithms like Merge Sort and Bubble Sort follow
a set sequence of operations to sort an array.

2. Non-deterministic Algorithm:

 Definition: A non-deterministic algorithm is one where multiple paths can be taken


during its execution. Unlike deterministic algorithms, non-deterministic algorithms may
have different outcomes for the same input, depending on the choices made at various
steps. The algorithm conceptually makes "guesses" at each step and chooses the optimal
path.
 Characteristics:
o Multiple Paths: The algorithm may proceed through various possible paths to
find a solution.
o Conceptual Use: In reality, true non-deterministic algorithms do not exist; they
are theoretical constructs used to study the complexity of problems.
o Non-deterministic Polynomial Time (NP): The class NP includes problems for
which a solution can be verified in polynomial time by a deterministic algorithm.
Non-deterministic algorithms are used to model these problems as if they can
explore all possible solutions simultaneously.
 Examples:
o Nondeterministic Turing Machine: A theoretical model used to study non-
deterministic algorithms. It can explore multiple computation paths at once.
o Decision Problems: Problems such as the Traveling Salesman Problem (TSP)
or Boolean Satisfiability Problem (SAT) are often studied using non-
deterministic algorithms to understand their complexity.

Key Differences:

 Execution Path: Deterministic algorithms follow a single, predictable path, while non-
deterministic algorithms have multiple potential paths.
 Output Consistency: Deterministic algorithms produce the same output for the same
input every time, whereas non-deterministic algorithms can produce different outputs due
to their hypothetical multiple execution paths.
 Practicality: Deterministic algorithms are implementable and practical, whereas non-
deterministic algorithms are mainly theoretical and used for complexity analysis.

Applications and Significance:

 Complexity Classes: The distinction between deterministic and non-deterministic


algorithms is crucial for understanding complexity classes like P and NP. Problems in P
can be solved in polynomial time by deterministic algorithms, while problems in NP can
be verified in polynomial time but may be solved non-deterministically.
 P vs NP Problem: One of the most famous unsolved problems in computer science asks
whether every problem whose solution can be verified in polynomial time (NP) can also
be solved in polynomial time (P). This question explores whether non-deterministic
polynomial-time algorithms have deterministic counterparts.

Definition of NP class Problem: - The set of all decision-based problems came into
the division of NP Problems who can't be solved or produced an output within
polynomial time but verified in the polynomial time. NP class contains P class as a
subset. NP problems being hard to solve.

Definition of Polynomial time: - If we produce an output according to the given input within a
specific amount of time such as within a minute, hours. This is known as Polynomial time.

Definition of Non-Polynomial time: - If we produce an output according to the given input but there
are no time constraints is known as Non-Polynomial time. But yes output will produce but time is not
fixed yet.

Definition of NP-hard class: - Here you to satisfy the following points to come into the
division of NP-hard

1. If we can solve this problem in polynomial time, then we can solve all NP problems in
polynomial time
2. If you convert the issue into one form to another form within the polynomial time

Definition of NP-complete class: - A problem is in NP-complete, if

1. It is in NP
2. It is NP-hard

NP-hard and NP-complete are two important classifications of problems within computational
complexity theory. They describe problems based on their difficulty level in relation to the class
NP.

1. NP-Hard:

 Definition: A problem is said to be NP-hard if it is at least as hard as the hardest


problems in NP. This means that an NP-hard problem does not need to be in NP itself,
so it may not have a solution that can be verified in polynomial time.
 Key Points:
o At Least as Hard as NP: If an NP-hard problem could be solved in polynomial
time, then every problem in NP could also be solved in polynomial time.
o Verification: Unlike NP-complete problems, solutions to NP-hard problems are
not necessarily verifiable in polynomial time.
o Examples:
 Halting Problem: Determining whether a given program will halt or run
forever. This problem is undecidable and is NP-hard but not in NP.
 Optimization Problems: Problems like the Travelling Salesman
Problem (TSP) in its optimization form (finding the minimum path) are
NP-hard.

2. NP-Complete:

 Definition: A problem is NP-complete if it satisfies two conditions:


1. It is in NP (i.e., solutions can be verified in polynomial time).
2. Every problem in NP can be reduced to it in polynomial time.
 Key Points:

o Verification: Solutions to NP-complete problems can be checked for correctness


in polynomial time.
o Hardest in NP: NP-complete problems are the hardest problems within the NP
class. If any NP-complete problem can be solved in polynomial time, then all NP
problems can be solved in polynomial time (i.e., P = NP).
o Reduction: To show a problem is NP-complete, one common method is to
reduce a known NP-complete problem to it in polynomial time. This
demonstrates that the problem is at least as hard as other NP-complete problems.
Examples:
o Boolean Satisfiability Problem (SAT): The problem of determining if there is an
assignment of variables that makes a given boolean formula true.
o Knapsack Problem: The decision version where you need to determine if there is
a subset of items that fits into a knapsack without exceeding the weight limit and
meets a target value.
o Hamiltonian Cycle Problem: Determining if there exists a cycle that visits each
vertex of a graph exactly once.

Relationship Between NP, NP-Complete, and NP-Hard:

 P⊆NP⊆NP-complete⊆NP-hard.
 NP-Complete: A subset of NP that represents the most challenging problems in NP.
These problems are both in NP and as hard as any problem in NP.
 NP-Hard: More general than NP-complete. NP-hard problems can be more complex
and are not required to be in NP, meaning they may not have verifiable solutions in
polynomial time.

How to Classify a Problem:

1. To prove a problem is in NP:


o Show that a proposed solution can be verified in polynomial time.
2. To prove a problem is NP-complete:
o Show that the problem is in NP.
o Show that an existing NP-complete problem can be reduced to this problem in
polynomial time.
3. To prove a problem is NP-hard:
o Show that any problem in NP can be reduced to this problem in polynomial time.
It does not need to be verifiable in polynomial time itself.

Importance of NP-Complete and NP-Hard:

 Research Significance: NP-complete problems are central to the study of the P vs NP


question. If one NP-complete problem is proven to have a polynomial-time solution, all
NP problems would be solvable in polynomial time (implying P = NP).
 Optimization: Many real-world optimization problems are NP-hard. Finding efficient
algorithms or approximations for them is crucial for practical applications in logistics,
scheduling, network design, and more.
 Cryptography: The difficulty of NP-hard problems forms the basis of many
cryptographic systems, which rely on certain problems being intractable for current
algorithms.

Fig: Commonly believed relationship among P vs NP vs NP-Complete.


BOOLEAN SATISFIABILITY (SAT Problem)
The Boolean Satisfiability Problem (SAT) is the problem of determining whether a given
Boolean formula can be made true by assigning appropriate truth values (True or False) to its
variables.

Problem Statement

 Input: A Boolean formula ϕ, typically expressed in Conjunctive Normal Form (CNF).


A CNF formula is a conjunction (AND) of one or more clauses, where each clause is a
disjunction (OR) of literals, and each literal is either a variable or its negation.

Example:

ϕ=(x1∨¬x2)∧(¬x1∨x3)∧(x2∨x3)

Output: True if there exists an assignment of truth values to the variables (x1,x2,…,xn)
such that ϕ evaluates to True. Otherwise, False.

Key Definitions

1. Literal: A Boolean variable (x) or its negation (¬x).


o Example: x1,¬x2
2. Clause: A disjunction (OR) of literals.
o Example: (x1∨¬x2)
3. CNF Formula: A conjunction (AND) of clauses.
o Example: (x1∨¬x2)∧(¬x1∨x3)

Example 1: Simple SAT Instance

Input Formula:
ϕ=(x1∨¬x2)∧(¬x1∨x3)∧(x2∨x3)

Variables:

 x1,x2,x3

Question:

Can we assign truth values to x1,x2,x3 such that ϕTrue?


Solution:

 Try assigning values:


 x1=True,x2=False,x3=True
 Clause 1: (x1∨¬x2)=(True∨True)=True (x1∨¬x2)=(True∨True)=True.
 Clause 2: (¬x1∨x3)=(False∨True)=True (¬x1∨x3)=(False∨True)=True.
 Clause 3: (x2∨x3)=(False∨True)=True (x2∨x3)=(False∨True)=True.

All clauses are satisfied, so ϕ is satisfiable.

Output:

 True.

REDUCIBILITY
Example
COOK’s Theorem
Cook's Theorem is a fundamental result in computational complexity theory. It states that the
Boolean Satisfiability Problem (SAT) is NP-complete, meaning:

1. SAT belongs to the complexity class NPNPNP.


2. Any problem in NPNPNP can be reduced to SAT in polynomial time.

This theorem, proved by Stephen Cook in 1971, laid the foundation for the theory of NP-
completeness, which helps classify problems based on their computational difficulty.

You might also like