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

Complexity Classes

The document discusses complexity classes in computer science, focusing on tractable (polynomial-time) and intractable (non-polynomial time) problems. It introduces the complexity classes P and NP, explaining their definitions and the relationship between them, including NP-hard and NP-complete problems. The document emphasizes the significance of decision problems and the ongoing research efforts to determine whether P equals NP or not.

Uploaded by

yashg8883
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Complexity Classes

The document discusses complexity classes in computer science, focusing on tractable (polynomial-time) and intractable (non-polynomial time) problems. It introduces the complexity classes P and NP, explaining their definitions and the relationship between them, including NP-hard and NP-complete problems. The document emphasizes the significance of decision problems and the ongoing research efforts to determine whether P equals NP or not.

Uploaded by

yashg8883
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Complexity Classes

Introduction – Complexity
Classes
• For some problems there are known polynomial-time algorithms;
• For others, we have proofs that no polynomial-time algorithm can exist;
• But for others, we have only exponential-time algorithms but no proof that no
polynomial-time algorithm can exist.
• Despite the holes in our knowledge, Computer Scientists have made some
progress.
• Computer Scientists have been able to find relationships between some of the
third kind of problem. – E.g. They have been able to show that some problems
are, in some sense, equivalent in complexity. (They do this using reductions.)
• This isn’t as good as closing the gap for these problems.
• But it is significant because all these problems will stand or fall together, which
makes them particularly worthy of further research effort.
2
Tractable vs. Intractable Problems or
Polynomial time vs Non-polynomial time problem

• Tractable Problem/Polynomial time Problem: a problem that is


solvable by a polynomial-time algorithm. The upper bound is
polynomial.
• Intractable Problem/Non-polynomial time Problem : a problem that
cannot be solved by a polynomial-time algorithm. The lower bound is
exponential.

3
Introduction Contd…
• In Computer Science, many problems are solved where the
objective is to maximize or minimize some values, whereas in
other problems we try to find whether there is a solution or
not. Hence, the problems can be categorized as follows −
• Optimization Problem - Optimization problems are those for
which the objective is to maximize or minimize some values.
(e.g.) Finding the minimum number of colors needed to color a
given graph.
• Decision Problem - There are many problems for which the
answer is a Yes or a No. These types of problems are known
as decision problems. .(e.g.) whether a given graph can be
colored by only 4-colors.
Decision Problems
• Researchers who work in Complexity Theory often concentrate on
decision problems.
• A decision problem is one whose return values are either YES or NO
(or true or false, or 0 or 1).
• Why concentrate on these—
• For many non-decision problems, there are related decision
problems. E.g. the TSP Search and Decision Problems. A non-
decision problem (such as the TSP Search Problem) can often be
turned into a decision problem by introducing a parameter k and
asking if there is an answer that costs at least or at most k.
5
• NOTE- Suppose you’ve a decision problem and an algorithm A that
solves that decision problem.
• We’ll say that algorithm A accepts input x if it returns YES.
• We’ll say that algorithm A rejects input x if it returns NO.

6
The Complexity Class P
• Definition: The complexity class P is the set of all decision problems that can
be solved with worst-case polynomial time-complexity.
• In other words, a problem is in the class P if it is a decision problem and there
exists an algorithm that solves any instance of size n in O(n k ) time, for some
integer k.
• So P is just the set of tractable decision problems: the decision problems for
which we have polynomial-time algorithms.

7
The Complexity Class NP
• The second class of decision problems that we look at is called NP,
which stands for non-deterministically polynomial.
• The definition of NP involves the idea of a non-deterministic
algorithm.
• Definition: The complexity class NP is the set of all decision problems
that can be non-deterministically accepted in worst-case polynomial
time.

8
Deterministic and non-deterministic
algorithms
A deterministic algorithm is one where, given a particular
input, the algorithm will always produce the same output and
follow the same sequence of states. It operates under the
principle of predictability and consistency. The outcome of a
deterministic algorithm can be precisely determined based on
its input.

A non-deterministic algorithm is one where the same


input can lead to multiple possible outcomes. Unlike
deterministic algorithms, these do not follow a single clear
path through execution. Instead, they explore various paths or
possibilities, often simultaneously.
9
Aspect Deterministic Algorithms Non-Deterministic Algorithms
Outcome Produce the same output for a given
Can produce different outputs for the same input.
Predictability input.
Execution Follow a single, clear path through Explore multiple paths, often simultaneously.
Path execution.
Randomness No element of randomness. Often involve randomness or probability.
Testing and Easier to test and verify due to Testing can be more challenging due to variability
Verification predictability. in outcomes.
Generally simpler and more Tend to be more complex due to multiple possible
Complexity
straightforward. paths.
Easier to optimize as the execution path Optimization can be more challenging but offers
Optimization
is predictable. exploration of multiple solutions.
Sorting, searching, mathematical
Applications calculations, data compression, Machine learning, heuristic search, randomized
cryptography. algorithms, certain cryptographic protocols.

Consistency, ease of testing, Handling ambiguity, exploring multiple solutions,


Advantages straightforward optimization, simplicity potentially faster in certain tasks, adaptability,
in implementation. creativity.
Example of a non deterministic algorithm

Some of the terms related to the non-deterministic algorithm are defined below:
• choice(X): chooses any value randomly from the set X.
• failure(): denotes the unsuccessful solution.
• success(): The solution is successful and the current thread terminates.

// The problem is to search for an element x //


// Output j such that A(j) =x; or j=0 if x is not in A //
j →choice (1 :n )
if A(j) =x then print(j) ; success endif
print (‘0’) ; failure
Complexity 0(1)

11
P ⊆ NP

The definition of NP allows for the inclusion of problems that may not be in P. But it may turn out that
there are no such problems and that P = NP. We don’t know which of these is the case. We know P ⊆
NP. But we don’t know whether P ⊂ NP or P = NP. The problems that are in NP but not in P are ones
that we’re not sure about: –
•There is no known polynomial-time algorithm;

•So is P = NP or is P ≠ NP(i.e. P ⊂ NP?) , still is an unresolved issue


•But no proof of intractability

12
P vs NP ??
So there are two possibilities

OR

But this gives Computer Scientists a clear line of attack. It makes sense to focus
efforts on the NP-complete problems: they all stand or fall together.

For curious bunch, check this:

https://youtu.be/pQsdygaYcE4?si=9sqVxqDNOV5JDN9R

13
NP-Hard Problems
• We say that a decision problem Pi is NP-hard if every problem in NP is polynomial
time reducible to Pi .
• In symbols,
• Pi is NP-hard if, for every Pj ∈ NP,
Pj → Pi , in polynomial time.
• Note that this doesn’t require Pi to be in NP.
• Highly informally, it means that Pi is ‘as hard as’ all the problems in NP.
• If Pi can be solved in polynomial-time, then so can all problems in NP.
• Equivalently, if any problem in NP is ever proved intractable (i.e. no proof that
there cannot be a polynomial-time algorithm), then Pi must also be intractable.14
NP-Complete Problems
• We say that a decision problem Pi is NP-complete if
• – it is NP-hard and
• – it is also in the class NP itself.
• In symbols, Pi is NP-complete if Pi is NP-hard and Pi ∈ NP
• Highly informally, it means that Pi is one of the hardest problems in
NP.

15
NP-Complete Problems
• So the NP-complete problems form a set of problems that may or may not be
intractable but, whether intractable or not, are all, in some sense, of equivalent
complexity.
• If anyone ever shows that an NP-complete problem is tractable, then
• – every NP-complete problem is also tractable
• – indeed, every problem in NP is tractable and so
P = NP.

NP-complete problem is also intractable and, of course, P ≠ NP.


• If anyone ever shows that an NP-complete problem is intractable, then – every

16
• The list below contains some well-known problems that are NP-complete when expressed as
decision problems.

 Boolean satisfiability problem (SAT)


 Knapsack problem
 Hamiltonian path problem
 Travelling salesman problem (decision version)
 Subgraph isomorphism problem
 Subset sum problem
 Clique problem
 Vertex cover problem
 Independent set problem
 Dominating set problem
 Graph coloring problem
17
18

You might also like