Answer 2019
Answer 2019
Answer 2019
Group A
1. (i) ---- (c), (ii) --- (d), (iii) --- (b), (iv) --- (a), (v) --- (b), (vi) --- (c), (vii) --- (d), (viii) --- (b),
(ix) --- (c), (x) --- (d)
Solve the following recurrence by recurrence tree method and
2. (a) Consider the marks division as 2 + 2 verify it with forward substitution method, T(n) = 3T(n/4) + cn^2
For the verification part of this question, if the students answer the question correctly by
mentioning only substitution, instead of forward substitution, then full marks may be given
3 (a)
If you do this as a tournament arranged as a binary tree where as many teams as possible play in
the 1st level and then in the 2nd level etc. then such a tree will have a height of lgn . In other
words the champion (the smallest element) has to play at most lg n games in order to be the
champion. If we can track which numbers were the direct losers to the champion, then the
smallest of them is the 2nd order statistic. To find the minimum of lgn numbers it will take
lgn -1 more comparisons.
You are provided as input an even positive integer n > 1 and an unsorted sequence S of n integers. You would like to
find both the second order statistic and the nth order statistic of S. Show that they can
be found out in (3 n/2 + lgn - 3) number of pair-wise comparisons.
click above
Now you can find out the nth order statistic in the same way. Total number of comparisons
required to find the 1st order statistic and nth order statistic simultaneously are: n/2 (1st level
out
comparisons) + (n/2 - 1) (to find the winner our of the larger numbers of 1st level) + (n/2 - 1) (to
find the winner out of the smaller numbers of 1st level) = 3n/2 - 2
So total number of comparisons to find the second order and nth order statistic along with the
earlier case is as follows: (3n/2 - 2) + ( lgn -1) = 3 n/2 + lgn - 3
3. (b)
TBSA(n) = 1 / nc 1 S c * c
k
Upto this point is algorithm, then it is completely mathematics to solve the recurrence and after
solving it we get TBSA(n) = O(log n)
Another Approach
Suppose when you first compare the key with the middle element, it matches, then the number of
comparisons required to find the key is only 1. Number of positions for which only one
comparison is required is therefore 1.
Now if you do not find the key in the 1st comparison but you find it in the 2nd comparison, then
number of such positions = 2 (middle elements of the half-arrays).
The number of positions for which 3 comparisons are reqd. is 4.
(highlighted term is for not finding the key, for which lh n comparisons are required)
M matrix:
b)
Method (the Greedy method): The selection policy (of which best pair of arrays to merge next) is to
choose the two shortest remaining arrays.
Implementation:
Need a data structure to store the lengths of the arrays, to find the shortest 2 arrays at any time, to
delete those lengths, and insert in a new length (for the newly merged array).
In essence, the data structure has to support delete-min and insert. Clearly, a min- heap is ideal.
Time complexity of the algorithm: The algorithm iterates (n-1) times. At every iteration two delete-mins
and one insert is performed. The 3 operations take O(log n) in each iteration.
Thus the total time is O(nlog n) for the while loop + O(n) for initial heap construction.
That is, the total time is O(nlog n).
Provide reasons for for why it will/ will not produce an optimal solution.
Ans:
The case is exactly similar as generation of Huffman code and hence since the strategy is exactly similar
as Huffman code generation it will give optimal result.
Assumption Merging two sorted arrays of length m and n will require O(m + n) time
or more precisely - c(m + n) time.
Consider the length of each array as the frequency of Huffman code. Then merging the two smallest
arrays is like merging the 2 Huffman codes of smallest frequency and rest follows easily from that. Note
that the array which merges early will be used for merging more number of times and hence it helps if it
is smaller in size. In Huffman code the character that has less frequency is merged early so that when it
gets a longer code it is multiplied by a smaller frequency.
c) Students can show the priority queues in various ways. One such way can be as follows:
Nodes a b c d e f g h i
Key ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
Nodes a b c d e f g h i
Key 0 4 ∞ ∞ ∞ ∞ ∞ 8 ∞
Nodes a b c d e f g h i
Key 0 4 8 ∞ ∞ ∞ ∞ 8 ∞
6. marks distribution is (4+4)+4. But as per the nature of the question, it should be 4+(4+4).
a) Amortized cost = O(1).
Note: Since the method is not mentioned, any method can be accepted.
b)
Find out the number of components for the following graph using union-find (union by rank),
b) Given a graph G = (V, E), we want to find a shortest path from a given source vertex s ∈ V to
each vertex v ∈ V .
Shortest-paths algorithms typically rely on the property that a shortest path between
two vertices contains other shortest paths within it.
Given a weighted, directed graph G = (V, E), let p = <v0, v1, .., vk> be a shortest path from v0 to
vk.
p0i pij pjk
If we decompose path p into v0 vi vj vk, then we have that w(p) = w(p0i) + w(pij)
+ w(pjk). Now, assume that there is a path p’ij from vi to vj with weight w(p’ij) < w(pij). Then the
weight of the new path p’, i.e. w(p’) < w(p), which contradicts the assumption that p is a shortest
path from v0 to vk
8. a) Define flow in a flow network. What is an s-t cut of a flow network? Prove that flow of any s-t cut is equal to
the flow of the network.
8. b) 9
4 5 6
1 2
Only the newly created link is marked bold. The rest of the tree will be same.
9. a) Explain with a small diagram how you can show the easiness or hardness of a new problem using
the easiness or hardness result of a known problem
Show that the Clique Decision Problem is NP-hard by using the result the 3-CNF-SAT problem is
b) computationally hard
CNF formula(f) => Graph (G)
● It has a vertex for every pair (v, c).
● v is a variable or its negation (v’),
● c is a clause in the formula f that contains v.
● Edges are there between (v, c) and (u, d) if , c ≠ d and u ≠ v’
Means: between any 2 literals in different clauses, who are not each other’s negation.
● If k denotes the no. of clauses in the CNF formula (f), then the k-vertex clique in
the graph represents ways of assigning truth values to some of its variables in order
to satisfy the formula.