0% found this document useful (0 votes)
84 views2 pages

Solutions - End Sem - Closed Book

The document provides a 20 question multiple choice exam on algorithms and data structures concepts. It includes questions on topics like sorting algorithms, heaps, hash tables, graph algorithms, asymptotic analysis, and more. The exam expects students to select all correct answers for each question and provides no partial credit for incorrect or missing answers.

Uploaded by

Annwesha Panda
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)
84 views2 pages

Solutions - End Sem - Closed Book

The document provides a 20 question multiple choice exam on algorithms and data structures concepts. It includes questions on topics like sorting algorithms, heaps, hash tables, graph algorithms, asymptotic analysis, and more. The exam expects students to select all correct answers for each question and provides no partial credit for incorrect or missing answers.

Uploaded by

Annwesha Panda
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/ 2

End-sem exam solutions- Part A Closed Book

Maximum Marks 40 (20*2)


No Partial Marking
Multiple choice correct answers.

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?

(a) The pivot could be 7. (b)The pivot could be 9.


(c) The pivot could be 5. (d)The pivot could be 12.

(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) G0 is connected. (b)G0 is acyclic.


(c) G0 is a spanning tree of G. (d)Number of edges in G’ is same as the number of
vertices in G.

(3) Which of the following statements about minheap are 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?

(a) 6 (b)112 (c) 114 (d)5

(6) Which of the following statements are true?

(a) n! ∈ O(n) (b)n! ∈ O(nn ) (c) n! ∈ O(2n )

(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) 99 (b)10 (c) 0 (d)100

(8) Which of the following statements are true about DFS.

(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.

(a) O(n2 log n) (b)O(n2 ) (c) O(n log2 n) (d)O(n log n)

(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

(a) Ω(n) (b)Ω(n2 ) (c) Ω(n log2 n) (d)Ω(n log n)


(12) The following postfix expression with single digit operands is evaluated using a stack:
823↑/23*+51*-
What are the top two values on the Stack when the evaluation stopped at first multiplication from the left
hand side. (upper arrow is used for exponential).

(a) 3, 2 (b)6, 1 (c) 5, 7 (d)1, 5

(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:

(a) Queue (b)Stack (c) Heap (d)Priority Queue

(14) What is the worst case possible height of AVL tree?

(a) 2 ∗ log n (b)1.44 ∗ log n (c) 1.618 ∗ log n (d)undefined

(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?

(a) Every minimum spanning tree of G must contain emin


(b) If emax is in a minimum spanning tree, then its removal must disconnect G
(c) No minimum spanning tree contains emax
(d) G has a unique minimum spanning tree

(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?

[a] ( ( ( ) ) [b] ( ) ) ( ( ) ) [c] ( ( ) ( ) ) ) [d] ( ( ) ) ( ( ) ( )

(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)

(20) T (n) = T (n − 2) + log n


O(n log n)

You might also like