set-d-daa-ct1-qp-solns
set-d-daa-ct1-qp-solns
CO5 2 1 2 1 - - - - 3 - 3 3 1 -
Part - A
(1 x 10 = 10 Marks) Instructions: Answer all
Q. Question M B C P P
No a L O O I
r C
k o
s d
e
1 Correctness of algorithm means 1 1 1 1 1.
a) Algorithm works in linear time 6.
b) Algorithm uses linear space 1
c) Algorithm is efficient
d) Algorithm behaves as expected
2 The objective of time complexity analysis is 1 1 1 1 1.
a) To determine the development time of algorithm 6.
b) To determine the compile time of algorithm 1
c) To determine the running time of algorithm
d) To determine the complexity of conditions in an algorithm
Answer: d) Θ(𝑛)
5 𝑓(𝑛) = 𝑛 is
2 1 1 2 3 1.
2.
a) ( 2) b) 𝑂(log 𝑙𝑜𝑔
𝑂 𝑛 𝑛) c) 𝑂(𝑛) d) 𝑂(1)
2
1
Answer: a) 𝑂(𝑛 )
10 Which technique can be used to obtain the asymptotic running time for a 1 1 2 3 1.
recursive algorithm by direct application without solving recurrences? 7.
a) Master theorem 1
b) Substitution method
c) Recursion tree
d) Mathematical Induction
Part – B
(5 x 4 = 20 Marks) Instructions: Answer All the Questions
11 2
Prove that 3𝑛 + 2𝑛 + 5 ∈ Θ 𝑛
2
( ) 5 2 1 1 1.
2.
1
12 Solve 𝑇(𝑛) = 2 𝑇 ( ) 𝑛
2
+ 𝑛 using recursion tree method (Assume T(1) 5 2 1 1 1.
2.
= 1).
1
13 Illustrate Partition algorithm used in quicksort for the following array: 31, 5 2 2 3 2.
43, 22, 15, 54, 17, 44, 29, 38 (use first element as pivot) 6.
2
Part – C
(2 x 10 = 20 Marks) Instructions: Answer All the Questions
15. Consider the algorithm below: 1 3 1 2 2.
A Algorithm F(A, lo, hi) 0 6.
Begin 2
If hi = lo return A[lo]
Mid = floor( (hi + lo)/2)
X1 = F(A, 1, mid)
X2 = F(A, mid+1, hi)
Return(X1 + X2)
End
(i) Summarize what algorithm F is doing?
(ii) Devise recurrence relations for running time of algorithm F (Assume
inputs which are powers of 2).
(iii) Compute the asymptotic time complexity using substitution method.
OR
15. Vimal works with a detective agency and is need of processing suspect 1 3 1 2 2.
B details in alphabetical order quickly. He has two processes running 0 6.
simultaneously (a) a sorting algorithm that will sort details of suspects and 4
provide them in sorted order (b) a background process that will process
the next suspect in sorted order without waiting for entire sorted list. He is
in need of completing the task non-recursively and quickly.
(i) Recommend the appropriate sorting algorithm for this task.
(ii) Compute the time complexity of this algorithm.
(iii) List the best case, average case, worst case time complexity of this
algorithm.
OR
16. Victory Supermarket has introduced an innovative incentive mechanism 1 3 2 2 2.
B for its sales representatives. Each sales representative has to make Rs X 0 5.
sales in a day. If he or she makes Y sales, then she gets Y – X points for 3
that day. The incentive for the month is determined by the largest
continuous cumulative streak of points (LCCSP) bagged by the sales
representative over the month obtained by summing up a sequence of
consecutive values.
(i) Devise an algorithm to compute the LCCSP for each sales
representative in a month.
(ii) Illustrate how the LCCSP will be computed for the following
sequence: 13, 8, 14, 12, 17, 21, 13, 16, 5 the sales representative is
required to make Rs.15/- each day.