CT1-Answer Key Set A DAA
CT1-Answer Key Set A DAA
CO1 2 1 2 1 - - - - 3 - 3 3 1 -
CO2 2 1 2 1 - - - - 3 - 3 3 1 -
CO3 2 1 2 1 - - - - 3 - 3 3 1 -
2 1 2 1 - - - - 3 - 3 3 1 -
CO4
CO5 2 1 2 1 - - - - 3 - 3 3 1 -
Part - A
(1 x 10 = 10 Marks)
Instructions: Answer all
Q. Question Marks BL CO PO PI
No Code
1 Assume that f(n) and g(n) are asymptotically 1 1 1 1-4,10, 1.1,
12
positive, then which of the following relation holds 1.3,
good? 2.4,
a. f(n)=O(g(n)) and g(n) = O(h(n)) then f(n) 12.2.2
=O(h(n)
b. f(n)=Ω(g(n)) and g(n) = O(h(n)) then f(n)
=Ω(h(n)
c. f(n)=Ω(g(n)) and g(n) = ϴ(h(n)) then f(n)
=Ω(h(n)
d. f(n)=O(g(n)) and g(n) = ϴ(h(n)) then f(n)
=Ω(h(n)
2 1 1 1 1-4,10, 1.1,
12
1.3,
2.4,
12.2.2
a. only I
b. only II
c. I or III or IV but not II
d. II or III or IV but not I
3 1 1 1 1-4,10, 1.1,
12
1.3,
2.4,
12.2.2
a. log n
b. log n * n
c. log n + 1
d. n
𝑎
a) T(n) = 𝑂(𝑛 )
b) T(n) = O(nc log n)
c) T(n) = O(f(n))
d) T(n) = O(n2)
8 What is the worst case time complexity of a quick 1 1 2 1-4,10, 1.1,
12
sort algorithm? 1.3,
a) O(N) 2.4,
b) O(N log N) 12.2.2
c) O(N^2)
d) O(log N)
9 What is the optimal time required for solving the 1 1 2 1-4,10, 1.1,
12
closest pair problem using divide and conquer 1.3,
approach? 2.4,
a) O(N) 12.2.2
b) O(log N)
c) O(N log N)
d) O(N^2)
10 What is the runtime efficiency of using brute force 1 1 2 1-4,10, 1.1,
12
technique for the closest pair problem? 1.3,
a) O(N) 2.4,
b) O(N log N) 12.2.2
c) O(N2)
d) O(N3 log N)
Part – B
(5 x 4 = 20 Marks)
Instructions: Answer All the Questions
11 Let t(n)=9n2. Prove that this is of the order of O(n2) 5 2 1 1-4,10, 1.1,
12
Answer: 1.3,
It can be observed from the given relation that, 9n2 2.4,
<=c* n2. This holds good for all values of c greater 12.2.2
than 9. Also, assuming c=9, the given relation holds
good. This is true n>= n0, where n0 =1. Therefore t(n)
ϵ O(n2)
12 Perform the complexity analysis of the following 2.5 2 1 1-4,10, 1.1,
12
algorithm segment. +2.5 1.3,
a) Algorithm Sample() 2.4,
Begin 12.2.2
loop i=1 to n
loop j=1 to m
A(i,j)=0
End loop
End loop
End
Answer :
Ans: O( n X m)
Here, the outer loop runs from 1 to n
In the inner loop runs from 1 to m
b) def fun(N):
for i in range(1,N+1)
j=N
while j>0:
j/=2
13 Compare and contrast Merge sort and Quick sort 5 2 2 1-4,10, 1.1,
12
Similarities: 1.3,
Divide and conquer: Both algorithms divide the input 2.4,
list recursively into smaller sub-lists, sort the 12.2.2
sub-lists, and then merge them back together in the
correct order.
Average time complexity: Both have an average time
complexity of O(n log n), making them efficient for
large datasets.
Differences:
Methodology:
FirstHalf = array[:halfArray]
# The first half of the data set
SecondHalf = array[halfArray:]
# The second half of the data set
k=0
Merge:
merge(FirstHalf, SecondHalf)
# Begin swapping values
While i < len(FirstHalf) and j < len(SecondHalf)
If FirstHalf[i] < SecondHalf[j] Then
array[k] = FirstHalf[i]
i += 1
Else
array[k] = SecondHalf[j]
j += 1
k += 1
EndIf
EndWhile
EndIf
OR
16. Justify the statement with an illustrative example 10 3 2 1-4,10, 1.1,
12
B “selection of pivot in Quick sort algorithm affects the 1.3,
running time” 2.4,
Answer: 12.2.2
The selection of the pivot in the Quick Sort
algorithm indeed has a significant impact on its
running time. Quick Sort works by partitioning an
array around a chosen pivot element, such that all
elements smaller than the pivot are placed before it,
and all elements greater than the pivot are placed
after it. Then, the algorithm recursively sorts the
subarrays created by the partitioning process.
Let's illustrate this with an example: