Solutions - End Sem - Closed Book
Solutions - End Sem - Closed Book
MCQ: There can be multiple choice answers. You must tick all correct answers to get full marks.
No partial marks will be awarded for any missing correct answer or wrong tick.
(1) Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first parti-
tioning with the array looking like this: {2, 5, 1, 7, 9, 11, 10, 12}. Which statement is correct?
(2) Suppose we are running BFS algorithm on a connected graph G. Let G0 be the subgraph formed by the
discovery edges. Which of the following statements is true?
(a) External nodes of heap does not store any keys or elements
(b) Insertion and deletion of n elements in heap can be done in O(n log n) time
(c) Minimum element can be found in constant time
(4) Which sorting algorithm will take asymptotically least time when all elements of input array are identical?
Consider typical implementations of sorting algorithms.
(a) Insertion Sort (b)Heap Sort (c) Merge Sort (d)Selection Sort
(5) Keys: {15, 75, 63, 47, 98, 113} are stored in a direct access table. What is the minimum size of the table?
(7) Keys: {200, 205, 210, 215, ... 600} are stored in a chained hash table. Suppose h(k) = k mod 100 is used,
which slot will have the maximum number of keys?
(a) At the end of DFS algorithm, each edge is labelled as either back edge or discovery edge.
(b) Discovery edges form a spanning tree.
(c) Number of discovery edges is same as the number of vertices in G
(9) Suppose we have an 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.
(10) You have to sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will
be most appropriate?
(a) Heap sort (b)Merge sort (c) Quick sort (d)Radix sort
(11) The tightest lower bound on the number of comparisons, in the worst case, for comparison-based sorting is
of the order of
(13) Given an unweighted graph G, you want to run a Dijkstra’s shortest path algorithm in linear time. Which
is the best data structure for efficient implementation:
(15) Let G be an undirected connected graph with distinct edge weight. Let emax be the edge with maximum
weight and emin the edge with minimum weight. Which of the following statements is true?
(16) Following is an incorrect pseudocode for the algorithm which is supposed to determine whether a sequence
of parentheses is balanced:
Initialize : Stack S , Expression A (17)
while ( A ) No change till EndWhile. Add below statements
{ in the end:
read a character ai from A if (!S.isEmpty()):
if ai = ’( ’ Print (”unbalanced”)
S . push (ai ) else:
else if ai = ’) ’ && ! S . isEmpty () Print (unbalanced)
S . pop ()
else
print " unbalanced " and exit
}
print " balanced "
Which of these unbalanced sequences does the above code think is balanced?
(17) Add/Delete the statements to correct the pseudocode given in (16). Provide the answer in the box given
above.
Write the run-time complexity (Big-Oh Notation) of the following recurrence equations. Feel
free to use Master’s Theorem, if applicable.
(18) T (n) = T ( 3n n
4 ) + T(4) + n
O(n log n)
√
(19) T (n) = T ( n2 ) + T ( n) + n
O(n)