Anda di halaman 1dari 13

# DAA QUESTION BANK

UNIT - I
SECTION A

## 1. Write down steps for designing an Algorithm.

2. Explain significance of studying Average –case complexity of an algorithm.
3. How can we modify almost any algorithm to have a good best case running time?
4. Write an algorithm which finds the position of largest and second largest element in an
array A with n>1 elements. Give its complexity.
5. Write an algorithm which finds the number of non zero elements in a two dimensional
array A and give its complexity.
6. Write an algorithm for towers of Hanoi problem and give its complexity.
7. Prove by induction that if n>=10, then 2n>n3.
8. Write an algorithm for factorial of a number and give its complexity.
9. Write an algorithm for Fibonacci series and give its complexity.
10. If f(n)=a0+a1n+a2n2+……………………………….+amnm is any polynomial of degree m then then
prove that f(n)=O(nm)
11. If f(n)=a0+a1n+a2n2+……………………………….+amnm is any polynomial of degree m then then
prove that f(n)=Ω(nm )
12. If f(n)=a0+a1n+a2n2+……………………………….+amnm is any polynomial of degree m then then
prove that f(n)=θ(nm)
13. For any two functions f(n) and g(n), f(n)=θ(g(n)) if f(n)=O(g(n)) and f(n)= Ω (g(n)).
14. (n+a)b =θ(nb ) where b>0, a and b are real constant.
15. Prove that Oθ (g(n))∩ω(g(n)) is empty set.
16. Prove that log n!= θ(n logn)
17. Prove that n!= O(nn)
18. Prove that n!= ω(2n)
19. Let f(n)= n3/2 and g(n)=37n2+12n+17, show that g(n)∈O(f(n)) but f(n)∉O(g(n)),
20. Prove that f(n)=logn is O(nd), for any α>0.
21. Prove that Σni=1 log (i) is θ(n log n).
22. Find the asymptotic notation for the given function f(n) and g(n). Given f(n)=n3/2 , g(n)=n
log2(n)
23. Prove that max (f(n)+g(n))= θ(f(n),g(n))
24. Prove that 3logn+log(logn) is θ(logn)
25. Design an algorithm for finding both the minimum and the maximum elements in an
array A of n elements. Your method should return a pair (a,b), where a is the minimum
element and b is the maximum. What is the running time of your method.
26. For the following program give a Big-O analysis of the running time in terms of n.
a. S=0;
for(i=0; i<n; i++) {
for(j=0; j<n; j++) {
for(k=0; k<n; k++) {
S++;
}
}
}

## b. for(i=0; i<n; i++) {

while(i==n-5){
if (i==10);
i++;
}
}
27. Consider the problem of adding two n-bit binary integers, stored in two n-elements
array A and B. The sum of two integers should be stored in binary form in an (n+1)
element array C. state the problem formally and write pseudo code for adding the two
integers.
28. Consider sorting n numbers stored in array A by first finding the smallest element of A
and exchange it with the element in A[i]. then find the second smallest element of A and
exchange it with A[2]. Continue in this manner for the n-1 elements of A. Write pseudo
code for this algorithm. Give the running time complexity for the above sorting
algorithm in θ-notation.
29. Use mathematical induction to show that when n is an exact power of 2, the solution of
the recurrence

T(n)= { 2 if n=2
2T(n/2)+n if n=2k for k>1

is T(n) =n logn

30. Describe a θ(n log n) time algorithm that gives a set S of n integers and another integer
x, determine whether or not there exist two elements in S whose sum is exactly x.
31. Show that the solution of recurrence relation using substitution method
a. T(n)=T(Γn/2˥)+1 is O(logn)
b. T(n)=2T(Ɩ n/2˩) +n is O(n logn)
c. T(n)=2T(Ɩ n/2˩+17) +n is O(n logn)

## 32. Use a recursion tree to determine solution to the recurrence

a. T(n)=3T(Ɩn/2˩)+n
b. T(n)=T(n/3)+T(2n/3)+cn where c is a constant
c. T(n)=4T(Ɩn/2˩)+cn where c is a constant
d. T(n)=T(n-a)+T(a)+cn where a>=1 and c>0 are constants.
e. T(n)=T(αn)+T((1-α)n)+cn where α is a constant in the range 0<α<1 and c>0 is also
constant.
33. Can the master method be applied to the recurrence T(n)=4T(n/2)+n2logn ? why or why
not ? Give an asymptotic upper bound for this recurrence.
34. Solve the following recurrence relation using master method.
a. T(n)=9T(n/3)+n
b. T(n)=T(2n/3)+1
c. T(n)=3T(n/4)+n logn
d. T(n)=T(√n)+1
e. T(n)=2T(n/4)+√n
f. T(n)=2T(n/4)+n/logn
g. T(n)=4T(n/2)+n2

## 35. Solve the following recurrence relation using iteration method.

a. T(n)=4T(n/2)+n3
b. T(n)=T(n-1)+1/n
c. T(n)=T(n-1)+n
d. T(n)=T(9n/10)+n
e. T(n)=9T(n/3)+n2
f. T(n)=4T(n/2)+n2/√n

36. How can you modify quick sort for searching an element in an array. Write pseudo code
and give its complexity.
37. What are the minimum and maximum numbers of elements in heap of height h ?
38. Show that an n-element heap has height Ɩlogn˩
39. Show that the worst case running time of MAX-HEAPIFY on a heap of size n is Ω(logn)
40. Starting with the procedure MAX-HEAPIFY, write pseudo code for the procedure MIN-
HEAPIFY (A,i), which performs the corresponding manipulation on a min heap.
41. Show that there are at most Γn/2n+1˥ nodes of height h in any n-element heap.
42. Illustrate the operation of HEAP SORT on the array A=<5,13,2,25,7,17,20,8,4>
43. What is the running time of heap sort on an array A of length n that is already sorted in
increasing order ? What about decreasing order.
44. Show that the worst case running time of heap sort is Ω(n logn)
45. The operation HEAP-DELETE (A,i) deletes the item in node i from heap A. Give
implementation of HEAP-DELETE that runs in O(logn) time for an n-element max-heap.
46. Show that the recurrence
T(n)=max (T(q)+T(n-q-1))+θ(n).
0<=q<=n-1

T(n)=Ω(n2)
47. Show that q2+(n-q-1)2 achieve a maximum over q=1,2,----------,n-1 when q=0 or q=n-1
48. What do you mean by stable set. Explain the concept by taking two sorting algorithm.
49. Given n digit numbers in which each digit can take up to k possible values, Radix_SORT
correctly sorts these numbers in θ(d(n+k)) time.
50. Given n b-bit numbers and any positive integer r<=b, RADIX_SORT correctly sorts these
numbers in θ((b/r)(n+2π)) time.
51. Prove that radix sort will take θ(nlogn) time to sort n elements.
52. Prove that the worst case running time of shell sort, using shell’s increments is θ(√2).
53. The worst case running time of shell sort, using Hibbard’s increments is θ(√3/2).
54. Show that the result of running shell sort on the input 9,8,7,6,5,4,3,2,1.
55. How would you implement merge sort without using recursion?
56. Write application of heao sort.
57. Compare different comparison based sorting algorithms.

UNIT - II

1. Prove that a red black tree with n internal nodes has height at most 2log(n+1).
2. Write pseudo code for RIGHT-ROTATE.
3. Show the red black trees that result after successively inserting the keys
I,N,T,R,O,D,U,C,T,I,O,N,A,L,G,O and deleting the keys A,C,T,I,O,N
4. Consider a red black tree formed by inserting n nodes with RB-INSERT. Argue that if n>1,
the tree has at least one red node.
5. Argue that after executing RB-Delete_Fixup, the root of the tree must be black.
6. Give steps that how to augment a data structure.
7. Write application of B-Tree.
8. If n>=1, then for any n-key B-Tree t of height h and minimum degree t>=2,
h<=logt(N+1)/2.
9. Explain the algorithm B-Tree-SPLIT-CHILD(x,i,y).
10. Show the results of inserting the keys
F,S,Q,K,C,L,H,T,V,W,M,R,N,P,A,B,X,Y,D,Z,E in order into an empty B-Tree with minimum
degree 2. Aldo show the result of deleting keys C<P and V.
11. State and prove properties of binomial trees.
12. Prove that the maximum degree of any node in an n-node binomial tree is logn.
13. Explain Binomial _heap-Union procedure using following two heap and Binomial-heap-
delete procedure by deleting key 48.
Heap[H1] 12
7 15 6

25 20 25 18 10 8

31 30 26 16

35

Heap[H2] 20 3 4

44
37 8 29 10

30 23 22 48 31 17

45 32 24 50

55
14. Why don’t we allow a minimum degree of t=1 in B Tree.
15. Show all legal B-trees of degree 2 that represent {1,2,3,4}
16. Find the amortized cost for extracting the minimum In fibinacci heap.
17. What is the amortized time using aggregate for the decreasing key operation.
18. Show the decreasing key operation for the following fig in given sequence:
18.1 Key 46 decreased to key 15.
18.2 Key 35 decreased to key 5.

Min[H] *

7 18 38

*
24 17 23 21 39 41

26 46 30 52

35

19.Delete key 36 from Fibonacci heap H shown below, where ‘*’ shows marked node

Min [H]

25 8 12 2 1 24

* *
20 25 39 26 46

*
34 27 30
35
*
36
20. Prove that amortized cost of FIB-HEAP-UNION.
21. Prove that for all integers k>=1

k
Fk+2=1+Σ i=0 Fi
22.Prove that the linked-list representation of disjoint sets and the weight-union Heuristics, a
sequence of M MAKE-SET, UNION and FIND-SET operations n of which are MAKE-SET
operations, take O(M+nlogn) time.
23.Write a recursive procedure OS-KEY-RANK(T,K) that takes as input an order statics tree T
and a key K and returns the rank of K in the dynamic set represented by T. Assume all the
keys of T are distinct.
24. Using accounting method find the amortized cost for Enqueue and Dequeue operation in a
queue.
25. Find the amortized cost of 8-bit binary counter using aggregate method.
S

UNIT - III

1. Given a sorted array of distinct integer A[1,………….,n], you want to find out whether
there is an index I for A[i]=i. give a divide and conquer algorithm that runs in time
O(logn).
2. You are given two sorted lists of size m and n. Give an O(logn+logn) time algorithm for
computing the kth smallest element in the union of two lists.
3. Design an algorithm that multiply two n-bit integers, in O(n2) time using divide and
conquer technique. Can we improve the algorithm given by you?
4. Multiply two matrix given below using Strassen’s method.

2 6 9 10 8 10 11
3 2 4 6 9 11 9
10 6 8
21 4 12

## 5. Explain optimal reliability allocation problem.

6. Write what do you mean by Convex Hull? Design & Explain Quick Hull algorithm. Derive
efficiency of Quick hull algorithm.
7. Explain Grahm scan algorithm and find its complexity.
8. Prove that if we order the characters in an alphabet so that their frequencies are
monotonically decreasing, then there exists an optimal code whose code word length
are monotonically increasing?
9. Find optimal solution of the following knapsack problem where n=3, W=20
(P1, P2, P3)=(25,24,15) and (W1, W2, W3)=(18,15,20)
10. Show how to solve fractional knapsack problem in θ(n) times.
11. A native Australian named Anatjari wishes to cross a desert carrying only single water
bottle. He has a map that marks all the watering holes along the way. Assuming he can
walk k miles on one bottle of water, design an efficient algorithm for determing where
Anatjari should refill his bottle in order to make as few stops as possible. Argue why
your algorithm is correct.
12. Consider the following graph.

6 5 6
A B C D

1 2 2 5 4 5 7

E F G H
1 3 3

## a. What is the cost of its minimum spanning tree?

b. How many minimum Spanning trees does it have?
c. Suppose Kruskal’s algorithm is run on this graph. In what order are the edges added
to the MST.
13.

1 2 3

4 8 6 6 2 1 4

5 1 1
a. Run Prim’s algorithm, whenever there is a choice of nodes, always use alphabetic
ordering (eg. Start node A) Draw a table showing the intermediate values of the cost
array.
b. Run Kruskal algorithm on the same graph. Show how the disjoint sets data structure
looks at every intermediate stage.
14. Suppose edges X are part of minimum spanning tree of G=(V,E). pich any subset of
nodes S for which X does not cross between S and V-S and let e be the lightest edge
cross this partition. Then prove that X U{e} is part of some MST.
15. Let G=(V,E) be an undirected Graph. Prove that if all its edge weights are distinct, then it
has a unique minimum spanning tree.
16. Show how to find the maximum spanning tree of a graph that is, the spanning tree of
largest total weight.
17. Let T be a MST of graph G. Given a connected sub graph H of G. Show that T∩H is
contained in some MST of H.
18. Suppose Dijkstra’s algorithm is run on the following graph, starting node A. show final
shortest path tree.

1 2 1
A B C D

4 8 6 6 2 1 4

E F G H
5 1 1

19. Find the shortest path using Bellman Ford algorithm from 3 to 1 of the following graph.

a d
2 4 1 2

S C f
-2 -3

3 5 2 1
b e

## 20.Find Shortest path from vertex 1 to 6 using graph shown below.

21
1 2
6 10

5 4 2 -3
6
8
5
3
a.Using Dijkstra Algorithm
b.Using Belman Ford Algorithm

## 21 Prove Kruskal’s algorithm is correct.

22 Prove Prim’s algorithm is correct.
23 How fast is Kruskal algorithm.
24 What do you mean by Greedy-Choice property? Prove that the fractional knapsack
problem has the greedy-choice property?
25 Rewrite Prim’s algorithm under the assumption that the graphs are represented by
adjacency list.

UNIT – IV

## 1. Find optimal solution to the 0/1 Knapsack instant n=7, W=15,

(P1, P2………………… P7)=(10, 5, 15, 7, 6, 18, 3) and
(W1, W2…………… W7)=(2, 3, 5, 7, 1, 4, 1)
2. Write an algorithm (Floyd Warshal) and explain it using following graph. You are also
required to find its complexity

2 3 4
2 6

1
1 6
3 4 7 4

8 6 2
3 5

3. Find the Hamilton Circuit in the following graph using back tracking.
A B C D

I J
H
G F E
L
4. Show how to compute transitive closure of a graph using wareshell’s algorithm for all
pair shortest path.
5. Give a dynamic programming solution for the subset sum problem. Analyze the
complexity of the algorithm.
6. Explain Dynamic programming. Apply it on Matrix –Chain multiplication. Analyze the
complexity of the algorithm. Find Matrix Multiplication for following two matrices

3 8 6 9 8 6 3
3 2 9 4 9 4 2
3 6 4 8 10 7 4
2 5 3

## 7. Run N-Queen algorithm for n=5. Tabulate the no of solutions.

8. Let W={5, 7, 10, 12, 15, 18, 20} and M=35. Find all possible subsets of w that sum to m.
Do this using Sum-of –subset algorithm. Draw the portion of state space tree that is
generated.
9. Prove that the size of the set of all subsets of n elements is d?
10. What do you mean by graph coloring. Explain the algorithm using following graph where
n=3.

A
B E

C D

## 11. Explain Resource allocation problem.

12. Distinguish Divide and Conquer and Dynamic programming approach. Explain assembly
line scheduling using following graph.

7 9 8 3

2 6
2 4 6

2 3 4 2
4

8 2 9 1
13. Find solution of TSP defined by the cost Matrix using LCBB algorithm.

∞ 7 3 12 8
3 ∞ 6 14 9
5 8 ∞ 6 18
9 3 5 ∞ 11
18 14 9 8 ∞
14. Find solution of TSP defined by the edge length Matrix X using Dynamic programming
method approach.

0 10 15 20
5 0 9 10
6 13 0 12
8 8 9 0

15. What do you mean by optimality? When can you use Dynamic programming? Find LCS
of X=<E, X, A, M, P, L, E> Y=<A, P, P, L, E> using dynamic programming approach

UNIT – V

1. Describe the generalization of the FFT procedure to the case in which n is a power of 3.
Give a recurrence for the running time, and solve the recurrence.
2. Show how to implement FFT algorithm with the bit reversal permutation occurring at
the end, rather than at the beginning, of the computation, (Hint-consider the inverse of
DFT
3. Construct the string matching automation for the pattern P=aabab and illustrate its
operation on the text string T=aaababaabaababaab
4. Draw a state transition diagram for a string matching automation for pattern
Ababbabbababbababbabb over the alphabets Σ={a,b}
5. Suppose that all characters in the pattern P are different. Show how to accelerate
NAÏVE-STRING-MATCHER to run in time O(n) on n character text T.
6. State and prove overlapping –Suffix lemma.
7. Working modulo q=11, how many spurious hits does the Rabin Karp matcher encounter
in the text T=3141592653589793 when .looking for a pattern P=26
8. Compute the prefix function π for the pattern ababbabbabbababbabb when the
alphabet is Σ={a,b}. Explain also KMP algorithm.
9. Explain Boyer’s Moore string matching algorithm using text T=010010101101 and
pattern P=01011.
10. Prove that Circuit satisfying problem belongs to the class NP.
11. Prove that Satisfiability Boolean formulas in 3-CNF is NP complete.
12. Prove that the Vertex cover problem is NP complete.
13. Prove that the Traveling Salesman problem is NP complete.
14. Explain and give approximation solution to following
a. The Vertex cover problem
b. The Traveling Salesman problem with triangular inequality.
c. The set covering problem

## 15. Write short notes on following

a. P class & NP class
b. NP complete
c. NP hard
d. Reducibility
e. Randomized Problem