Sie sind auf Seite 1von 78

COMPREHENSIVE VIVA VOCE

Design And Analysis


Of Algorithm

Divide And Conquer


Divideproblem into several smaller subproblems
Normally, the subproblems are similar to the original

Conquerthe subproblems by solving them recursively


Base case: solve small enough problems by brute force

Combinethe solutions to get a solution to the


subproblems
And finally a solution to the orginal problem

Divide and Conquer algorithms are normally recursive

1. Divide and Conquer works on


a)
b)
c)
d)

Top down approach


Bottom up approach
Both
None of these

Ans is A
The solution to atop level instance of
a problem is obtained by going down
and obtaining solutions to smaller
problems.

2. Divide and conquer is efficient for


a)
b)
c)
d)

Sorting kind of problems


Multiplying large numbers
Syntactic analysis
All the above

Ans is D
Sorting merge sort, quicksort
Multiplication - Karatsuba algorithm is
a fast multiplication algorithm,
Strassens multiplication
Syntactic analysis top down parsers
All the above algorithms are designed
using d&c approach

3. The number of comparisons made in


an array containing 1024 entries using
binary search algorithm in the worst
case is
a)
b)
c)
d)

256
512
10
12

Ans is 10
i) Coz, at each iteration half the
number of input is ignored. So it takes
atmost 10 comparisons for the binary
search algorithm to find the value in
an array of size 1024
ii) Yet another way is to substitute the
input size in the time complexity
formulae of BS algorithm(i.e.,
log(1024)=10)

4. What are the correct intermediate


steps of the following data set when it
is being sorted with the Merge sort?
a)
b)
c)
d)

15,18,10,20
15,10,20,18
15,20,10,18
15,20,10,18

-----

10,18,15,20
15,10,18,20
10,15,20,18
15,10,20,18

-----

10,15,18,20
10,15,18,20
10,15,18,20
10,15,20,18

Ans is C

5. Which of the following is False about


merge sort algorithm?
a) It is a comparison sorting algorithm.
b) The unsorted array is divided into sublists,
which are in turn divided into more
sublists.
c) The unsorted array is divided into sublists,
each sublist is then sorted recursively by
re-applying the algorithm.
d) All of the above statements are false

Ans is b

6. An array has indices ranging from x


to x+n; the merge sort would be
applied from c to x+n, where c is
a) is the remainder of x/2, if x is an odd
number
b) is the the non-integer part of x/2
c) is the integer part of x/2
d) is an integer chosen arbitrarily, so long that
it is smaller than x+n

Ans is C

7. In this sequence, 11 4 20 45 32 60
98 70, which element seems to be the
pivot?
a)
b)
c)
d)

70
20
98
4

Ans is B

8. The time complexity of Strassens


multiplication algorithm is
a)
b)
c)
d)

O(n^2.807)
O(n^2.3737)
O(n^3)
None of these

Ans is A

Greedy Method
In a greedy method we attempt to
construct an optimal solution in
stages.

At each stage we make a decision


that appears to be the best (under some
criterion) at the time.
A decision made at one stage is not
changed in a later stage, so each
decision should assure feasibility.

A method that do not guarantee an


optimal solution but help make
decision on local optimum at each
stage hoping to lead to global
optimum is ?
a) Back Tracking
b) Knapsack
c) Greedy Method
d) Divide and Conquer

Ans is C

9. For 0/1 KNAPSACK problem, the algorithm


takes ________ amount of time for memory
table, and ______time to determine the
optimal load, for N objects and W as the
capacity of KNAPSACK.
a)

c)
d)
e)

O(N+W), O(NW)
(NW), O(N+W)
O(N), O(NW)
O(NW), O(N)
O(N+W), O(N+W).

Answer : (b)
i) the memory table ( 2 D matrix )
contains N rows and W columns,
hence it is NW
ii) the composition of the optimal load
takes up to N+W time

10. The optimality condition for 0/1


knapsack problem is
a)
b)
c)
d)

pi xi is maximum
wi xi < c
Both
Only A

Ans is C

11. Identify the MST obtained using prims algorithm

a)
b)
c)
d)

(1,6),(6,5),
(1,6),(6,5),
(1,6),(6,5),
(1,6),(6,5),

(5,4),
(5,7),
(5,7),
(5,4),

(4,3),
(7,2),
(7,4),
(4,7),

(3,2),
(2,3),
(4,3),
(7,2),

(2,
(3,
(3,
(2,

7)
4)
2)
3)

Ans is A

12. Identify the MST obtained using Kruskals algorithm

a) (1,6), (6,5),
b) (1,6), (6,5),
c) (1,6), (3,4),
d) (1,6), (6,5),

(5,4), (4,3), (3,2), (2, 7)


(2,7), (7,3), (3,4), (4, 5)
(2,7), (2,3), (4,5), (5,6).
(5,4), (4,7), (7,2), (2, 3)

Ans is C

13. Dijkstras algorithm may not


terminate if the graph contains
negative-weight edges
True
False

Ans is False
It always terminates, but may
produce incorrect results.

13. BellmanFord algorithm computes


shortest path for graphs with only nonnegative edges
a) True
b) False

Ans is False
BellmanFord is used primarily for
graphs with negative edge weights

14. Which one is true


I.
In the Kruskals algorithm, for the construction of minimal
spanning tree for a graph, the selected edges always form a
forest.
II.
In Prims algorithm, for the construction of minimal spanning
tree for a graph, the selected edges always form an orchard.
III. DFS, BFS algorithms always make use of a queue, and stack
respectively.
(a) Only (I)
(b) Only (II)
(c) Only (III)
(d) Both (I) and (III)
(e) Both (II) and (III)

Answer : (a)
Reason: In the Kruskals algorithm,
for the construction of minimal
spanning tree for a graph, the
selected edges always form a forest.

15. Huffmann tree are used in


a)
b)
c)
d)

Uniform length encoding


Variable length encoding
Compression algorithms
Both b and c

Ans is D

Dynamic Programming
Dynamic programmingis a method for
solving complex problems by breaking them
down into simpler subproblems.
applicable to problems exhibiting the
properties of overlapping subproblems and
optimal substructure
overlapping subproblems means those
problems that can be broken down into subproblems and the solutions for which are reused several times eg., Fibonacci series

Optimal SubStructure means optimal


solution to a problem is obtained by
the combination of optimal solution
to its sub problem
eg., The shortest path between two
vertices also implies the shortest
path between the intermediate
vertices too

16. The problem solving strategy that


finds the optimal solution by keeping
the best solution found up to the point
is called ?
a) Divide and Conquer
b) Greedy Methods
c) Backtracking
d) Dynamic Programming

Ans is D

17. How the Dynamic programming


method differs from greedy method?
a) Decision sequence that has
generated
b) Principle of optimality
c) both a & b
d) none

Ans is A

18. Which among the following


algorithm is used to detect whether a
regular expression is accepted by a
finite machine automata
a) Prims algorithm
b) Kruskals algorithm
c) Bellmann and Ford algorithm
d) Warshalls and Floyd algorithm

Ans is D
Warshall and Floyd algorithm is aka all
pair shortest path algorithm

19. The time complexity of optimal


binary search tree constructed using
dynamic programming is
a) O(n)
b) O(n2)
c) O(n3)
d) none

Ans is C
OBST is an algorithm that is used for
the construction of a tree which has
minimum search cost for each key
node in the tree

20. An O(n^2 2^n) dynamic


programming is for which Problem ?
a) Branch and bound
b) 0/1 Knapsack problem
c) Travelling Salesman problem
d) None

Ans is C

Backtracking
Backtracking is a general algorithm
for finding all (or some) solutions to
some computational problem, that
incrementally builds candidates to the
solutions, and abandons each partial
candidate c ("backtracks") as soon as
it determines that c cannot possibly be
completed to a valid solution

21. Rules that restrict each Xi to take


on values only from a given set is
a)
b)
c)
d)

Implicit constraint
Explicit constraint
both
none

Ans is B

22. Which algorithm determines


solution by systematically searching
the solution space for the given
problem of instance?
a) Backtracking
b) Dynamic programming
c) Branch and bound
d) none

Ans is A

23. The search for backtracking is


facilitated by using ---------- for solution
space
a)
b)
c)
d)

leaf organization
node organization
tree organization
space organization

Ans is C

24. 8 tuples is a solution to which of


the problem?
a) 4 queens
b) traveling salesman
c) 8 queens
d) none

Ans is C

25. Which problem does the following


line belong to?
Given n distinct positive numbers and
we desire to find all combination of
these numbers whose sum is N
a) backtracking
b) traveling salesman
c) sum of subsets
d) graph coloring

Ans is C

26. When a graph G can be colored in


such a way no adjacent nodes have
same color yet only M colors are used.
What problem does the above line
refer?
a) colorability decision
b) colorability optimization
c) both a and b
d) none

Ans is A

27. Which problem asks for smallest


integer m for which the graph can be
colored
a)
b)
c)
d)

colorability decision
colorability optimization
both a and b
none

Ans is B

28. What is the smallest integer


referred to as in graph coloring?
a) colorability decision
b) colorability optimization
c) chromatic number
d) none

Ans is C

29. The solution space for knapsack


problem is
a)2^2
b)2^6
c)2^8
d)2^n

Ans is D

Branch and Bound


Live node is a node that has been
generated but whose children have
not yet been generated.
E-node is a live node whose children
are currently being explored. In other
words, an E-node is a node currently
being expanded.

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.
Branch-and-bound refers to all state space
search methods in which all children of an
E-node are generated before any other
live node can become the E-node.

30. In a 4-queen problem the nodes


not leading to the solution are killed
using which function ?
a) Branching
b) Backtracking
c) Ranking
d) Bounding

Ans is D

31. Knapsack problem is what type of


problem ?
a) Minimisation problem
b) Maximisation problem
c) Optimal problem
d) None

Ans is B

33. In order to use procedure LCBB to


solve Knapsack problem we need to
satisfy which of the following conditions ?
a) the structure of nodes in the state
space tree
b) how to generate the children node
c) how to recognize a solution node
d) all the above

Ans is D

34. In 0/1 Knapsack problem c(X) is


recursively defined to be
min{c(LCHILD(X)), c{RCHILD(X))}
a) feasible leaf node
b) infeasible leaf node
c) nonleaf node
d) none

Ans is C

Das könnte Ihnen auch gefallen