0% found this document useful (0 votes)
9 views17 pages

Alg IntDecProb - NPC

Uploaded by

227567
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)
9 views17 pages

Alg IntDecProb - NPC

Uploaded by

227567
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/ 17

Decision Problems

Decision Problems- DPm


Yes/No problems

A decision problem is the problem of determining an answer to


a class of Yes/No questions about some objects of interest

Any optimization problem can be restated in a form of decision


problem

Example:
Is the optimal profit of 0/1 knapsack >= v ???
Is the optimal cost of TSP <=D ???
Decision problems- DPm
Decision problems- DPm
• Decision problems can be further be classified
in:
• decidable, where we have a way to solve
them, or
• undecidable, for which there cannot be or has
not been yet discovered a way to solve them.
‫حتمية – احتمالية – كمية ‪ -‬غير حتمية‬
DPRm
• Theory developed in terms of yes/no
problems
Example:
– Independent set
• Given a graph G and an integer K; does G have an
independent set of size at least K?
– Vertex cover
• Given a graph G and an integer K, does the graph have
a vertex cover of size at most K?.
Deterministic and non-Deterministic
• Deterministic: if we can write a computer
program for a decision problem that is Y or N in a
finite time. The output of every problem is
defined uniquely.

• Non-deterministic
The outcome of each operation is not defined
uniquely, but restricted to a set of possibilities.
Can’t be executed on conventional machines ( ‫االت‬
‫)تقليدية‬, but on hypothetical machines ‫أجهزة افتراضية‬
based on the following steps/ points of guessing and
checking
steps/ points of guessing and checking:
1- choice(s): arbitrary chooses one of element of s.
2- failure: signals on unsuccessful completion
3. success: signals on successful completion

Example:
search a target x in unordered array A on n
elements
• Example: search a target x in unordered array A on n
elements

It is required to determine an index j such that A[j]=x or


j=0 if x is ∉ in A

NDet Search (A,n,x)


{
j = choose(1:n)
if (A[j]=x)
then success ……Ɵ(1)
else
failure
}
Non-deterministic sorting
NdetSort(A,n)
{
for i=1 to n
{choice(1:n)→j
B[i]=A[j]
}
for i=1 to n-1
{if (B[i]>B[i+1])
failure
}
success
}
Non-deterministic 0-1 knapsack
Ndetnpk(w,p,n,M)
{
for i=1 to n
x[i]=choice(1:n)

If (∑ xiwi<=M)
i=1->n

then success
else
failure
}
Class P and NP
P:yes/no NP: yes/no problem with a polynomial time checking
P: Polynomial; the set of all decision problems solvable by deterministic algorithm in polynomial time.
O(nk), k:const
That is; Class of problems that can be solved in polynomial time
A polynomial is an expression consisting of variables (like x) raised to non-negative integer powers

NP: set of all decision problems solvable by non-deterministic algorithms in polynomial time and also
verifiable in polynomial time.
• Problems solvable in non-deterministic polynomial time . . .
• Problems where “yes” instances have polynomial time checkable certificates
That is: if we were given somehow a solution (certificate), we could verify that certificate is correct in poly
time.
ie, Hamiltonian path:
Given a sequence <v1,v2,…,v|v|> of |V| vertices,
we can easily check in poly time that (vi, vi+1)ϵ E for =1,2,…, |v|-1 and (v|v|,v1) ϵ E as well.

ie, 3-CNF SAT


Certificate: Assignment of values to variables.
We can check in poly time that the assignment satisfies the Boolean formula.
?
Any problem in P is also NP: why??
Since a problem is in P, then we can solve it in poly
time without even being supplied a certificate. That
is
P is subset of NP.
?
P ⊆ NP, is P a proper subset of NP?? Open
question P ⊂ NP
Is P=NP
Is P≠NP
NP-C
• The problem is in NP-C iff the problem is in NP
and as hard as any problem in NP. (intractable)
(no efficient alg is likely to exist)
• If any problem in NP-C can be solved in poly
time, then every problem in NP has a poly
time alg.
• NP-C are intractable up till now.
P, NP
Classes
1. P Problems (Polynomial Time):
– Sorting: Given a list of elements, arrange them in ascending or descending order.
– Searching: Given a sorted list of elements, determine if a specific element is present in the list.
– Matrix Multiplication: Given two matrices, compute their product.
– Primality Testing: Given an integer, determine whether it is a prime number.
– Shortest Path Problem (Dijkstra's Algorithm): Given a weighted graph, find the shortest path between two
vertices.
– MST
2. NP problems (Nondeterministic Polynomial Time):
– Hamiltonian Path: Given a graph, determine whether there exists a path that visits every vertex exactly
once.
– Traveling Salesman Problem (TSP): Given a list of cities and the distances between each pair of cities,
find the shortest possible route that visits each city exactly once and returns to the original city.
3. NP-complete problems (These are the hardest problems in NP, and if any one of them is solved in
polynomial time, then all NP problems are solvable in polynomial time):
– Knapsack Problem: Given a set of items, each with a weight and a value, determine the maximum value
that can be obtained by selecting a subset of the items such that the total weight does not exceed a given
limit.
– Vertex Cover: Given a graph, find the smallest set of vertices such that every edge in the graph is incident
to at least one vertex in the set.
4. NP-hard problems (These problems are at least as hard as the hardest problems in NP but may not
necessarily be in NP themselves):
– Graph Coloring: Given a graph, assign colors to its vertices such that no two adjacent vertices have the
same color, using the fewest possible colors.

You might also like