ASA Mcqs 2
ASA Mcqs 2
ASA Mcqs 2
Q 1 What is recurrence for worst case of Quick Sort and what is the time complexity
in Worst case?
Answer-B
Q2. Suppose we have a O(n) time algorithm that finds median of an unsorted array.
Now consider a QuickSort implementation where we first find median using the
above algorithm, then use median as pivot. What will be the worst case time
complexity of this modified QuickSort.
A O(n^2 Logn)
B O(n^2)
D O(nLogn)
Answer: D If we use median as a pivot element, then the recurrence for all cases
becomes T(n) = 2T(n/2) + O(n) The above recurrence can be solved using Master
Method. It falls in case 2 of master method.
Q3. Given an unsorted array. The array has this property that every element in array
is at most k distance from its position in sorted array where k is a positive integer
smaller than size of array. Which sorting algorithm can be easily modified for sorting
this array and what is the obtainable time complexity?
Answer:C
Solution:
1) to sort the array firstly create a min-heap with first k+1 elements and a separate
array as resultant array. 2) because elements are at most k distance apart from
original position so, it is guranteed that the smallest element will be in this K+1
elements. 3) remove the smallest element from the min-heap(extract min) and put it
in the result array. 4) Now,insert another element from the unsorted array into the
mean-heap, now,the second smallest element will be in this, perform extract min and
continue this process until no more elements are in the unsorted array.finally, use
simple heap sort for the remaining elements Time Complexity ------------------------
1) O(k) to build the initial min-heap 2) O((n-k)logk) for remaining elements... 3)
0(1) for extract min so overall O(k) + O((n-k)logk) + 0(1) = O(nlogk)
Q4. Which of the following is not true about comparison based sorting algorithms?
B Any comparison based sorting algorithm can be made stable by using position as
a criteria when two elements are compared
Answer:D
int fun(int n)
{
int count = 0;
count += 1;
return count;
A O(n^2)
B O(nLogn)
C O(n)
DO(nLognLogn)
Answer:C
B.Heap Sort
D Quick Sort
Answer:B
Q6.Consider the problem of computing min-max in an unsorted array where min and
max are minimum and maximum elements of array. Algorithm A1 can compute min-
max in a1 comparisons without divide and conquer. Algorithm A2 can compute min-
max in a2 comparisons by scanning the array linearly. What could be the relation
between a1 and a2 considering the worst case scenarios?
A a1 < a2
B a1 > a2
C a1 = a2
Q7.
Let G be the directed, weighted graph shown in below figure We are interested in
the shortest paths from A. (a) Output the sequence of vertices identified by the
Dijkstra’s algorithm for single source shortest path when the algorithm is started at
node A. (b) Write down sequence of vertices in the shortest path from A to E. (c)
What is the cost of the shortest path from A to E?
Q8. Let P be an array containing n integers. Let t be the lowest upper bound on the
number of comparisons of the array elements, required to find the minimum and
maximum values in an arbitrary array of n elements. Which one of the following
choices is correct?
A t>2n−2
Answer:B
Q9. Consider the following array. Which algorithm out of the following options
uses the least number of comparisons (among the array elements) to sort the above
array in ascending order?
A Selection sort
B Mergesort
C Insertion sort
Answer:C
B Prim's algorithm
C Kruskal algorithm
D Huffman Coding
Answer:E
Q11.
B P, Q, R, U, S, T
C P, Q, R, U, T, S
D P, Q, T, R, U, S
Answer: B
character Frequency
a 5
b 9
c 12
d 13
e 16
f 45
Note : Each character in input message takes 1 byte. If the compression technique
used is Huffman Coding, how many bits will be saved in the message?
A 224
B 800
C576
D324
Answer:C
A O(N)
B O(NlogN)
CO(N(logN)^2)
DO(N^2)
Answer:B
Q14. Which of the following is true about Kruskal and Prim MST algorithms?
Assume that Prim is implemented for adjacency list representation using Binary
Heap and Kruskal is implemented using union by rank.
Answer:A
Answer:C
Q16
A(E, G), (C, F), (F, G), (A, D), (A, B), (A, C)
B (A, D), (A, B), (A, C), (C, F), (G, E), (F, G)
C (A, B), (A, D), (D, F), (F, G), (G, E), (F, C)
D(A, D), (A, B), (D, F), (F, C), (F, G), (G, E)
Answer :D
Q17. Consider the weights and values of items listed below. Note that there is only
one unit of each item.
The task is to pick a subset of these items such that their total weight is no more than
11 Kgs and their total value is maximized. Moreover, no item may be split. The total
value of items picked by an optimal algorithm is denoted by Vopt. A greedy
algorithm sorts the items by their value-to-weight ratios in descending order and
packs them greedily, starting from the first item in the ordered list. The total value
of items picked by the greedy algorithm is denoted by Vgreedy. The value of Vopt
− Vgreedy is ______ .
A 16
B8
C 44
D 60
Answer:A
Q18 Six files F1, F2, F3, F4, F5 and F6 have 100, 200, 50, 80, 120, 150 records
respectively. In what order should they be stored so as to optimize act. Assume each
file is accessed with the same frequency
D Ordering is immaterial as all files are accessed with the same frequency
Answer:A
Q19Consider a job scheduling problem with 4 jobs J1, J2, J3, J4 and with
corresponding deadlines: ( d1, d2, d3, d4) = (4, 2, 4, 2). Which of the following is
not a feasible schedule without violating any job schedule?
Answer:B
Q20. Consider a graph G=(V, E), where V = { v1,v2,…,v100 }, E={ (vi, vj) ∣ 1≤ii,
vj) is ∣i–j∣. The weight of minimum spanning tree of G is ________ . Note - This
question was Numerical Type.
A99
B100
C 98
D 101
Answer:A
Q22. Consider the string abbccddeee. Each letter in the string must be assigned a
binary code satisfying the following properties:
For any two letters, the code assigned to one letter must not be a prefix of the code
assigned to the other letter.
For any two letters of the same frequency, the letter which occurs earlier in the
dictionary order is assigned a code whose length is at most the length of the code
assigned to the other letter.
Among the set of all binary code assignments which satisfy the above two properties,
what is the minimum length of the encoded string?
A 21
B23
C25
D30
Answer:B
Answer:D
Answer:B
Q25 Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the
longest common subsequence (not necessarily contiguous) between A and B and let
y be the number of such longest common subsequences between A and B. Then x +
10y = ___.
A33
B23
C43
D34
Answer:D
Q26Consider the weights and values of items listed below. Note that there is only
one unit of each item.
The task is to pick a subset of these items such that their total weight is no more than
11 Kgs and their total value is maximized. Moreover, no item may be split. The total
value of items picked by an optimal algorithm is denoted by Vopt. A greedy
algorithm sorts the items by their value-to-weight ratios in descending order and
packs them greedily, starting from the first item in the ordered list. The total value
of items picked by the greedy algorithm is denoted by Vgreedy. The value of Vopt
− Vgreedy is ______ .
A16
B8
C44
D60
Answer:A
Y = < C, A, D, B, C, B >
A5
B3
C4
D2
Answer:C
Q29 The following paradigm can be used to find the solution of the problem in
minimum time: Given a set of non-negative integer, and a value K, determine if there
is a subset of the given set with sum equal to K:
B Dynamic Programming
C Greedy Algorithm
Answer:B
Answer:B
A. O(sum)
B. O(n)
C. O(sum * n)
D. O(sum + n)
Answer:C
Q32Which of the following is/are property/properties of a dynamic programming
problem?
a) Optimal substructure
b) Overlapping subproblems
c) Greedy approach
Answer: d
a) Overlapping subproblems
b) Optimal substructure
c) Memoization
d) Greedy
Answer: b
Q34 If a problem can be broken into subproblems which are reused several times,
the problem possesses ____________ property.
a) Overlapping subproblems
b) Optimal substructure
c) Memoization
d) Greedy
Answer: a
Answer: b
Explanation: The top-down approach uses the memoization technique which stores
the previously calculated values. Due to this, the time complexity is decreased but
the space complexity is increased.
Q36. Which of the following problems is NOT solved using dynamic programming?
Answer: d
(A) NP-complete = NP
(D) P = NP-complete
A A
B B
C C
D D
Q38 Let S be an NP-complete problem and Q and R be two other problems not
known to be in NP. Q is polynomial time reducible to S and S is polynomial-time
reducible to R. Which one of the following statements is true?
A R is NP-complete
B R is NP-hard
C Q is NP-complete
DQ is NP-hard
Answer:B
Q39 Let X be a problem that belongs to the class NP. Then which one of the
following is TRUE?
Answer:C
A both in P
B both NP complete
Answer:C
Q41 Which of the following statements are TRUE? (1) The problem of determining
whether there exists a cycle in an undirected graph is in P. (2) The problem of
determining whether there exists a cycle in an undirected graph is in NP. (3) If a
problem A is NP-Complete, there exists a non-deterministic polynomial time
algorithm to solve A.
A1, 2 and 3
B 1 and 3
C2 and 3
D1 and 2
Answer:A
Q42What is recurrence for worst case of QuickSort and what is the time complexity
in Worst case?
Q43Suppose we have a O(n) time algorithm that finds median of an unsorted array.
Now consider a QuickSort implementation where we first find median using the
above algorithm, then use median as pivot. What will be the worst case time
complexity of this modified QuickSort.
A O(n^2 Logn)
B O(n^2)
D O(nLogn
Answer:D
A Insertion Sort
B Merge Sort
C Quick Sort
D Bubble Sort
Answer:C
Q45 Which of the following sorting algorithms in its typical implementation gives
best performance when applied on an array which is sorted or almost sorted
(maximum 1 or two elements are misplaced).
A Quick Sort
B Heap Sort
C Merge Sort
D Insertion Sort
Q46 Given an unsorted array. The array has this property that every element in array
is at most k distance from its position in sorted array where k is a positive integer
smaller than size of array. Which sorting algorithm can be easily modified for sorting
this array and what is the obtainable time complexity?
Answer:B
Q47 Consider a situation where swap operation is very costly. Which of the
following sorting algorithms should be preferred so that the number of swap
operations are minimized in general?
A Heap Sort
B Selection Sort
C Insertion Sort
D Merge Sort
Answer:B
Q48 Which of the following is not true about comparison based sorting algorithms?
B Any comparison based sorting algorithm can be made stable by using position as
a criteria when two elements are compared
A N^2
B NlogN
CN
D N(logN)^2
Answer:C
A Merge Sort works better than quick sort if data is accessed from slow sequential
memory.
Answer:D
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: