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

Algorithms - Weekly Test 04 - Test Paper

Uploaded by

Am kae
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Algorithms - Weekly Test 04 - Test Paper

Uploaded by

Am kae
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1

Branch : CSE/IT Batch : Hinglish


WEEKLY TEST – 04
Subject : Algorithms
Topic : Greedy Method
Maximum Marks 15

Q.1 to 4 Carry ONE Mark Each


[MCQ] (a) O(nlogn) (b) O(n)
1. Consider the statements (c) O(n2) (d) None of these
S1: Dijkstra’s algorithm for single source shortest
path is guaranteed to work if there are no negative [MCQ]
cycles. 3. What is the time complexity of Dijkstra’s algorithm in
S2: Prim’s algorithm for MST is guaranteed to case of a sparse directed connected graph represented
produce MST even if there is negative weight cycles. as an adjacency matrix.
(a) O(vlogv) (b) O(Elogv)
(a) only S1 is true (c) O(v )2
(d) None of these
(b) only S2 is true
(c) Both S1 and S2 are true [MCQ]
(d) Neither S1 nor S2 is true 4. What is the time complexity of the job sequencing with
deadline algorithm if greedy method is used?
[MCQ] (a) O(n2) (b) O(nlogn)
2. What is the time complexity of the merge sort (c) O(n) (d) O(n2logn)
algorithm if the array contains more than half of
repeated elements?

Q.5 to 8 Carry TWO Mark Each


[MCQ] [NAT]
5. The profit of the optimal schedule with the following 7. Consider the following Graph G.
jobs and deadlines given below.
Job 1 2 3 4 5 6
Deadline 5 4 4 2 1 2
Profit 15 12 5 15 13 14
What is the total profit?
(a) 58 (b) 59
(c) 60 (d) 61
What is the total number of minimum spanning trees
[MCQ]
possible using prim’s (or) Kruskal’s algorithm?
6. Consider P, Q, R, S which is used to make a text each
occurring with the probability of 0.38, 0.25, 0.08, 0.15, ______
0.14 respectively. Then optimal coding technicians
will have the average length of _______.
(a) 2.21 (b) 2.9
(c) 1.58 (d) 1.69
2

[MCQ] 90, 116, 20, 76, 104, 176, 36


8. Consider a modified version of Quick sort where we quick sort partition algorithm is used by choosing 1st
have an input as an sorted array X[1 ……. n], all elements as pivot, then what is the total number of
element of the array is distinct and n ≥ 3. Pivot is arrangements of integer is possible to preserve the
median of set of 3 elements (first, middle, last). Then
effect of first pass of partition algorithm?
what is the worst-case time complexity of this
algorithm?
(a) O(n2) (b) O(nlogn) 10. [NAT]
(c) O(n2 logn) (d) O(nlog logn) Consider an array X of length n array contains number
between (1 – 10) in any arbitrary order, best sorting
9. [NAT] algorithm takes 325 ns if n = 25, the time required by
Consider the following array with 90 as the first algorithm if n = 150 is ______?
element, all other elements can be in any order.
3

Answer Key
1. (b) 6. (a)
2. (a) 7. (3 to 3)
3. (c) 8. (b)
4. (a) 9. (36 to 36)
5. (d) 10. (1950 to 1950)
4

Hints and Solutions

1. (b) 7. (3 to 3)
S1(False): if there exist any negative weight edges,
then it may or may not work as expected.
S2(True): It is guaranteed to produce the MST even
there exists negative weight cycles.

2. (a)
Irrespective of the elements the time complexity of
merge sort is always O(nlogn)

3. (c)
If the graph is input by adjacency matrix then the T.C
is O(v2) as for each vertex we need to check if it is
connected to all other neighboring vertices.
∴ option (c) is correct.
4. (a) 8. (b)
As we can see that array is sorted, finding first, middle
for Job sequencing algorithm, time required to sort in
and last will take O(1) time and the selected pivot will
order get maximum profit is O(nlogn) find the max
divide the given array in two pards of n/2.
deadline = O(n)
n
For each slot ‘i’ apply linear search to find a job T ( n ) = 2T   + O ( n )
containing deadline ≥ i = O (n2) 2
T(n) = O(nlogn) + O(n) + O(n2) = O(n2) = O (nlogn)

5. (d) 9. (36 to 36)


Time 1 2 3 4 5 First element is chosen as pivot and 90 is first elements,
after 1St pass pivot goes to correct place.
Job J6 J4 J3 J2 J1 Total profit
So, all elements less than 90 go to left of it and greater
Profit 14 15 5 12 15 61
will go to right of pivot.

6. (a)

6 × 6 = 36

10. (1950 to 1950)


We known the range of the elements present in the
array X, so we can use counting sort, which takes O(n)
time
C.n = 325
C.25 = 325
Average length = 0.38 × 1 + 0.25 × 2 + 0.15 × 3 + 0.08 C = 13
× 4 + 0.14 × 4 n = 150
= 0.38 + 0.5 + 0.45 + 0.32 + 0.56 = 2.21 150 × 13 = 1950
❑❑❑
5

For more questions, kindly visit the library section: Link for web: https://smart.link/sdfez8ejd80if

PW Mobile APP: https://smart.link/7wwosivoicgd4

You might also like