Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
36 views38 pages

Introduction To P-NP Class Problems

The document provides an introduction to P and NP problems, classifying them into optimization and decision problems, and discussing polynomial and exponential time algorithms. It explains the concepts of tractability, deterministic and non-deterministic algorithms, and the distinction between P and NP classes. The document concludes with the ongoing debate of whether P equals NP, highlighting the implications of solving NP problems efficiently.

Uploaded by

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

Introduction To P-NP Class Problems

The document provides an introduction to P and NP problems, classifying them into optimization and decision problems, and discussing polynomial and exponential time algorithms. It explains the concepts of tractability, deterministic and non-deterministic algorithms, and the distinction between P and NP classes. The document concludes with the ongoing debate of whether P equals NP, highlighting the implications of solving NP problems efficiently.

Uploaded by

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

Introduction to P, NP problems

and
Non deterministic Algorithms

Dr.V.Sireesha
Asst. Prof., Dept of CSE
Contents
 Problems – Classification
 Polynomial time algorithms
 Exponential time algorithms
 Exponential to Polynomial
 Non-deterministic Algorithms
 P Class
 NP Class
 P vs NP
Problems-Classification
 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

 Decision Problem
Optimization Problem
 Optimization problems are those for which the

objective is to maximize or minimize some

values.

For example,

 Finding the minimum number of colors needed

to color a given graph.

 Finding the shortest path between two vertices

in a 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. For example,
 Whether a given graph can be colored by only
4-colors.
 Finding Hamiltonian cycle in a graph is not a
decision problem, whereas checking a graph is
Hamiltonian or not is a decision problem.
What is Language?
 Every decision problem can have only two
answers, yes or no. Hence, a decision problem
may belong to a language if it provides an
answer ‘yes’ for a specific input. A language is
the totality of inputs for which the answer is
Yes. Most of the algorithms discussed in the
previous units are polynomial time
algorithms.

 For input size n, if worst-case time complexity


of an algorithm is O(nk), where k is a constant,
the algorithm is a polynomial time algorithm.
Tractability
 Some problems are intractable:
as they grow large, we are unable to solve them
in reasonable time

 What constitutes reasonable time?


» Standard working definition: polynomial time
» On an input of size n the worst-case running
time is O(nk) for some constant k
» O(n2), O(n3), O(1), O(n lg n), O(2n), O(nn),
O(n!)
» Polynomial time: O(n2), O(n3), O(1), O(n lg n)
» Not in polynomial time: O(2n), O(nn), O(n!)
Polynomial Time Algorithms

 Linear Search  O(n)


 Binary Search  O(log n)
 Insertion sort  O(n2)
 Merge Sort  O(n log n)
 Matrix multiplication  O(n3)
Algorithms such as Matrix Chain Multiplication, Single
Source Shortest Path, All Pair Shortest Path, Minimum
Spanning Tree, etc. run in polynomial time.
Exponential Time Algorithms
 0/1 Knapsack
 Travelling Salesperson Problem
 Sum of subsets 2 n

 Graph Coloring
 Hamiltonian Cycle
However there are many problems, such as traveling salesperson, optimal
graph coloring, Hamiltonian cycles, finding the longest path in a graph, and
satisfying a Boolean formula, for which no polynomial time algorithms is
known. These problems belong to an interesting class of problems, called
the NP- problems, whose status is unknown.
Exponential Polynomial Time
1.Determine Similarity between the
Exponential time algorithms. If one
problem is solved in polynomial time,
then remaining problems also can be
solved in polynomial time.

2. Write a Non-deterministic algorithm for


solving an exponential time algorithm to
polynomial time algorithm.
Deterministic Algorithms

 Deterministic: The algorithm in which


every operation is uniquely defined is
called deterministic algorithm.

Examples:
 Linear Search
 Binary Search
 Bubble Sort
 Merge Sort
Non-deterministic Algorithms
 The algorithm in which the operations are not
uniquely defined but are limited to specific set of
possibilities for every operation, such an
algorithm is called non-deterministic algorithm.

The non-deterministic algorithms use the


following functions:
1. Choice: Arbitrarily chooses one of the element
from given set.
2. Failure: Indicates an unsuccessful completion
3. Success: Indicates a successful completion
Non-deterministic algorithms
 A non-deterministic algorithm terminates
unsuccessfully if and only if there exists no set
of choices leading to a success. Whenever, there
is a set of choices that leads to a successful
completion, then one such set of choices is
selected and the algorithm terminates
successfully.

 In case of successful completion then the time


required is the minimum number of steps
needed to reach a successful completion of
O(n) where n is the number of inputs.
Non-deterministic algorithms
 The problems that are solved in polynomial time are called
tractable problems and the problems that require super polynomial
time are called non-tractable problems. All deterministic polynomial
time algorithms are tractable and the non-deterministic
polynomials are intractable.

 A nondeterministic algorithm is considered as a superset for


deterministic algorithm i.e., the deterministic algorithms are a
special case of nondeterministic algorithms.
Non-deterministic algorithm-
Search
Non-deterministic algorithm-Sort
Non-deterministic Algorithm-
0/1 Knapsack Problem
Non-deterministic Algorithm-
0/1 Knapsack Problem
Guess What?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P or NP ?
P-CLASS
 The class P consists of those problems that are solvable in
polynomial time, i.e. these problems can be solved in
time O(nk) in worst-case, where k is constant.

 These problems are called tractable, while others are


called intractable or superpolynomial.

 Formally, an algorithm is polynomial time algorithm, if there


exists a polynomial p(n) such that the algorithm can solve
any instance of size n in a time O(p(n)).

 Problem requiring Ω(n50) time to solve are essentially


intractable for large n. Most known polynomial time
algorithm run in time O(nk) for fairly low value of k.


P CLASS
NP-CLASS

 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.
NP CLASS
P vs NP
 Every decision problem that is solvable by a
deterministic polynomial time algorithm is also solvable
by a polynomial time non-deterministic algorithm.

 All problems in P can be solved with polynomial time


algorithms,whereas all problems in NP are intractable.

 It is not known whether P = NP. However, many


problems are known in NP with the property that if
they belong to P, then it can be proved that P = NP.

 The problem belongs to class P if it’s easy to find a


solution for the problem. The problem belongs to NP, if
it’s easy to check a solution that may have been very
tedious to find.
P-NP

You might also like