You are on page 1of 11

DAA Assignment – 17-April-2020

Q1. With help of Venn Diagram Explain commonly believed relationship between P and
NP?

Ans. 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.
The advantages in considering the class of polynomial-time algorithms is that all reasonable deterministic single
processor model of computation can be simulated on each other with at most a polynomial slow-d.

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.

P versus 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 - P 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.
If P ≠ NP, there are problems in NP that are neither in P nor in NP-Complete.
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.

NP (Non-deterministic Polynomial) Problems: A problem is assigned to the NP (nondeterministic polynomial


time) class if it is solvable in polynomial time by a nondeterministic Turing machine.

A P-problem (whose solution time is bounded by a polynomial) is always also NP. If a problem is known to be
NP, and a solution to the problem is somehow known, then demonstrating the correctness of the solution can
always be reduced to a single P (polynomial time) verification. If P and NP are not equivalent, then the solution of
NP-problems requires (in the worst case) an exhaustive search.

Linear programming, long known to be NP and thought not to be P, was shown to be P by L. Khachian in 1979. It
is an important unsolved problem to determine if all apparently NP problems are actually P.
A problem is said to be NP-hard if an algorithm for solving it can be translated into one for solving any other NP-
problem. It is much easier to show that a problem is NP than to show that it is NP-hard. A problem which is both
NP and NP-hard is called an NP-complete problem. An example to illustrate NP-Problem.

n order to solve this entire puzzle, the algorithm would have to check each 3x3 matrix to see which numbers are
missing, then each row, then each column, and then make sure there are no repetitions of any digit from 0–9. This
becomes more complex because the number of digits that are missing is inconsistent in each row, column, and
matrix (i.e. top-left matrix is missing 4 digits while top-right matrix is missing 8 digits). Solving this problem
would not have a polynomial run-time. However, if you were to feed this puzzle with a possible solution, it would
be much less complex to check if there are any repetitions in the rows, columns and matrices. This is a simple
check which would have a polynomial run-time.

Below is a Venn diagram of the different class spaces.


Q2. Define the terms Deterministic algorithm and Non-Deterministic Algorithm?
Ans. Deterministic algorithm: A deterministic algorithm is an algorithm that is purely determined by its inputs,
where no randomness is involved in the model. Deterministic algorithms will always come up with the same
result given the same inputs.

By contrast, probabilistic models include an element of probability. One way to think about probabilistic and
deterministic models is to think about linear programming, where in earlier traditional paradigms, results were
purely deterministic.
More recently, with the development of weighted inputs and various tools, programs can inject an element of
probability into results which often provide sophisticated dynamic results instead of static results that are
associated with purely deterministic algorithms.
If, for example, a machine learning program takes a certain set of inputs and chooses one of a set of array units
based on probability, that action may have to be “verified” by a deterministic model – or the machine will
continue to make these choices and self-analyze to “learn” in the conceptual sense.

Non-Deterministic Algorithm: A non-deterministic algorithm can provide different outputs for the same input
on different executions. Unlike a deterministic algorithm which produces only a single output for the same input
even on different runs, a non-deterministic algorithm travels in various routes to arrive at the different outcomes.

Non-deterministic algorithms are useful for finding approximate solutions, when an exact solution is difficult or
expensive to derive using a deterministic algorithm.
A non-deterministic algorithm is capable of execution on a deterministic computer which has an unlimited
number of parallel processors. A non-deterministic algorithm usually has two phases and output steps. The first
phase is the guessing phase, which makes use of arbitrary characters to run the problem.

The second phase is the verifying phase, which returns true or false for the chosen string. There are many
problems which can be conceptualized with help of non-deterministic algorithms including the unresolved
problem of P vs NP in computing theory.
Q3. Write Non deterministic algorithm for sequential search

Ans. Non-deterministic Algorithms: Let's start with the case where there are no "pick" statements.
A successful branch in a non-deterministic algorithm is some execution of the code with some particular
sequence of choices at the "choose" and "either/or" statements that ends in success (either in the execution of
"succeed" or in reaching the end of the program.) A non-deterministic algorithm succeeds if some branch
succeeds. A non-deterministic algorithm A returns value V if V is returned by some successful branch of A.
(Thus, A can return many different values.) Algorithm A correctly solves problem P if the following holds.

 If A returns V, then V is a solution to P.


 If A returns no value, then P has no solution.

Note that it is not required that A return every possible solution to P.

If there are "pick" statements, the first definitions become a little more involved. Let A be a non-deterministic
algorithm. Let B be a branch of an execution of A up to some execution E of a statement S of the form "pick X
such that Z(X)". A picking strategy Q is a function that maps any such branch B to a value of X that satisfies the
condition in S. any execution of a statement "pick X such that Z(X)" into some particular X such that Z(X). A
successful branch of non-deterministic algorithm A under pick strategy Q is one execution of the code with some
choice of values at the "choose" and "either/or" statements, where the values picked at the execution of pick
statements is governed by Q, that ends in success. Algorithm A succeeds under pick strategy Q if some branch of
A under Q succeeds. Algorithm A returns value V under Q if some successful branch of A under Q returns V.
Algorithm A correctly solves problem P if, for every pick strategy Q, the following conditions hold:

 If A returns V under Q, then V is a solution to P.


 If A returns no value under Q, then P has no solution.

Therefore, an implementation I of non-deterministic algorithm A is correct if it satisfies the following properties:

 If I returns value V, then A returns V.


 If I returns no value, then A returns no value.

Again, it is not required that I find every value returned by A, just that if A finds some value, then I finds some
value.

It follows immediately that if I is a correct implementation of algorithm A and A correctly solves problem P,
then I correctly solves problem P.

Converting a non-deterministic algorithm to code executing DFS: Let S be an instance in the code of the
statement "choose X such that P(X)". Each execution E1 of S is translated an execution of the loop for (X such
that P(X)) do g(X) where g(X) executes all the code that occurs between the execution E1 and the eventual
success or failure. In particular, if S is executed again within the branch following E1 then these further
executions must occur within the function g(X) (which is presumably recursive.)

For instance, the code

while (A) do
{ choose X such that P(X);
B(X);
if (C) then succeed else if (D) then fail;
}
can be implemented as a DFS as follows:

f(X)
{ if (A) {
found := false;
for (X1 such that P(X1)) {
B(X1);
if (C) then found := true;
else if (D) then noop;
else found := f(X1);
if found then exitloop;
}
return(found)
}
}
Q4. define Clique. Explain Cook's Theorem.

Ans. In Clique, every vertex is directly connected to another vertex, and the number of vertices in the Clique
represents the Size of Clique.

In an undirected graph, a clique is a complete sub-graph of the given graph. Complete sub-graph means, all the
vertices of this sub-graph is connected to all other vertices of this sub-graph.

Cook’s Theorem: Stephen Cook presented four theorems in his paper “The Complexity of Theorem Proving
Procedures”. These theorems are stated below. We do understand that many unknown terms are being used in
this chapter, but we don’t have any scope to discuss everything in detail.
Following are the four theorems by Stephen Cook −

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 difficulty): {tautologies}, {DNF tautologies}, D3, {sub-graph pairs}.

Theorem-3:

 For any TQ(k) of type Q, TQ(k)k√(logk)2TQ(k)k(logk)2 is unbounded


 There is a TQ(k) of type Q such that TQ(k)⩽2k(logk)2TQ(k)⩽2k(logk)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 emphasized the significance of polynomial time reducibility. It means that if we have a
polynomial time reduction from one problem to another, this ensures that any polynomial time algorithm
from the second problem can be converted into a corresponding polynomial time algorithm for the first
problem.
 Second, he focused attention on the class NP of decision problems that can be solved in polynomial time
by a non-deterministic computer. Most of the intractable problems belong to this class, NP.
 Third, he proved that one particular problem in NP has the property that every other problem in NP can
be polynomially reduced to it. If the satisfiability problem can be solved with a polynomial time
algorithm, then every problem in NP can also be solved in polynomial time. If any problem in NP is
intractable, then satisfiability problem must be intractable. Thus, satisfiability problem is the hardest
problem in NP.
 Fourth, Cook suggested that other problems in NP might share with the satisfiability problem this
property of being the hardest member of NP.
Q5. Explain the terms NP-Complete And NP- Hard in detail.
Ans. A problem is in the class NPC if it is in NP and is as hard as any problem in NP. 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.

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.

Definition of NP-Completeness

A language B is NP-complete if it satisfies two conditions


 B is in NP
 Every A in NP is polynomial time reducible to B.
If a language satisfies the second property, but not necessarily the first one, the language B is known as NP-
Hard. Informally, a search problem B is NP-Hard if there exists some NP-Complete problem A that Turing
reduces to B.
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 find an efficient algorithm for it. Instead, we can focus on design
approximation algorithm.

NP-Complete Problems: Following are some NP-Complete problems, for which no polynomial time algorithm
is known.

 Determining whether a graph has a Hamiltonian cycle


 Determining whether a Boolean formula is satisfiable, etc.

NP-Hard Problems: The following problems are NP-Hard

 The circuit-satisfiability problem


 Set Cover
 Vertex Cover
 Travelling Salesman Problem
In this context, now we will discuss :
TSP is NP-Complete: The traveling salesman problem consists of a salesman and a set of cities. The salesman
has to visit each one of the cities starting from a certain one and returning to the same city. The challenge of the
problem is that the traveling salesman wants to minimize the total length of the trip

Proof: To prove TSP is NP-Complete, first we have to prove that TSP belongs to NP. In TSP, we find a tour and
check that the tour contains each vertex once. Then the total cost of the edges of the tour is calculated. Finally,
we check if the cost is minimum. This can be completed in polynomial time. Thus, TSP belongs to NP.

Secondly, we have to prove that TSP is NP-hard. To prove this, one way is to show that Hamiltonian cycle
≤p TSP (as we know that the Hamiltonian cycle problem is NPcomplete).
Assume G = (V, E) to be an instance of Hamiltonian cycle.
Hence, an instance of TSP is constructed. We create the complete graph G' = (V, E'), where
E′={(i,j):i,j∈Vandi≠jE′={(i,j):i,j∈Vandi≠j
Thus, the cost function is defined as follows −
t(i,j)={01if(i,j)∈Eotherwiset(i,j)={0if(i,j)∈E1otherwise
Now, suppose that a Hamiltonian cycle h exists in G. It is clear that the cost of each edge in h is 0 in G' as each
edge belongs to E. Therefore, h has a cost of 0 in G'. Thus, if graph G has a Hamiltonian cycle, then
graph G' has a tour of 0 cost.
Conversely, we assume that G' has a tour h' of cost at most 0. The cost of edges in E' are 0 and 1 by definition.
Hence, each edge must have a cost of 0 as the cost of h' is 0. We therefore conclude that h' contains only edges
in E.
We have thus proven that G has a Hamiltonian cycle, if and only if G' has a tour of cost at most 0. TSP is NP-
complete.
Q6. What is satisfiability problem? Under which problem Category it comes?
Ans. The Satisfiability Problem in Propositional Logic (SAT) is a conceptually simple combinatorial decision
problem that plays a prominent role in complexity theory and artificial intelligence. To date, stochastic local
search methods are among the most powerful and successful methods for solving large and hard instances of
SAT. In this chapter, we first give a general introduction to SAT and motivate its relevance to various areas and
applications. Next, we give an overview of some of the most prominent and best-performing classes of SLS
algorithms for SAT, covering algorithms of the GSAT and WalkSAT architectures as well as dynamic local
search algorithms. We discuss important properties of these algorithms – such as the PAC property – and outline
their empirical performance and behavior.

Boolean Satisfiability Problem: Boolean Satisfiability or simply SAT is the problem of determining if a
Boolean formula is satisfiable or unsatisfiable.

 Satisfiable: If the Boolean variables can be assigned values such that the formula turns out to be TRUE,
then we say that the formula is satisfiable.
 Unsatisfiable: If it is not possible to assign such values, then we say that the formula is unsatisfiable.

Examples:
 , is satisfiable, because A = TRUE and B = FALSE makes F = TRUE.
 , is unsatisfiable, because:

Note : Boolean satisfiability problem is NP-complete (For proof, refer lank”>Cook’s Theorem).
Q7. With help of Venn diagram Explain relationship between NP, NP-Complete and NP-
Hard Problems.
Ans. P - Problems that can be solved in polynomial time.

NP - Problems whose solution can be verified in polynomial time.

Therefore, Every P problem is also an NP as every P problem’s solution can also be verified in polynomial time,
but vice-versa is not true because every NP problem cannot be solved in polynomial time.

Now here is the Venn diagram representation of the same,

NP-Hard - If an even harder problem is reducible to all the problems in NP set (at least as hard as any NP-
problem) then that problem is called as NP-hard.

Here is the Venn diagram,

NP-Complete: If an NP-hard problem is inside the set of NP problems then that is NP-complete,
NP - Problems whose solutions can be verified in polynomial time.

NP-complete vs NP-hard:

1. NP-complete: All problems in NP can be translated as a NP-complete problem and NP-complete ⊂ NP.
2. NP-hard: All problems in NP can be translated as a NP-hard problem but NP-hard ⊄ NP or NP ⊄ NP-hard.
3. NP-complete ⊂ NP
4. NP-complete ⊂ NP-hard
5. NP-complete = NP ∩ NP-hard

You might also like