Daa Questions 2020
Daa Questions 2020
Enrolment No:
Instructions:
➢ All Questions are compulsory.
➢ Use of scientific calculator is not permitted.
➢ You are allowed to use rough paper and pen during the exam.
B An algorithm has two phases. The first phase, initialization, takes time O(n2). The
second phase, which is the main computation, takes time O(n log n). What is the most
accurate description of the complexity of the overall algorithm? [1]
(a) O(n log n) (b) O(n2) (c) O(n3log n) (d) O(n2 + nlog n)
C The worst case time complexity of heap sort and Quick sort is
(a) O(nlogn) and O(nlogn) respectively
(b) O(n2) and O(nlogn) respectively [1]
(c) O(nlogn) and O(n2) respectively
(d) O(n2) and O(n2) respectively
D Which of the following statement is not true about binary heap?
(a) Each path from root to a leaf is sorted
(b) A heap is a full binary tree [1]
(c) A heap is a binary tree
(d) A heap is a complete binary tree
I In O-notation, log(2n) is
(a) O(log n) (b) O(log(2n)) (c) O(log2) (d) O(2log n) [1]
c) Verify the correctness of the following algorithm to compute power of a number, i.e.
xn, e.g. x=5, n=3, then xn = 53 = 125.
my_pow_func(x, n)
{ // where x is any real number and n is any integer [5+5+5]
p=1;
for( i = 1; i< n; i++)
p = p * x;
return p;
}
Q4
Consider the following graph.
[7.5+7.5]
b) Use Dijkstras algorithm on the graph below, using vertex S as the source. Write the
vertices in the order which they are traversed and compute all distances at each step.
Q6 [10+5]
a) Give a Backtracking algorithm to solve the n queen problem.
Q7 [15]
Use the Floyd algorithm on the weighted, directed graph in the following figure. Find
the distance matrix D(k) that results for each iteration.