Vous êtes sur la page 1sur 14

1) ) From fastest to slowest, the correct order for the following algorithms is:

(a) Linear search, Binary search, Bubble Sort, Selection Sort, finding the maximum element of an
unsorted array, finding the maximum element of a sorted array.
(b) finding the maximum element of an unsorted array, finding the maximum element of a sorted
array, Linear search, Binary search, Selection Sort, Bubble Sort.
(c) finding the maximum element of a sorted array, Binary search, Linear search, finding the maximum
element of an unsorted array, Selection Sort, Bubble Sort.
(d) Bubble Sort, Selection Sort, Binary search, Linear search, finding the maximum
element of a sorted array, finding the maximum element of an unsorted
array.
ANS-C
2) Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the
worst-case time complexity of the best-known algorithm to delete the node x from the list ?
A) O(n)
B) O(log 2 n)
C) O(log n)
D) O(1)
Answer A
3) Consider a list of recursive algorithms and a list of recurrence relations as shown below. Each
recurrence relation corresponds to exactly one algorithm and is used to derive the time complexity of
the alogrithm. Recursive Algorithm Recurrence Relation
P. Binary search I. T(n) = T(n-k) + T(k) + cn
Q. Merge sort II. T(n) = 2T(n -1) + 1
R. Quick sort III. T(n) = 2T(n/2) + cn
S. Tower of Hanoi IV. T(n) = T(n/2) + 1
Which of the following is the correct match between the algorithms and their recurrence relations?
A) P-II, Q-III, R-IV, S-I
B) P-IV, Q-III, R-I, S-II
C) P-III, Q-II, R-IV, S-I
D) P-IV, Q-II, R-I, S-III
Correct Answer B
4) To implement Dijkstras shortest path algorithm on unweighted graphs so that it runs in linear time,
the data structure to be used is:
(A) Queue
(B) Stack
(C) Heap
(D) B-Tree
Answer(A)
5) An algorithm that always takes the best immediate or local solution while finding an answer
is called____.
a) Deterministic Algorithm
b) Non deterministic Algorithm
c) Greedy Algorithm
d) Randomized Algorithm

Ans-c


6) Inserting an element into an unsorted array of length n that is not yet full requires how many
comparison operations between elements in the worst case (assume that you do not know how many
elements are in the array)?
(a) O(logn)
(b) O(n)
(c) O(1)
(d) n^2 - 1

Ans- b
7) Finding and removing an element from a sorted array of length n requires how many copy
operations and how many comparisons between elements, in the
worst case (assume to remove an element one copies all subsequent elements
down one position)?
(a) logn copy operations and n comparisons between elements
(b) O(1) copy operations and n comparisons between elements
(c) O(n) copy operations and logn + 1 comparisons between elements
(d) O(n) copy operations and n comparisons between elements

ans- c
8) A sorting algorithm is called stable if equal elements are in the same relative order in the sorted
sequence as in the original sequence. Which of INSERTION-SORT, MERGE-SORT, HEAPSORT and
QUICKSORT are unstable?
a) INSERTION-SORT
b) QUICKSORT
c) HEAPSORT
d) QUICKSORT and HEAPSORT
ans-d
9) what is the time complexity to merge k sorted lists into one sorted list, where n is the total number of
elements in all the input list using heap sort?
a)O(nlogk)
b)O(logn)
c)O(logk)
d)O(klogk)
ans-a
10) we have a hash table table with load factor
1
n
m
o = <
, in which collision is
resolved by chaining what is expected time of successful search?
a)
1 1
ln
1 o o

b)
1
1 o

c)1+ o
d)none
ans-c
11) The median of n elements choosen as pivot by taking 0(n) time algo. Then what will be the
time complexity of quick sort.
(a) O(n
2
) (b) 0(n log n)
(c) 0(n) (d) None
Ans-b
12) Suppose Q and R are languages. Assuming P!= NP, which of the following implies that R is
not in P ?
(A) R is in NP.
(B) Q is in NP and Q is polynomial-time reducible to R.
(C) Q is in NP and R is polynomial-time reducible to Q.
(D) Q is NP-complete and Q is polynomial-time reducible to R.
(E) Q is NP-complete and R is polynomial-time reducible to Q.

Ans-d
13) Many operations can be performed faster on sorted than unsorted data. Which of the following is
not applicable to the above statement?
(a) Checking whether one word is an anagram of another word. (e.g. plum and lump)
(b) Finding an item with a minimum value
(c) Finding the middle value (median)
(d) Finding the value which appears most frequently (mode) in the data
Ans-a

14)

Ans-a
15)

Ans-c



16)

Ans-e

17) Given a graph G with vertex set V and edge set E, which of the following statements is/are
true?

I. If G is directed and acyclic, the asymptotic algorithmic complexity of topological sort on G
is O(|V | + |E|), assuming edges are represented in adjacency lists rather than an adjacency
matrix.


II. If G is directed or undirected, the asymptotic algorithmic complexity of breadth-first search on G is
O(|V | + |E|), assuming edges are represented in adjacency lists rather than an
adjacency matrix.
III. If G is undirected, during a depth-first search of G, exactly four types of edges might be identified:
tree edges (members of the spanning forest), back edges (linking descendants to ancestors), forward
edges (non-tree edges linking ancestors to descendants), and cross edges (all other remaining links).

A. I only
B. III only
C. I and II only
D. I, II, and III
E. None of the above
Ans-c
18) Given an undirected graph G with vertex set V and edge set E, which of the following statements
about single-source shortest path algorithms is not true?

A. Dijkstras algorithm is different than Prims algorithm in that Dijkstras algorithm can use a priority
queue, but Prims algorithm cannot use a priority queue.
B. Dijkstras algorithm runs on G in asymptotic algorithmic complexity O(|E| + |V | lg |V |),
assuming that a Fibonacci heap is used for the priority queue of waiting vertices and edges
are represented in adjacency lists (rather than an adjacency matrix).
C. Dijkstras algorithm possesses lower average asymptotic algorithmic complexity than the
Bellman-Ford algorithm, especially if G is so dense that |E| |V |2 .
D. The Bellman-Ford algorithm can handle edges with negative weights, whereas Dijkstras
algorithm may fail if G possesses edges with negative weights.
E. Dijkstras algorithm resembles breadth-first search in that each algorithm grows a tree of
finished nodes (none of which are modified again later by the algorithm).
Ans-a
19) Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a hash function
h(x) = x(mod 10), collision is resolved by Open addressing hash table using linear probing.
What will be the content of table at location 4.
a)1323
b)6173
c)4344
d)4199
ans-b
20) For permutation (a1, a2 an) of (1, 2 n), define its inversion table to be (b1, b2.bn), where
bi is the number of elements in the permutation (a1, a2. an) to the left of i which are greater than i
(each pair (ai, aj) such that i < j but ai > aj is called an inversion).
For example, if (a1, a2.. a9) = (5, 9, 1, 8, 2, 6, 4, 7, 3)
then
(b1, b2,.., b9) = (2, 3, 6,4, 0, 2, 2, 1, 0),
That is, b2 = 3 because 5, 9 and 8 are to the left of 2 and are greater than 2.
For each i, 1 <= i <= n, how many possible values are there for bi?
a)n-i
b)n
c)n+i
d)n
2
ans-a
21) Consider a knapsack having capacity of 15. Some weight and their corresponding profit is given in
table below
obj1 obj 2 obj 3 obj 4 obj 5 obj 6 obj 7
Profit 10 5 15 7 6 18 3
Weight 2 3 5 7 1 4 1


What will be optimal profit?

a)57
b)61
c)54
d)60
ans-a
22) We are given two strings: String S of length n and string T of length m
for the LCS problem, we have produced the following exponential time recursive program.
LCS(S, n, T, m)
{
if (n = = 0 || m = = 0) return 0
if (S[n] = = T[m]) result = 1 + LCS(S, n 1, T, m 1);
Else result = max (LCS(S, n 1, T, m), LCS(S, n, T, m 1));
return result;
}
Then the number of times that LCS(S, 1, T, 1) is recursively called equals________
a)
2
1
n m
m
+ | |
|

\ .

b)
1
2
n m
m
+ + | |
|

\ .

c)
2 n m
m
+ + | |
|
\ .

d)
1
n m
m
+ | |
|

\ .

ans-a
23) Which of the following problems can be solved by a standard greedy algorithm?
I. Finding a minimum spanning tree in an undirected graph with positive-integer edge weights
II. Finding a maximum clique in an undirected graph
III. Finding a maximum flow from a source node to a sink node in a directed graph with positive-
integer edge
capacities
(A) I only (B) II only (C) III only (D) I and II only
Ans-a
24) For a connected, undirected graph G = aV, Ef, which of the following must be true?
I. vV degree(v) is even.
II. E V 1
III. G has at least one vertex with degree 1.
(A) I only
(B) II only
(C) III only
(D) I and II
Ans-d

25) Consider the following possible data structures for a set of n distinct integers.
I. A min-heap
II. An array of length n sorted in increasing order
III. A balanced binary search tree
For which of these data structures is the number of steps needed to find and remove the 7th largest
element O(logn) in the worst case?
(A) I only (B) II only (C) I and II (D) II and III
Ans-d
26) Which of the following problems would have polynomial time algorithms if it is assumed that P
!=NP ?
I. Given a combinational circuit with n inputs and m outputs and n
2
gates, where each gate is either
AND,OR, or NOT, and given m values c
1
, . . . , c
m
in {0, 1}, either find a string of n input values b
1
, . . . ,
b
n
in {0,1} that would produce c
1
, . . . , c
m
as output or determine that c
1
, . . . , c
m
is not a possible
output of the
circuit.
II. Given an n by n matrix A with rational number entries, either find the exact inverse A
1
of A or
determine that A
1
does not exist. (Assume that each rational number is expressed as a pair a/b of
integers (b!= 0), where a and b are expressed in binary notation.)
III. Given a directed graph with nodes numbered 1, 2, . . . , n, and given positive integer weights
assigned to the edges, either find the length of a shortest path from node 1 to node n or determine
that no such path exists. (Here the length of a path is the sum of the lengths of the edge weights on
the path.)
(A) I only (B) II only (C) III only (D) II and III
Ans-d

27) Let T be a depth-first search tree of a connected undirected graph G. For each vertex v of T, let
pre(v) be the number of nodes visited up to and including v during a preorder traversal of T , and
post(v) be the number of nodes visited up to and including v during a postorder traversal of T. The
lowest common ancestor of vertices u and v in T is a vertex w of T such that w is an ancestor of both u
and v, and no child of w is an ancestor of both u and v.
Let (u, v) be an edge in G that is not in T, such that pre(u) < pre(v). Which of the following statements
about u and v must be true?
I. post(u) < post(v)
II. u is an ancestor of v in T.
III. If w is the lowest common ancestor of u and v in T, then w = u.
(A) I only (B) II only (C) III only (D) II and III
Ans-d





common data question 28-29
Question numbers 28-29 are based on the following pseudo code algorithm segments and data
set given thereafter.
Program segment 1:
qqq( data, first,last);
if first < last
mid=(first+last) /2 ;
qqq( data,first, mid);
qqq(data,mid+1,last);
combine(data, first, last);
Program segment 2:
combine( array1, array2, array3);
i1,i2,i3 are properly initialized;
while both array2 and array3 contained elements;
If array2[i2] < array3[i3]
array[i1++]=array2[i2++];
else array1[i1++] = array3 [i3++];
load into array1 the remaining elements of either array2 or array3;
Data set : 1 8 6 4 10 5 3 2 22
28) What are the above program segments intended to do?
(a) binary search algorithm (b) merge sort algorithm
(c) straight selection sort (d) radix sort
Ans-b
29) If one uses the above program segments to sort/search the data set, how many sub files may be
created during the above process?
(a) 17 (b) 12 (c) 16
(d) 18
Ans-c
Common data question 30-31
Question numbers 30-31 are based on the following directed graph.

30) Consider the following statements about the directed graph.
(i) There are only three cyclic paths from node A to Node A.
(ii) There is only one path from NODE Dto F where each path of length is equal to 2.
(iii) There is no direct path form node A to A.
(iv) This can be represented using a tree.
Which of the above statements is/are true in relation to the above graph?
(a) (i) and (ii) only (b) (i) ,(ii) and (iii) only
(c) (i) and (iv) only (d) (iv) only
Ans-d




31) The adjacency matrix of the above graph is
(a)
A B C D E F
A 0 1 1 0 1 1
B 1 0 1 0 1 0
C 0 0 0 1 0 0
D 1 0 0 0 1 0
E 0 0 0 0 0 1
F 1 0 0 0 1 0
(b)
A B C D E F
A 0 1 1 0 1 1
B 1 0 1 0 0 0
C 0 1 0 1 0 0
D 1 0 0 0 1 0
E 0 0 0 0 0 1
F 1 0 0 0 0 0
(c)
A B C D E F
A 0 1 1 0 1 1
B 1 0 1 0 0 0
C 0 0 0 1 0 0
D 1 0 0 0 1 0
E 0 0 0 0 0 1
F 1 0 1 0 0 0
(d)
A B C D E F
A 0 1 1 0 1 1
B 1 0 1 0 0 0
C 0 0 0 1 0 0
D 1 0 0 0 1 0
E 0 0 0 0 0 1
F 1 0 0 0 0 0
Ans-d


Linked data question 32-33
Consider the random variable:

32)Find a binary Huffman code for x7
a) 011
b) 01000
c) 01011
d)01010
ans-c

33) Find the expected codelength for this encoding.
a) 2.02 bits
b) 2.12 bits
c) 2.07 bits
d) 2.67 bits
nas-a

Vous aimerez peut-être aussi