DAA SET A CT 1 Answer Key
DAA SET A CT 1 Answer Key
SET A
College of Engineering and Technology
School of Computing
SRM Nagar, Kattankulathur – 603203, Chengalpattu District, Tamil Nadu
Academic Year: 2022-23 (EVEN)
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 positive, 1 1 1 1- 1.1,
4,10,1
then which of the following relation holds good? 2
1.3,
a. f(n)=O(g(n)) and g(n) = O(h(n)) then f(n) 2.4,
=O(h(n) 12.2.
b. f(n)=Ω(g(n)) and g(n) = O(h(n)) then f(n) =Ω(h(n) 2
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- 1.1,
4,10,1
2
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- 1.1,
4,10,1
2
1.3,
2.4,
12.2.
2
a. log n
b. log n * n
c. log n + 1
d. n
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
Methodology:
b. nϵ O(n2)
Answer: The given statement implies that
n <=c* n2. This is true n>= n0, where n0 =0 and
c>0. Therefore n ϵ O(n2)
16. Design an algorithm to arrange given integers in an 10 3 2 1- 1.1,
4,10,1
A array with running time complexity in O(nlogn) and 2
1.3,
prove the same. 2.4,
Answer: mergesort( array) 12.2.
If len(array) > 1 Then 2
# This is the point where the array is divided into
two subarrays
halfArray = len(array) / 2
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- 1.1,
4,10,1
B “selection of pivot in Quick sort algorithm affects the 2
1.3,
running time” 2.4,
Answer: 12.2.
The selection of the pivot in the Quick Sort algorithm 2
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.