You are on page 1of 5

Qns : 1

 Ans: Precision – the steps are precisely stated(defined).


 Uniqueness – results of each step are uniquely definedand only depend on the
input and the result of the precedingsteps.
 Finiteness – the algorithm stops after a finite number ofinstructions are executed.
 Input – the algorithm receives input.
 Output – the algorithm produces output.
 Generality – the algorithm applies to a set ofinputs.
mcs 031 qns2 image
We introduced Travelling Salesman Problem and discussed Naive and Dynamic Programming
Solutions for the problem in the previous post,. Both of the solutions are infeasible. In fact, there
is no polynomial time solution available for this problem as the problem is a known NP-Hard
problem. There are approximate algorithms to solve the problem though. The approximate
algorithms work only if the problem instance satisfies Triangle-Inequality.

Triangle-Inequality: The least distant path to reach a vertex j from i is always to reach j directly
from i, rather than through some other vertex k (or vertices), i.e., dis(i, j) is always less than or
equal to dis(i, k) + dist(k, j). The Triangle-Inequality holds in many practical situations.

Algorithm:
1) Let 1 be the starting and ending point for salesman.
2) Construct MST from with 1 as root using Prim’s Algorithm.
3) List vertices visited in preorder walk of the constructed MST and add 1 at the end.

Q2 :

Ans :

Q3:

Ans : Multiplication of matrix chain is an optimization problem. Here the goal is find the most
efficient way to multiply the matrices. Matrix multiplication is associative. The problem is to find
the way of matrix multiplication which involves less and easy arithmetic operations. If each way
of multiplication of matrix is verified, it would take a long time and the process will be very slow
when there are many matrices involved.
The solution to this is breaking up the problem into smaller sets of related matrices, so that
solutions of sub problems can be reused.

The dynamic programming algorithm is recursive and is as follows :

1. Split the given matrix expression in to two sub expressions.

2. Calculate the minimum cost of multiplying each sub sequence.

3. Add the costs together, to find it for the whole expression.

4. Repeat the same with the sub sequences and find the minimum cost of computation.

The results of each stage are stored so that they can be reused.

Multiplying of two matrices involves the minimum cost as there is only one way to do it. So, the
sub sequences can be split, until a 2 are left

Read more on Brainly.in - https://brainly.in/question/6765342#readmore

Qns:

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.

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

Qns :

Ans:
Vertex Cover Problem | Set 2 (Dynamic
Programming Solution for Tree)
A vertex cover of an undirected graph is a subset of its vertices such that for every edge (u, v) of
the graph, either ‘u’ or ‘v’ is in vertex cover. Although the name is Vertex Cover, the set covers
all edges of the given graph.
The problem to find minimum size vertex cover of a graph is NP complete. But it can be solved
in polynomial time for trees. In this post a solution for Binary Tree is discussed. The same
solution can be extended for n-ary trees.
For example, consider the following binary tree. The smallest vertex cover is {20, 50, 30} and
size of the vertex cover is 3.

Q: Vertex Cover problem

Ans : A vertex cover of an undirected graph is a subset of its vertices such that for every edge
(u, v) of the graph, either ‘u’ or ‘v’ is in vertex cover. Although the name is Vertex Cover, the set
covers all edges of the given graph. Given an undirected graph, the vertex cover problem is
to find minimum size vertex cover.

Knapsac problem
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given
a set of items, each with a weight and a value, determine the number of each item to include in
a collection so that the total weight is less than or equal to a given limit and the total value is as
large as possible.

Strassen’s algorithm
In linear algebra, the Strassen algorithm, named after Volker Strassen, is an algorithm for
matrix multiplication. It is faster than the standard matrix multiplication algorithm and is useful
in practice for large matrices, but would be slower than the fastest known algorithms for
extremely large matrices.

Dynamic Programming
Dynamic Programming is mainly an optimization over plain recursion. Wherever we see a
recursive solution that has repeated calls for same inputs, we can optimize it using Dynamic
Programming. The idea is to simply store the results of subproblems, so that we do not have to
re-compute them when needed later.

You might also like