DAA Question Bank - 2
DAA Question Bank - 2
Introduction
2. What is algorithmic?
The study of algorithms is called algorithmic. It is more than a branch of computer science. It is the
core of computer science and is said to be relevant to most of science, business and technology.
3. What is an algorithm?
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a
required output for any legitimate input in finite amount of time. An algorithm is step by step
procedure to solve a problem.
5. What is the formula used in Euclid’s algorithm for finding the greatest common divisor
of two numbers?
Euclid‘s algorithm is based on repeatedly applying the equality Gcd(m,n)=gcd(n,m mod n) until m
mod n is equal to 0, since gcd(m,0)=m.
6. What are the three different algorithms used to find the gcd of two numbers?
The three algorithms used to find the gcd of two numbers are
Euclid’s algorithm
Consecutive integer checking algorithm
Middle school procedure
9. What is pseudocode?
A pseudocode is a mixture of a natural language and programming language constructs to specify an
algorithm. A pseudocode is more precisethan a natural language and its usage often yields more
concise algorithm descriptions.
7. Define of feasibility
A feasible set (of candidates) is promising if it can be extended to produce not merely a
solution, but an optimal solution to the problem.
8. Define Hamiltonian circuit.
A Hamiltonian circuit is defined as a cycle that passes through all the vertices of the graph exactly
6. Write the difference between the Greedy method and Dynamic programming.
Greedy method
1. Only one sequence of decision is generated.
2. It does not guarantee to give an optimal solution
always. Dynamic programming
1. Many number of decisions are generated.
2. It definitely gives an optimal solution always.
7. What is greedy technique?
Greedy technique suggests a greedy grab of the best alternative available in the hope that a
sequence of locally optimal choices will yield a globally optimal solution to the entire
problem. The choice must be made as follows
Feasible : It has to satisfy the problem’s constraints
Locally optimal : It has to be the best local choice among all feasible choices
available on that step.
Irrevocable : Once made, it cannot be changed on a subsequent step of the algorithm
14. How are the vertices not in the tree split into?
The vertices that are not in the tree are split into two sets
Fringe : It contains the vertices that are not in the tree but are adjacent to atleast one
tree vertex.
Unseen : All other vertices of the graph are called unseen because they are yet to be
affected by the algorithm.
15. What are the operations to be done after identifying a vertex u* to be added to
the tree? After identifying a vertex u* to be added to the tree, the following two
operations need to be performed
Move u* from the set V-VT to the set of tree vertices VT.
For each remaining vertex u in V-VT that is connected to u* by a shorter edge than the
u‘s current distance label, update its labels by u* and the weight of the edge between
u* and u, respectively.
PART - A
Let X be a set of vertices in a network that includes its source but does not include its
sink, and let X, the complement of X, be the rest of the vertices including the sink. The cut
induced by this partition of the vertices is the set of all the edges with a tail in X and a head in
X.
Capacity of a cut is defined as the sum of capacities of the edges that compose the cut.
We‘ll denote a cut and its capacity by C(X,X) and c(X,X)
Note that if all the edges Of a cut were deleted from the
network, there would be no directed path from source to sink
Minimum cut is a cut of the smallest capacity in a given network
17. What is the difference between a stable matching and an unstable matching?
Answer: A stable matching has no blocking pairs, whereas an unstable matching has at least one blocking
pair.
21. What is the difference between maximum matching and maximum cardinality matching?
Both terms are synonymous and refer to a matching with the largest number of edges.
UNIT V
COPING WITH THE LIMITATIONS OF A LGORITHM POWER
PART - A
2. Define Backtracking
Backtracking is used to solve problems with tree structures. Even problems seemingly remote
to trees such as a walking a maze are actually trees when the decision \'back-left-straight-
right\' is considered a node in a tree. The principle idea is to construct solutions one
component at a time and evaluate such partially constructed candidates
3. What is the Aim of Backtracking?
Backtracking is the approach to find a path in a tree. There are several different aims to be achieved :
• just a path
• all paths
• the shortest path
9. Why the search path in a state-space tree of a branch and bound algorithm is
terminated?
The value of the node‘s bound is not better than the value of the best solution.
The node represents no feasible solutions because the constraints of the problem are
already violated
The subset of feasible solutions represented by the node consists of a single point
10.Define Subset-Sum Problem?
This problem find a subset of a given set S={s1,s2,……,sn} of n positive integers whose sum is
equal to a given positive integer d.
18. What is the manner in which the state-space tree for a backtracking algorithm is
constructed?
In the majority of cases, a state-space tree for backtracking algorithm is constructed in the manner of
depth-first search. If the current node is promising, its child is generated by adding the first
remaining legitimate option for the next component of a solution, and the processing moves to this
child.If the current node turns out to be non-promising, the algorithm backtracks to the node‘s parent
to consider the next possible solution to the problem, it either stops or backtracks to continue
searching for other possible solutions.
19. Define the Hamiltonian circuit.
The Hamiltonian is defined as a cycle that passes through all the vertices of the graph exactly once.
It is named after the Irish mathematician Sir William Rowan Hamilton (1805-1865).It is a sequence
of n+1 adjacent vertices vi0, vi1,……, vin-1, vi0 where the first vertex of the sequence is same as
the last one while all the other n-1 vertices are distinct.
20. What are the tricks used to reduce the size of the state-space tree?
The various tricks are
Exploit the symmetry often present in combinatorial problems. So some solutions can be
obtained by
the reflection of others. This cuts the size of the tree by about half.
Pre assign values to one or more components of a solution
Rearranging the data of a given instance.
21. What are the additional features required in branch-and-bound when compared to
backtracking?
Compared to backtracking, branch-and-bound requires:
A way to provide, for every node of a state space tree, a bound on the best value of the
objective function on any solution that can be obtained by adding further components to the
partial solution represented by the node.
The value of the best solution seen so far
27.Give the formula used to find the upper bound for knapsack problem.
A simple way to find the upper bound ‗ub‘ is to add ‗v‘, the total value of the items already
selected, the product of the remaining capacity of the knapsack W-w and the best per unit payoff
among the remaining items, which is vi+1/wi+1
ub = v + (W-w)( vi+1/wi+1)
29.List out the steps of Greedy algorithms for the Knapsack Problem
a) Compare the value to weight ratio
b) Sort the items in nonincreasing order of the ratios
c) If the current item on the list fits into the knapsack place it in the knapsack; otherwise
proceed to the next.
41.Define Heuristic
Generally speaking, a heuristic is a "rule of thumb," or a good guide to follow when making
decisions. In computer science, a heuristic has a similar meaning, but refers specifically to
algorithms.