Академический Документы
Профессиональный Документы
Культура Документы
Question Bank
UNIT - I
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 finite amount of time.
2. 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
1. Euclids algorithm
2. Consecutive integer checking algorithm
/
k
t
.
e
b
u
t
e
s
c
/
/
:
p
t
t
h
http://csetube.weebly.com/
/
k
t
3. String processing
.
e
b
4. Graph problems
5. Combinatorial problems
u
t
e
6. Geometric problems
s
c
/
7. Numerical problems
/
:
p
t
t
h
1.The closest pair problem: given n points in a plane find the closest pair among them
2. The convex hull problem: find the smallest convex polygon that would include all the points
of a given set.
8. What is the basic operation of an algorithm and how is it identified?
The most important operation of the algorithm is called the basic operation of the algorithm, the
operation that contributes the most to the total running time. It can be identified easily because it
is usually the most time consuming operation in the algorithms innermost loop.
9. What is the running time of a program implementing the algorithm?
The running time T(n) is given by the following formula
T(n) copC(n)
cop is the time of execution of an algorithms basic operation on a particular computer and C(n)
is the number of times this operation needs to be executed for the particular algorithm.
http://csetube.weebly.com/
/
k
t
The average case efficiency of an algorithm is its efficiency for an average case input of size n. It
provides information about an algorithm behavior on a typical or random input.
.
e
b
In some situations a single operation can be expensive, but the total time for the entire sequence
of n such operations is always significantly better that the worst case efficiency of that single
operation multiplied by n. this is called amortized efficiency.
u
t
e
s
c
/
/
:
p
t
t
h
A function t(n) is said to be in O(g(n)), denoted by 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 exists some positive constant c and
some nonnegative integer n0 such that
T(n) cg(n) for all n n0
16. Define -notation?
A function t(n) is said to be in (g(n)), denoted by t(n) (g(n)), if t(n) is bounded below by
some constant multiple of g(n) for all large n, i.e., if there exists some positive constant c and
some nonnegative integer n0 such that
T(n) cg(n) for all n n0
17. Define -notation?
A function t(n) is said to be in (g(n)), denoted by t(n) (g(n)), if t(n) is bounded both above
& below by some constant multiple of g(n) for all large n, i.e., if there exists some positive
constants c1 & c2 and some nonnegative integer n0 such that c2g(n) t(n) c1g(n) for all n n0
http://csetube.weebly.com/
18. Mention the useful property, which can be applied to the asymptotic notations and its use?
If t1(n) O(g1(n)) and t2(n) O(g2(n)) then t1(n)+t2(n) max {g1(n),g2(n)} this property is also true for
and notations. This property will be useful in analyzing algorithms that comprise o
19. What is the recurrence relation to find out the number of multiplications and
the initial condition for finding the n-th factorial number?
The recurrence relation and initial condition for the number of multiplications Is M(n)=M(n-1)+1
for n>0
M(0)=0f two consecutive executable parts.
20. Write the general plan for analyzing the efficiency for recursive algorithms.
The various steps include ._
/
k
t
.
e
b
u
t
e
s
c
/
/
:
p
t
t
h
http://csetube.weebly.com/
4.Using the recursive algorithm ,explain how the tower of Hanoi problem can be solved. What will be time
a nd space complexity for the algorithms.
5. Explain linear search with example
UNIT-II
1.Give the general plan for divide-and-conquer algorithms.
The general plan is as follows
1. A problems instance is divided into several smaller instances of the same problem, ideally
about the same size
2. The smaller instances are solved, typically recursively
/
k
t
3. If necessary the solutions obtained are combined to get the solution of the original problem
2.What is the general divide-and-conquer recurrence relation?
.
e
b
An instance of size n can be divided into several instances of size n/b, with a of them needing
to be solved. Assuming that size n is a power of b, to simplify the analysis, the following
recurrence for the running time is obtained:
u
t
e
s
c
/
T(n) = aT(n/b)+f(n)
Where f(n) is a function that accounts for the time spent on dividing the problem into smaller
ones and on combining their solutions.
/
:
p
t
t
h
3. Define mergesort.
Mergesort sorts a given array A[0..n-1] by dividing it into two halves a[0..(n/2)-1] and A[n/2..n1] sorting each of them recursively and then merging the two smaller sorted arrays into a single
sorted one.
4. What is the difference between quicksort and mergesort?
Both quicksort and mergesort use the divide-and-conquer technique in which the given array is
partitioned into subarrays and solved. The difference lies in the technique that the arrays are
partitioned. For mergesort the arrays are partitioned according to their position and in quicksort
they are partitioned according to the element values.
5. What is binary search?
Binary search is a remarkably efficient algorithm for searching in a sorted array. It works by
comparing a search key K with the arrays middle element A[m]. if they match the algorithm
http://csetube.weebly.com/
stops; otherwise the same operation is repeated recursively for the first half of the array if K <
A[m] and the second half if K > A[m].
6. What are the classic traversals of a binary tree?
The classic traversals are as follows ._Preorder traversal: the root is visited before left & right
subtrees ._Inorder traversal: the root is visited after visiting left subtree and
before visiting right subtree ._Postorder traversal: the root is visited after visiting the left and
right subtrees
7. what is knapsack problem ?
knapsack problem is a problem in combinatorial optimization: Given a set of items, each with a weight
and a value, determine the count 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. It derives its name from the problem
faced by someone who is constrained by a fixed-size knapsack and must fill it with the most useful items.
/
k
t
8. 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
.
e
b
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
u
t
e
is vi+1/wi+1
s
c
/
ub = v + (W-w)( vi+1/wi+1)
9. What is greedy technique?
/
:
p
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 .
t
t
h
http://csetube.weebly.com/
/
k
t
.
e
b
u
t
e
{
if(a[i] >max) then max: = a[i];
s
c
/
/
:
p
}
}
t
t
h
http://csetube.weebly.com/
/
k
t
T(n) = a
2T (n/2) + n n >1, c a constant
.
e
b
o To solve a problem in an optimal way construct the solution from given set of
u
t
e
candidates.
s
c
/
o As the algorithm proceeds, two other sets get accumulated among this one set
contains the candidates that have been already considered and chosen while
/
:
p
the other set contains the candidates that have been considered but rejected.
t
t
h
http://csetube.weebly.com/
/
k
t
.
e
b
u
t
e
s
c
/
/
:
p
t
t
h
16 MARKS
http://csetube.weebly.com/
merging two sorted arrays into a single sorted one. Explain with an
example. (12)
(b) Setup an solve a recurrence relation for the number of key
comparisons made by the above pseudo code. (4)
6. Explain in detail merge sort. Illustrate the algorithm with a numeric example. Provide
complete analysis of the same
UNIT -III
1.What is the use of TVSP?
In places where the loss exceeds the tolerance level boosters have to the
/
k
t
placed. Given a network and loss tolerance level the tree vertex splitting problems is
.
e
b
u
t
e
s
c
/
/
:
p
t
t
h
W is more commonly denoted as w (i,j) which is the weight of the edge <i,j> _E.
http://csetube.weebly.com/
5. Write the difference between the Greedy method and Dynamic programming.
Greedy method Dynamic programming
Only one sequence of decision is Many number of decisions are
generated. generated1.
/
k
t
.
e
b
u
t
e
s
c
/
/
:
p
t
t
h
their values.
considered.
http://csetube.weebly.com/
/
k
t
.
e
b
to decide the value of xi for 1<i<n. First we make a decision on x1 and then on x2
and so on. An optimal sequence of decisions maximizes the object function Spi xi.
u
t
e
s
c
/
/
:
p
decide which vertex should be the second, which is the third, which is the fourth, and
t
t
h
so on, until vertex j is reached. An optimal sequence of decisions is one that results
in a path of least length.
13. What is the formula to calculate optimal solution in 0/1 knapsack problem?
http://csetube.weebly.com/
assembly line.
/
k
t
15. Give the time complexity and space complexity of traveling salesperson
problem.
.
e
b
u
t
e
s
c
/
The finish time fi (S) of job i is the time at which all tasks of job i have been
/
:
p
t
t
h
http://csetube.weebly.com/
16MARKS
1.How will you construct a optimal search tree with example. (16)
.
e
b
/
k
t
u
t
e
4. Describe the Traveling salesman problem & discuss how to solve it usingDynamic Programming(16)
s
c
/
5. Solve the all-pairs shorest path problem for the digraph with any example?
/
:
p
tt
UNIT IV
1.,What are the factors that influence the efficiency of the backtracking algorithm?
The efficiency of the backtracking algorithm depends on the following four
factors. They are:
i. The time needed to generate the next xk
ii. The number of xk satisfying the explicit constraints.
iii. The time for the bounding functions Bk
iv. The number of xk satisfying the Bk.
2.Define Branch-and-Bound method.
The term Branch-and-Bound refers to all the state space methods in which all
http://csetube.weebly.com/
children of the E-node are generated before any other live node can become the E- node.
3.What are the searching techniques that are commonly used in Branch-and-Bound
method.
The searching techniques that are commonly used in Branch-and-Bound method
are:
i. FIFO
ii. LIFO
iii. LC
iv. Heuristic search
4.State 8 Queens problem.
/
k
t
attack that is, so that no two of them are on the same row, column or on the diagonal.
.
e
b
Given n distinct positive numbers usually called as weights , the problem calls for finding all
the combinations of these numbers whose sums are m.
u
t
e
s
c
/
Let G be a graph and m be a given positive integer. We want to discover whether the nodes of
/
:
p
G can be colored in such a way that no two adjacent nodes have the same color yet only m
colors are used.
t
t
h
8.Define Backtracking.
Backtracking is to build up the solution vector one component at a time and to use
modified criterion function Pi(x1,..,xi) (sometimes called bounding function) to test whether
the vector being formed has any chance of success. Desired solution expressed as an ntuple
(x1,x2,,xn) where xi are chosen from some set Si.
If |Si|=mi, m=m1m2..mn candidates are possible
http://csetube.weebly.com/
/
k
t
.
e
b
-Queens problem
u
t
e
-Sum problem
s
c
/
/
:
p
t
t
h
http://csetube.weebly.com/
I
constraints
xi >= 0, or Si = {all nonnegative real numbers}
xi = {0, 1} or Si = { 0, 1 }
li <= xi <= ui or Si = {a : li
/
k
t
.
e
b
Suppose we are given a graph G = (V,E) that is undirected. We say that a path v1, v2. . .
u
t
e
vn is a Hamiltonian path if every vertex of the graph occurs exactly once in this path.
Moreover, if the last vertex of the path duplicates the first one without ever repeating any
s
c
/
/
:
p
Solution state:
t
t
h
http://csetube.weebly.com/
/
k
t
Promising Node:
.
e
b
u
t
e
s
c
/
/
:
p
t
t
h
18. How can you represent the solution for 8 queens problem?
All solutions represented as 8-tuples (x1, x2,, x8) where xi is the column on which
queen i is placed.
Constraints are,
Explicit constraints
Si={1,2,,8}
Implicit constraints
1. No two xis can be the same column or row (By this, solution space
http://csetube.weebly.com/
/
k
t
and (24, 7)
.
e
b
The solution vectors can also be represented by the indices of the numbers as (1, 2, 4)
and (3, 4)
u
t
e
s
c
/
/
:
p
16 MARKS
t
t
h
http://csetube.weebly.com/
UNIT-V
1. Define graph traversal.
/
k
t
.
e
b
systematically searching the graph G for vertices that can be reached from V.
u
t
e
It starts at initial vertex and visits each and every vertex exactly once and finally reaches
s
c
/
end vertex.
/
:
p
t
t
h
http://csetube.weebly.com/
(i)
(ii)If the graph is represented by adjacency List: O (|V|+ |E| ).
e search terminates when all reached vertices have been fully explored.
/
k
t
(i)
.
e
b
(ii)
7.Define connected component.
u
t
e
(i)
s
c
/
path from U to V.
(ii)
/
:
p
t
t
h
nimal sub graph, G', of G such that V (G') = V (G) and G' is
connected
(ii)
(iii)
http://csetube.weebly.com/
/
k
t
.
e
b
Branch-and-bound refers to all state space search methods in which all children of an Enode
u
t
e
are generated before any other live node can become the E-node.
s
c
/
/
:
p
t
t
h
(ii)E-node is a live node whose children are currently being explored. In other words,
an E-node is a node currently being expanded.
(iii)Dead node is a generated node that is not to be expanded or explored any further.
All children of a dead node have already been expanded.
14.What are the types search strategies in branch and bound?
(i)
(ii)
(iii)
http://csetube.weebly.com/
(i)
(ii)
(iii)
(iv)
17. What are the two classes of non polynomial time problems?
/
k
t
(i)NP- hard
(ii)
.
e
b
-complete
u
t
e
s
c
/
(i)
(ii)
(iii)
/
:
p
t
t
h
Let g(x) be an estimate of the additional effort needed to reach an answer from node x, x
is assigned a rank using a function c (.) such that
^c (x) = f(h(x)) + g(x)
Where h(x) is the cost of reaching x from root and f (.) is any non decreasing function.
20.What is meant by class P (Polynomial)?
Class P consists of problems whose solutions are bounded by the polynomial of small
degree. Examples are Binary search O(log n), sorting O(n log n), and matrix
multiplication 0(n 2.81).
http://csetube.weebly.com/
16 MARKS
1. Define spanning tree? Discuss the design steps in prims algorithm to construct
minimum spanning tree with example. (16)
2. Explain the method of binding the minimum spanning tree for a connected graph
using prims algorithm. (16)
3. Define spanning tree? Discuss the design steps in kruskal algorithm to construct
minimum spanning tree with example (16)
4. Compare and contrast the depth first search and birth first search. How do they fit
in to the decrease and conquer strategies. (16)
5. Explain NP-hard and NP complete problems with example. (16)
/
k
t
.
e
b
(16)
7. Give a suitable example and explain the birth first search and depth first search
u
t
e
algorithm. (16)
s
c
/
/
:
p
t
t
h
http://csetube.weebly.com/