GATE 2009
66 questions
MCQ 661-mark 24 · 2-mark 42
Questions 36–40 of 66
We wish to find the length of the longest common sub-sequence (LCS) of x[m] and Y[n] as l(m,n), where an incomplete recursive definition for the function l(i,j) to compute the length of the LCS of x[m] and Y[n] is given below:
l(i, j) = 0, if either i=0 or j=0
l(i, j) = expr1, if i,j>0 and x [i-1] = Y [j -1]
l(i, j) = expr2, if i,j>0 and x [i-1] != Y [j -1]The values of l(i,j) could be obtained by dynamic programming based on the correct recursive definition of l(i,j) of the form given above, using an array L[M,N], where M = m+1 and N=n+1, such that L[i,j] = l(i,j). Which one of the following statements would be TRUE regarding the dynamic programming solution for the recursive definition of l(i,j)?
Answer: (B)
So depends only on , and .
- (A) is false. Only the first row and first column (where i = 0 or j = 0) must be 0. Every other cell is filled by the recurrence.
- (B) is true. In row-major order, the cells it needs lie in the previous row or earlier in the same row. In column-major order, they lie in the previous column or earlier in the same column. Both orders work.
- (C) is false, because (B) shows both orders work.
- (D) is false. It asks that comes before if or . For and this would need each to come before the other. The real need is only and .
Answer: (B)
We wish to find the length of the longest common sub-sequence (LCS) of x[m] and Y[n] as l(m,n), where an incomplete recursive definition for the function l(i,j) to compute the length of the LCS of x[m] and Y[n] is given below:
l(i, j) = 0, if either i=0 or j=0
= expr1, if i,j>0 and x [i-1] = Y [j -1]
= expr2, if i,j>0 and x [i-1] != Y [j -1] Which one of the following options is correct?Answer: (C)
If they match, that letter ends an LCS, so . If they differ, the LCS leaves out or leaves out , so . This is option (C).
The others fail:
- (A) : for X = aa and Y = a it gives , but the LCS length is 1.
- (B) : for X = a and Y = a it gives 0, but the LCS length is 1.
- (D) : it uses to define itself.
Answer: (C)
Which one of the following is NOT the sequence of edges added to the minimum spanning tree using Kruskal's algorithm?
Answer: (D)
The MST has 6 edges: b-e (2), then a-c and e-f (3, either order), then b-c and f-g (4, either order), then c-d (5). The edges a-b and e-g (5) are rejected because they close a cycle (a-c-b and e-f-g).
(A), (B) and (C) have weights 2, 3, 3, 4, 4, 5 in order, so all are valid sequences.
(D) adds b-c (weight 4) before a-c (weight 3). At that point a-c would join two different components, so Kruskal would take it first. So (D) is not a possible sequence.
Answer: (D)
P. Always finds a negative weighted cycle, if one exists.
Q. Finds whether any negative weighted cycle is reachable from the source.
Answer: (B)
Single-source shortest paths, time .
In each pass, relax every edge once. At most passes are needed, so the cost is . One more pass is then made to verify the result: if any distance still improves, a negative cycle is reachable from the source.
Example from the figure, source A. The edges are relaxed in the order in every pass: , , , , , .
Each pair of lines in the table gives the distances and the predecessors. Rows i=0, 1, 2 are the passes. Row i=3 is the verification pass: the values stay unchanged. This is because the only cycle here, , weighs , so there is no negative cycle.
If a negative cycle were reachable from the source, some value would still drop in the verification pass, so Q is true.
Now say the cycle is not reachable from the source. Its vertices stay at from the beginning to the end, because relaxing an edge that starts at gives nothing. Other vertices that are not reachable also stay at . So the algorithm cannot tell such a cycle apart from those vertices, and it misses it. So P is false.
Answer: (B)
Answer: (C)
The other options do not match:
- (A) The string is accepted, but it does not have in it.
- (B) The string is accepted, but it has three 0's, which is more than two.
- (D) The set of strings that begin and end with 0 or 1 includes , but is not accepted since it has only one 0.
Answer: (C)