CS2251 Design and Analysis of Algorithms - Question Bank: Unit - I
CS2251 Design and Analysis of Algorithms - Question Bank: Unit - I
com
Part - A
1.
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 a finite amount of time
2.
State the Euclids algorithm for finding GCD of two given numbers.
ALGORITHM Euclid (m, n)
om
a.
c
di
r m mod n
mn
in
in
nr
.k
return m.
4.
5.
6.
7.
3.
Page 1 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
A Pseudo code is a mixture of a natural language and programming language like constructs. A
pseudo code is usually more precise than a natural language, and its usage often yields more succinct
algorithm descriptions.
Define Flowchart.
A method of expressing an algorithm by a collection of connected geometric shapes containing
descriptions of the algorithms steps.
9.
10.
11.
12.
13.
14.
15.
.k
in
in
di
a.
c
om
8.
Ex: if you want to sort a list of numbers in ascending order when the numbers are
given i n descending order. In this running time will be the longest.
16.
Page 2 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
The Best case-Efficiency of an algorithm is its efficiency for the Best-case input of size n, which is an
input(or inputs) of size n for which the algorithm runs the fastest among all possible inputs of that
size.
Ex: if you want to sort a list of numbers in ascending order when the numbers are
given i n ascending order. In this running time will be the smallest.
18.
19.
20.
21.
22.
23.
.k
in
in
di
a.
c
om
17.
Page 3 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
A function t(n) is said to be in O(g(n)) denoted t(n) O (g(n)), if t(n) is bounded above by some
constant multiple of g(n) for all large n, i.e., if there exist some positive constant c and some non
negative integer n0 such that
T (n) < c g (n) for n > n0
24.
Define notation
A function t(n) is said to be in (g(n)), denoted t(n) (g(n)), if t(n) is bounded below by some
positive constant multiple of g(n) for all large n, i.e., if there exist some positive constant c and some
non negative integer n0 such that
T (n) < c g (n) for n > n0
26.
om
25.
a.
c
Define - notation
A function t(n) is said to be in (g(n)), denoted t(n) (g(n)), if t(n) is bounded both above and
below by some positive constant multiples of g(n) for all large n, i.e., if there exist some positive
constant c1 and c2 and some non negative integer n0 such that
c2 g (n) < t (n) < c1 g(n) for n > n0
28.
29.
.k
in
in
di
27.
PART - B
Page 4 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
(b) Explain the various asymptotic notations used in algorithm design. (6)
3. (a) Explain the general framework for analyzing the efficiency of algorithm. (8)
(b) Explain the various Asymptotic efficiencies of an algorithm. (8)
4. (a) Explain the basic efficiency classes. (10)
(b) Explain briefly the concept of algorithmic strategies. (6)
5. Describe briefly the notions of complexity of an algorithm. (16)
(b) Find the complexity C(n) of the algorithm for the worst
om
case,best case and average case.(Evaluate average case complexity for n=3,Where n is the
a.
c
7. Set up & solve a recurrence relation for the number of key comparisons made by above
in
in
di
Part - A
.k
UNIT II
Divide and conquer is probably the best known general algorithm design technique. It work
according to the following general plan
i)A problem's instance is divided into several smaller instances of the same problem, ideally of about
the same size.
ii) The smaller instances are solved
iii) If necessary, the solutions obtained for the smaller instances are combined to get a solution to the
original problem
Page 5 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
4) What can we say about the average case efficiency of binary search?
om
A sophisticated analysis shows that the average number of key comparisons made by binary search
is only slightly smaller than that in the worst case
a.
c
Cavg(n) log2n
in
in
di
A binary tree T is defined as a finite set of nodes that is either empty or consists of s root and two
disjoint binary trees TL, and TR called, respectively the left and right subtree of the root.
.k
Since the binary tree definition itself divides a binary tree into two smaller structures of the same
type, the left subtree and the right subtree, many problems about binary trees can be solved by applying the
divide-conquer technique.
Page 6 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
The Internal Path Length I of an extended binary tree is defined as the sum of the lengths of the paths
- taken over all internal nodes- from the root to each internal node.
om
a.
c
in
in
di
A Spanning Tree of a connected graph is its connected acyclic subgraph(i.e., a tree) that contains all
the vertices of the graph.
.k
A minimum spanning tree of a weighted connected graph is its spanning tree of the smallest weight
,where the weight of a tree is defined as the sum of the weights on all its edges.
A min-heap is a complete binary tree in which every element is less than or equal to its children. All
the principal properties of heaps remain valid for min-heaps, with some obvious modifications.
15) Define Kruskal's Algorithm
Kruskal's algorithm looks at a minimum spanning tree for a weighted connected graph G =(V,E) as an
acyclic subgraph with | V| - 1 edges for which the sum of the edge weights is the smallest.
Page 7 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
algorithm but compares path lengths rather than edge lengths. Dijkstra's algorithm always yields a correct
solution for a graph with nonnegative weights.
Part - B
1) Write a pseudo code for divide & conquer algorithm for merging two sorted arrays in to a single sorted
one.Explain with example. (12)
2) Construct a minimum spanning tree using Kruskals algorithm with your own example. (10)
om
.k
in
in
di
a.
c
5) Define Spanning tree.Discuss design steps in Prims algorithm to construct minimum spanning
UNIT III
Part - A
Dynamic programming is a technique for solving problems with overlapping problems. Typically,
these subproblems arise from a recurrence relating a solution to a given problem with solutions to its smaller
subproblems of the same type. Rather than solving overlapping subproblems again and again, dynamic
programming suggests solving each of the smaller sub problems only once and recording the results in a table
from which we can then obtain a solution to the original problem.
2) Define Binomial Coefficient
Page 8 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
The transitive closure of a directed graph with n vertices can be defined as the n by n Boolean matrix
T = {ti,}, in which the element in the ith row (1<i<n) and the jth column (l<j<n) is 1 if there exists a non trivial
directed path from the ith vertex to jth vertex ; otherwise , tij is 0.
om
a.
c
Given a weighted connected graph (undirected or directed), the all pairs shortest paths problem asks to find
the distances(the lengths of the shortest path) from each vertex to all other vertices.
in
in
di
It is convenient to record the lengths of shortest paths in an n by n matrix D called the distance
matrix: the element dij in the ith row and the jth column of this matrix indicates the length of the shortest path
from the ith vertex to the jth vertex . We can generate the distance matrix with an algorithm that is very similar
to warshall's algorithm. It is called Floyd's algorithm.
.k
It says that an optimal solution to any instance of an optimization problem is composed of optimal
solutions to its subinstances.
Page 9 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
Given n items of known weights w1,w2...........wn and values v1,v2............vn and a knapsack of capacity W,
find the most valuable subset of the items that fit into the knapsack.(Assuming all the weights and the
knapsack's capacity are positive integers the item values do not have to be integers.)
a.
c
om
di
Part - B
in
in
1) Solve the all pair shortest path problem for the diagraph with the weighted matrix given below:abcd
a03
.k
b20
d 6 0(16)
c701
Page 10 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
UNIT IV
Part - A
l) Explain Backtracking
The principal idea is to construct solutions one component at a time and evaluate such partially
constructed candidates as follows.
> If a partially constructed solution can be developed further without violating the problem's constraints, it is
done by taking the first remaininig legitimate option for the next component.
a.
c
om
> If there is no legitimate option for the next component, no alternatives for any remaining component need
to be considered.
di
In this case, the algorithm backtracks to replace the last component of the partially constructed solution with
its next option
in
in
.k
If it is convenient to implement backtracking by constructing a tree of choices being made, the tree is
called a state space tree. Its root represents an initial state before the search for a solution begins.
The problem is to place n queens on an n by n chessboard so that no two queens attack each other by
being in the same row or same column or on the same diagonal.
Page 11 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
om
a.
c
di
in
in
9)Mention two reasons to terminate a search path at the current node in a state-space tree of a branch and
bound algorithm.
.k
The value of the node's bound is not better than the value of the best solution seen so far. The node
represents no feasible solutions because the constraints of the problem are already violated.
Part - B
1. Explain the 8-Queens problem & discuss the possible solutions. (16)
2. Solve the following instance of the knapsack problem by the branch & bound algorithm. (16)
3. Apply backtracking technique to solve the following instance of subset sum problem :
CS2251 - Design and Analysis of Algorithms Question Bank
Page 12 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
a.
c
om
Problems that can be solved in polynomial time are called tractable problems, problems that cannot
be solved in polynomial time are called intractable problems.
in
in
di
A problem's intractability remains the same for all principal models of computations and all
reasonable input encoding schemes for the problem under consideration
.k
Class P is a class of decision problems that can be solved in polynomial time by(deterministic)
algorithms. This class of problems is called polynomial.
If the decision problem cannot be solved in polynomial time, and if the decision problems cannot be
solved at all by any algorithm. Such problems are called Undecidable.
Page 13 of 14
www.vidyarthiplus.com
www.vidyarthiplus.com
om
a.
c
A heuristic is a common-sense rule drawn from experience rather than from a mathematically
proved assertion.
di
Ex: Going to the nearest unvisited city in the traveling salesman problem is a good illustration for
Heuristic
10) Explain NP-Hard problems
in
in
The notion of an NP-hard problem can be defined more formally by extending the notion of polynomial
reducability to problems that are not necessary in class NP including optimization problems.
.k
11)Define Traversals.
When the search necessarilyinvolves the examination of every vertex in the object being searched it
is called a traversal.
Part - B
1. Give a suitable example & explain the Breadth first search & Depth first search. (16)
2. Explain about biconnected components with example.
3. Briefly explain NP-Hard and NP-Completeness with examples.
4. Explain about 0/1 Knapsack Problem using branch and bound with example.
Page 14 of 14
www.vidyarthiplus.com