0% found this document useful (0 votes)
63 views

Class Test 2018-19: Computer Science & It

CSC Solution

Uploaded by

Abhishek Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Class Test 2018-19: Computer Science & It

CSC Solution

Uploaded by

Abhishek Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Serial : SK1_W_CS_Algorithms_070418

Delhi | Noida | Bhopal | Hyderabad | Jaipur | Lucknow | Indore | Pune | Bhubaneswar | Kolkata | Patna
Web: www.madeeasy.in | E-mail: [email protected] | Ph: 011-45124612

CLASS TEST COMPUTER


2018-19 SCIENCE & IT

Subject : Algorithms
Date of test : 07/04/2018

Answer Key
1. (d) 7. (d) 13. (d) 19. (d) 25. (a)

2. (b) 8. (d) 14. (c) 20. (a) 26. (a)

3. (b) 9. (d) 15. (d) 21. (b) 27. (c)

4. (c) 10. (c) 16. (c) 22. (c) 28. (d)

5. (b) 11. (b) 17. (c) 23. (d) 29. (d)

6. (b) 12. (d) 18. (a) 24. (a) 30. (a)


6 Computer Science & IT

Detailed Explanations

1. (d)
The value of ‘k’ printed is equal to the number of times “k = k+1” is executed.
The outer for loop executes for (log2n+1) = 6 times.
i.e. for a = 1, 2, 4, 8, 16 and 32 (6 times)
The middle loop executes for b = 1, 11, 21, 31 (4 times)
The inner-most loop executes for i = 1, 2, 4, 8, 16, 32 (6 times)
∴ The value of k = 6 × 4 × 6 = 144

2. (b)
It is given that
f(n) = Θ (g (n))
f(n) = c1 ⋅ g (n) ...(1)
It is also given that g(n) = Θ (h (n))
g(n) = c2⋅h (n) ...(2)
Substituting (2) in (1) we get
f(n) = c1⋅ c2 h ⋅ (n)
f(n) = c3⋅h (n)
f(n) = Θ (h (n))
3. (b)
GCD algorithm has worst case time complexity when both P and Q are prime numbers.
The worst case time complexity is O(log2 max(Q, P)).

4. (c)
The following are best case of the sorting algorithms
Insertion sort : O(n)
Quick sort : O(nlogn)
Merge sort : O(nlogn)
Buble sort : O(n2)
Heap sort : O(nlogn)
As we can see insertion sort has most efficient best case.
In heap sorting algorithm we extract the elements one by one. First the smallest (or largest) item is located
and it is separated from the rest, then the next smallest (or next largest) is selected and so on until all
items are separated.
Hence both S1 and S2 are true.

5. (b)

Only these four minimum cost spanning trees are possible.

6. (b)
The following are hamming codes obtained by using hamming code algorithm.
w4 = 0 w3 = 1000
w1 = 11 w5 = 1001
w2 = 101
∴ w3 w1 w2 = 100011101

www.madeeasy.in © Copyright :
CT-2018 | CS • Algorithms 7

7. (d)
The following is the respective expressions for A, B and C.
A : X [m] == Y [n]
B: m
C:m–1

8. (d)
Original sequence: 12, 15, 17, 11, 14, 13
After 1st pass: 12, 15, 11, 14, 13, 17
After 2nd pass: 12, 11, 14, 13, 15, 17
After 3rd pass: 11, 12, 13, 14, 15, 17

9. (d)
The minimum time required is O(K).
Take two variables ‘i’ end ‘j’ such that i = 0 and j = K – 1. ‘i’ moves right until it finds 20 and ‘j’ moves left
until it finds ‘10’. Then both will swap, and procedure continues as long as i < j.
In this way maximum ‘K’ comparisons are required.
Hence it take O(K) time.

10. (c)
In Bellman ford algorithm for every round ‘E’ edges are relaxed.
Each edge relaxation takes constant time. In general there are (V – 1) rounds excluding the verification
round.
Total time = (V – 1) × O(E) × O(1) = O(VE)
But for complete graph E = O(V2)
∴ Total time = O(V3)

11. (b)
Preorder: 51, 28, 17, 5, 13, 35, 30, 45, 89, 66, 53, 78, 94, 93

51 Level 0

28 89 Level 1

17 35 66 94 Level 2

5 53 78 93 Level 3
30 45

13 Level 4

Number of nodes at level 3 = 6

12. (d)
A → E : 3[edge e1]
A → D : 6[edge e3]
A → B : 4[edge e2]
A → C : 9[edge e2, edge e5]
The edges e4, e6, e7 and e8 are never used in any of the shortest paths.

www.madeeasy.in © Copyright :
8 Computer Science & IT

13. (d)
 p1 p2 p3 p7 
 w , w , w ,..., w  = (4, 2, 3.33, 1.142, 5, 6, 2.5)
1 2 3 7

pi
Decreasing order of is x6, x5, x1, x3, x7, x2, x4
wi
pi
Since capacity of bag is 17 we can only add the following items using the ratio.
wi
x6(4) + x5(2) + x1(3) + x3(6) + x7(2)
Total profit = 1 × 24 + 1 × 10 + 1 × 12 + 1 × 20 + 1 × 5
= 24 + 10 + 12 + 20 + 5
= 71 units.

14. (c)

3
The minimum comparisons required are n−2
2

3(20)
∴ − 2 = 28 comparisons
2

15. (d)
Bubble sort takes O(n2) time to sort ‘n’ entries.
T(n) = C1 ⋅ n2
400 = C1 ⋅ (400)2
1/400 = C1
Now 1600 = C1 ⋅ n2
1600 × 400 = n2
800 = n
∴ It can sort 800 entries.

16. (c)
Quick sort is not stable algorithm i.e. if the elements are repeated in the array, their order may or may not
be preserved after the application of quick sort algorithm.
Hence S2 is false.

17. (c)
(log n)200 < 100000 n < n log n < 1/30 n2 < 2n

18. (a)
II, III and IV are not asymptotically tight. They can be expressed with more tightness.
2n = o(n2)
n2 = o(n5)
n4 = ω(n3)
I is already asymptotically tight.

19. (d)
The correct recurrence relation is

 Θ(1) if n = 1
T(n) = 
7T (n / 2) + Θ(n )
2

www.madeeasy.in © Copyright :
CT-2018 | CS • Algorithms 9

20. (a)
Applying Master theorem
Here a = 2, b = 4, d = 1/2
1/2
nlogb a = nlog4 2 = nlog4(4) = n1/2
log a
also f (n) = n1/2 = n b
∴ T(n) = Θ(nlogb a ⋅ logn) (According to case 2 of Master theorem)

= Θ( n logn)

21. (b)
X and Y have LCS’s of length 4. The following are longest common subsequences of X and Y.
〈B, C, B, A〉
〈B, D, A, B〉
Hence (b) is true.

22. (c)
Maximum deadline is 6. Therefore maximum 6 jobs can be scheduled.
The following table shows the completion of tasks according to their deadlines to obtain maximum profit.
J3 J7 J4 J5 J6 J1
15 29 17 16 24 21
1 2 3 4 5 6

Profit = 122.

23. (d)
Dijkstra’s algorithm assumes that all edge weights are non-negative. Because of this negative edge
weight cycles are undetected. Hence Dijkstra’s algorithm is bound to give wrong shortest path whenever
there is a negative weight cycle.
It finds only negative edge weight cycle which are reachable from source.

24. (a)
To create binary tree inoder always neccessory. Here binary search tree is created whose inoder always in
increasing order.
So we can apply binary search i.e. n time binary search that takes n × log n = n log n.
Or
To construct binary search tree when preorder and postorder of the tree is given will take O(n) time.
So best answer will be option (a).

25. (a)
ABC

(AB)C A(BC)
To multiply AB we need 3 × 7 × 2 = 42 multiplications.
(AB)3× 2 ⋅ C2× 9
Further multiplication with C requires 3 × 2 × 9 = 54 Multiplications
∴ Total 54 + 42 = 96 multiplications for (AB)C.
To multiply BC we need 7 × 2 × 9 = 126 multiplications.
A3× 7 (BC)7× 9
Further multiplication with A requires 3 × 7 × 9 = 189 Multiplications
∴ Total 126 + 189 = 315 multiplications for A(BC)
∴ Minimum multiplications required are 96.

www.madeeasy.in © Copyright :
10 Computer Science & IT

26. (a)
1; if (i = 0)
0; if (i > 0 and j = 0)
C(Ai, Bj) =
C(Ai, Bj–1); if (A[i] ≠ B[i]) when elements are not matched.
C(Ai, Bj–1) + C(Ai–1, Bj–1); if (A[i] = B[i]) when elements are matched.

27. (c)
Back edges are those edges connecting a vertex u to an ancestor V in a depth first tree.
A B

C F

D E

There are only 5 back edges.

28. (d)
i j Pivot
Initially 12 18 17 11 13 15 16 14

After completion of partition algorithm


Pivot
14 11 13 12 15 18 16 17

As we can see only 16 do not change its place.


∴ 7 elements changes their place.

29. (d)
A B C

11
F
13 12
16 14
D E

∴ Weight = 13 + 16 + 11 + 14 + 12 = 66

30. (a)
The search key 110 is less than 190. Therefore key 220 to the right of 190 makes this search sequence
invalid.

„„„„

www.madeeasy.in © Copyright :

You might also like