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

Unit 5 Tractable and Intractable Problems

Problem unit-5-tractable-and-intractable-problems

Uploaded by

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

Unit 5 Tractable and Intractable Problems

Problem unit-5-tractable-and-intractable-problems

Uploaded by

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

COPYRIGHT © 2021 AKU BTECH BIHAR All rights reserved. visit: https://www.akubtechbihar.

in

DAA

Unit-5

Tractable and Intractable Problems

5.1 Computability of Algorithms

COMPUTABILITY Could the task be computed by an algorithm?

Is the assignment I want impossible?

A di cult mission can be conceived.


ffi
What are the implications for other algorithms?

Computability Vs Complexity

● Computability refers to whether it is possible to test f(n) by


following a set of instructions, not in theory.

● For the moment, we are not worried whether 1,000,000 or more


consecutive steps are required for this measurement.

● The above applies to the uncertainty we will later return to.


5.2 Computability classes – P

● The P class solves the problem of deterministic computation.

● P class is used to solve the problems that are solvable in polynomial


run time.

● The problem belongs to class P if it’s easy to nd a solution for the

fi
problem.

● This problem can be solved by the worst case in O(nK) where k is


constant.

● The problems which are solved by P class are known as tractable


problems and others are known as intractable or superpolynomial.

● If polynomial time is P(n) then the algorithm can solve in time O


(P(n)) with input size n.

● The advantage of the class of polynomial time algorithms is that all


reasonable deterministic single processor models of computation can
be simulated on each other with at most polynomial slow-d.

5.3 NP-class

● The NP class solves the problem of non-deterministic


computation.

● The problem belongs to NP, if it’s easy to check a solution that may
have been very tedious to nd.
fi
● It solves the problem which is veri able by polynomial time.
fi
● It is a class of decision problems.

● For using this class, it is easy to check the correctness of the


claimed answer even if it has extra information added in it.

● Hence it is used to verify the solution is correct, not for nding the
fi
● If there is a problem in this class then it can be solved by exhaustive
search in exponential time.

5.4 NP-complete

● NP complete class is used to solve the problems of no polynomial


time algorithm.

● If a polynomial time algorithm exists for any of these problems, all


problems in NP would be polynomial time solvable. These problems are
called NP-complete.

● The phenomenon of NP-completeness is important for both


theoretical and practical reasons.

● Following are the no polynomial run time algorithm:

Hamiltonian cycles
Optimal graph coloring
Travelling salesman problem
Finding the longest path in graph, etc

Application of NP complete class

Clique

● A clique is a complete sub graph which is made by given undirected


graph.

● All the vertices are connected to each other i.e.one vertex of


undirected graph is connected to all other vertices in graph.

● There is the computational problem in clique where we can nd the


fi
maximum clique of graph this known as max clique.

● Max clique is used in many real world problems and in many


application.
● Assume a social networking where peoples are the vertices and
they all are connected to each other via mutual acquaintance that
becomes edges in graph.

● In the above example clique represents a subset of people who


know each other.

● We can nd max clique by taking one system which inspect all


fi
subsets.

● But the brute force search is too time consuming for a network
which has more than a few dozen vertices present in the graph.

Example:

● Let's take an example where 1, 2, 3, 4, 5, 6 are the vertices that are


connected to each other in an undirected graph.

● Here subgraph contains 2,3,4,6 vertices which form a complete


graph.

● Therefore subgraph is a clique.

● As this is a complete subgraph of a given graph. So it’s a 4-clique.

Analysis of Clique Algorithm

● Non-deterministic algorithms use max clique algorithms to solve


problems.

● In this algorithm we rst nd all the vertices in the given graph.


fi
fi
● Then we check if the graph is complete or not i.e. all vertices should
form a complete graph.

● The no polynomial time deterministic algorithm is used to solve


this problem which is known as NP complete.
2. Vertex Cover

● A vertex-cover of an undirected graph G = (V, E) is a subset of


vertices V' ⊆ V such that if edge (u, v) is an edge of G, then either u in V
or v in V' or both.

● In a given undirected graph we need to nd the maximum size of

fi
vertex cover.

● It is the optimization version of NP complete problems.

● It is easy to nd vertex cover.


fi
Example:

Given graph with set of edges are

{(1,6),(1,2),(1,4),(2,3),(2,4),(6,7),(4,7),(7,8),(3,8),(3,5),(8,5)}

Now, start by selecting an edge (1, 6).

Eliminate all the edges, which are either incident to vertex 1 or 6 and we
add edge (1, 6) to cover.

In the next step, we have chosen another edge (2, 3) at random


Now we select another edge (4, 7).

We select another edge (8, 5).

Hence, the vertex cover of this graph is {1, 2, 4, 5}.

Analysis of Vertex Cover Algorithm

● In this algorithm, by using an adjacency list to represent E it is easy


to see the running time of this algorithm is O (V+E).

5.5 NP-hard

● A problem is in the class NPC if it is in NP and is as hard as any


bl
● A problem is NP-hard if all problems in NP are polynomial time
reducible to it, even though it may not be in NP itself.

● The problem in NP-Hard cannot be solved in polynomial time,


until P = NP.

● If a problem is proved to be NPC, there is no need to waste time on


trying to nd an e cient algorithm for it.
fi
ffi
● Instead, we can focus on design approximation algorithms.

● Following are the NP hard class problems:

Circuit satis ability problem


fi
Set cover
Vertex cover
Travelling salesman problem

5.6 Cook’s theorem

In his paper "The Complexity of Theorem Proving Procedures,"


Stephen Cook proposed four theorems. Below are these theorems
mentioned.

The four theorems by Stephen Cook follow :

Theorem-1

If a set S of strings is accepted by some non-deterministic Turing


machine within polynomial time, then S is P-reducible to {DNF
tautologies}.

Theorem-2
The following sets are P-reducible to each other in pairs (and hence
each has the same polynomial degree of di culty): {tautologies}, {DNF

ffi
tautologies}, D3, {sub-graph pairs}.

Theorem-3

● For any TQ(k) of type Q, is unbounded.

● There is a TQ(k) of type Q such that TQ (K) ≤ 2K(log K)2

Theorem-4

If the set S of strings is accepted by a non-deterministic machine


within time T(n) = 2n, and if TQ(k) is an honest (i.e. real-time
countable) function of type Q, then there is a constant K, so S can be
recognized by a deterministic machine within time TQ(K8n).

● First, he emphasizes the importance of polynomial time


reducibility. This implies that if we have a reduction in polynomial time
from one problem to another, it guarantees that for the rst problem,
fi
every polynomial time algorithm from the second problem can be
translated into a corresponding polynomial time algorithm.

● Second, he centred attention on the class NP of decision problems


that a non-deterministic machine can solve in polynomial time. This
class, NP, belongs to most of the intractable issues.

● Third, he showed that one unique problem in NP has the property


that it can be polynomially reduced to any other problem in NP. If a
l i l ti l ith l th ti f t i bl th
every problem in NP can also be solved in polynomial time. If any NP
problem is intractable, then the problem of satisfaction must be
intractable. Thus, in NP, the most di cult problem is the problem of

ffi
satisfaction.

● Fourth, Cook suggested that NP's other issues could share this
property of being the hardest member of NP with the satisfaction issue.

5.7 Standard NP-complete problems and Reduction techniques

Steps for proving a problems as NP-complete

First, try to prove it to be NP-hard, by :-

Finding a related problem which is already found to be NP-hard


(choosing such a suitable "source" problem close to your "target"
problem, for the purpose of developing poly-trans, is the most
di cult step), and then
ffi
2. Developing a truth-preserving polynomial problem-
transformation from that source problem to your target problem.

Signi cance : if anyone nds a poly algorithm for your “target”


fi
fi
problem, then by using your poly-trans algorithm one would be able to
solve that “source” NP-hard problem in poly-time, or in other words P
would be = NP.
Second, try to prove that the given problem is in NP-class: by
developing a polynomial algorithm for checking any "certi cate" of

fi
any problem-instance.

The class P is the set of decision problems that can be solved in


polynomial time.

P = {L | L ⊆ {0, 1}* and there exists an algorithm A that decides L in


polynomial time}.

Reduction
If the NPC problem solution does not exist, then within the polynomial
era, the conversion from one NPC problem to another NPC problem.
You need the de nition of reduction for this. If within the polynomial
fi
time there is a solution to the one NPC problem, then the rest of the
problem may also give the polynomial time solution (but it is di cult

ffi
to believe). You need the de nition of reduction for this.
fi
Example :

There are two questions, A and B, suppose. You know that solving
problem A in polynomial time is di cult. You want to show that, in
ffi
polynomial time, B can not be solved. Thus, in polynomial time, you
can transform problem A into problem B.

5.8 Approximation algorithms

An Approximate Algorithm is a way of approaching the optimization


problem of NP-COMPLETENESS. This approach does not guarantee the
right solution. The purpose of an approximation algorithm is to get as
which is at the most polynomial moment. These algorithms are called
approximation algorithms or heuristic algorithms.

● The optimization issue is to nd the shortest cycle for the

fi
travelling salesperson problem, and the approximation issue is to nd

fi
a short cycle.

● The optimization problem for the vertex cover problem is nding

fi
the vertex cover with the fewest vertices, and the approximation
problem is nding the vertex cover with the fewest vertices.
fi
An algorithm A is said to be an algorithm, given an optimization
problem P.

Approximation algorithm for P if it returns an approximation


algorithm for any given instance I, approximate solution, that is a
feasible solution.

Types of Approximation

P An optimization problem

A An approximation algorithm

I An instance of P

A∗ (I) Optimal value for the instance I

A(I) Value for the instance I generated by A

Absolute Approximation

● A is an absolute approximation algorithm if a constant k exists.


Such that I, of P, for every case, |A∗ (I) − A(I)| ≤ k.
2. Relative Approximation

● A is a relative approximation algorithm if there exists a constant k

Such that I, of P, for every case,

● Vertex cover

Example :

1. Vertex Cover

2. Traveling Salesman Problem

3. Bin Packing

Key takeaway :

These are e cient algorithms that nd approximate solutions.


ffi
fi
It is used to solve NP hard optimization problems with proof.
It arises into theoretical computer science as consequences of P !=
NP.

5.9 Randomized algorithms

Randomized Algorithms use random numbers in order to decide what


should be the next step to be performed. An example of the random
algorithm can be like suppose there is a group of students in class and a
professor is randomly making a student stand to answer the question.
Randomized algorithms sometimes have deterministic time
complexity. Algorithms like Monte Carlo algorithm use a randomized
approach and its worst case complexity can be easily identi ed,

fi
whereas randomized algorithms like Las Vegas are dependent on the
value of random variables and hence in these algorithms worst case
identi cation becomes tougher.
fi
In order to compute expected time taken in the worst case an time
taken by every possible value needs to be evaluated. Average of all
evaluated times is the expected worst case time complexity

Randomized algorithm are mainly used either to reduce the time


complexity or the space complexity in the given algorithm

Randomized algorithms are classi ed into two categories


fi
Las Vegas: - Lag Vegas algorithms usually produce correct or
optimum results, here the time complexity is based on the random
value and is evaluated as the expected value. An example of the Las
Vegas algorithm is Randomized Quick sort in which the expected
worst case time complexity is O(nlogn). Las Vegas algorithm is a
randomized algorithm that always gives the correct result but
gambles with resources.

Example of Las Vegas

Finding Random point in the circle

It is easy and convenient to nd a random point in the circle using


fi
these approach, here the idea is to rst generate a point(x, y) with -1< x
fi
<1 and -1<y <1. So if the random selected point appear in this unit
circle we keep it else we will throw it and repeat until the point in the
unit circle is found

Algorithm for nding Random point in the circle


fi
funpoint()(x,y oat64)
fl
{

for

{
x=2* rand.Float64()-1

y=2* rand.Float64()-1

if x*x+y*y < 1

Return

2. Monte Carlo: - These algorithms produce the correct or optimum


result on the basis of probability. Monte Carlo algorithm has
deterministic running time and it is generally easier to nd out worst
fi
case time complexity.

For example implementation of Karger’s algorithm produces a


minimum cut with probability greater than or equal to (1/n2) where n is
the number of vertices in Karger’s algorithm and it has the worst case
time complexity as O(E).

Monte Carlo simulations are a broad class of algorithms that use


repeated random sampling to obtain numerical results; these are
generally used to simulate the behavior of other systems.

If a point(x, y) with -1< x <1 and -1<y <1 are placed randomly then the
ratio of points that fall within the unit circle will be close to .

Algorithm to nd a random point in the given circle using Monte Carlo


fi
approach

const a = 99999

count := 0

for i := 0; i <a; i++ {


: a d. oat64()

y := 2*rand.Float64() - 1

if x*x+y*y < 1 {

count++

Key takeaway :

Randomized Algorithms use random numbers in order to decide


what should be the next step to be performed.
Randomized algorithms sometimes have deterministic time
complexity.
Randomized algorithms are mainly used either to reduce the time
complexity or the space complexity in the given algorithm.

References:

Introduction to Algorithms, 4th Edition, Thomas H Cormen,


Charles E Lieserson, Ronald L Rivest and Cli ord Stein,
ff
MITPress/McGraw-Hill.

2. Algorithms—A Creative Approach, 3RD Edition, UdiManber,


Addison-Wesley,

Reading, MA.
Viewed using Just Read

You might also like