GATE 2014 (Session 2)
65 questions
MCQ 42 · NAT 231-mark 30 · 2-mark 35
Questions 46–50 of 65
Let has at least as many occurrences of (110)'s as (011)'s}.
Let has at least as many occurrence of (000)'s as (111)'s}.
Which one of the following is TRUE?
Let has at least as many occurrence of (000)'s as (111)'s}.
Which one of the following is TRUE?
Answer: (A)
is regular. The substring 110 occurs once for each block of 1s of length at least 2 that is followed by a 0. The substring 011 occurs once for each block of 1s of length at least 2 that is preceded by a 0. A block with a 0 on both sides counts once in each, so the counts can differ only because of the first block and the last block of :
, where each bracket is 1 if true and 0 if false.
So is outside only when it ends with 0 and at least two 1s, and does not start with at least two 1s followed by a 0. A DFA can check this by looking only at the first three and the last three symbols, so is regular.
is not regular. Let be the pumping length and take . It has copies of 000 and copies of 111, so it is in . In any split with and , lies inside the 0s. Pumping down gives , which has at most copies of 000 but still copies of 111. So it is not in .
Answer: (A)
, where each bracket is 1 if true and 0 if false.
So is outside only when it ends with 0 and at least two 1s, and does not start with at least two 1s followed by a 0. A DFA can check this by looking only at the first three and the last three symbols, so is regular.
is not regular. Let be the pumping length and take . It has copies of 000 and copies of 111, so it is in . In any split with and , lies inside the 0s. Pumping down gives , which has at most copies of 000 but still copies of 111. So it is not in .
Answer: (A)
Consider two strings A="qpqrr" and B="pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.
Answer: 34
Let be the LCS length of the first i letters of A and the first j letters of B. If the two letters match, ; otherwise it is the larger of the cell above and the cell to the left. Columns are for B = p, q, p, r, q, r, p (j = 1 to 7):
i = 1 (q): 0 1 1 1 1 1 1
i = 2 (qp): 1 1 2 2 2 2 2
i = 3 (qpq): 1 2 2 2 3 3 3
i = 4 (qpqr): 1 2 2 3 3 4 4
i = 5 (qpqrr): 1 2 2 3 3 4 4
The last cell is 4, so x = 4. A has 5 letters and x is less than 5, so no common subsequence has length 5.
Every LCS of length 4 is A with exactly one letter deleted. Try each deletion and check whether the result is a subsequence of B = pqprqrp:
- delete the first q: pqrr, found in B (p, q, r, r)
- delete p: qqrr, not in B (after the two q's only one r is left)
- delete the second q: qprr, found in B
- delete either r: qpqr, found in B (same string both times)
The distinct longest common subsequences are pqrr, qprr and qpqr, so y = 3.
x + 10y = 4 + 10 3 = 34
Answer: 34
i = 1 (q): 0 1 1 1 1 1 1
i = 2 (qp): 1 1 2 2 2 2 2
i = 3 (qpq): 1 2 2 2 3 3 3
i = 4 (qpqr): 1 2 2 3 3 4 4
i = 5 (qpqrr): 1 2 2 3 3 4 4
The last cell is 4, so x = 4. A has 5 letters and x is less than 5, so no common subsequence has length 5.
Every LCS of length 4 is A with exactly one letter deleted. Try each deletion and check whether the result is a subsequence of B = pqprqrp:
- delete the first q: pqrr, found in B (p, q, r, r)
- delete p: qqrr, not in B (after the two q's only one r is left)
- delete the second q: qprr, found in B
- delete either r: qpqr, found in B (same string both times)
The distinct longest common subsequences are pqrr, qprr and qpqr, so y = 3.
x + 10y = 4 + 10 3 = 34
Answer: 34
Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 respectively. They are to be merged into a single sequence by merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is ____.
Answer: 358
In the worst case, merging two lists of sizes m and n takes m + n 1 comparisons. The best way is to always merge the two smallest lists, as in Huffman coding.
- 20 + 24 = 44 43
- 30 + 35 = 65 64
- 44 + 50 = 94 93
- 65 + 94 = 159 158
Total = 43 + 64 + 93 + 158 = 358
Answer: 358
- 20 + 24 = 44 43
- 30 + 35 = 65 64
- 44 + 50 = 94 93
- 65 + 94 = 159 158
Total = 43 + 64 + 93 + 158 = 358
Answer: 358
Consider the expression tree shown. Each leaf represents a numerical value, which can either be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of the expression represented by the tree is ___.
Answer: 6
Root = (left subtree) + (right subtree).
- Left: (a + b) (c d). Max = (1 + 1) (0 1) = 3
- Right: (e f) + (g + h). Max = (1 0) + (1 + 1) = 3
Maximum = 3 + 3 = 6
Answer: 6
- Left: (a + b) (c d). Max = (1 + 1) (0 1) = 3
- Right: (e f) + (g + h). Max = (1 0) + (1 + 1) = 3
Maximum = 3 + 3 = 6
Answer: 6
Consider the following function
double f (double x) {
if ( abs (x*x - 3) < 0.01) return x;
else return f (x / 2 + 1.5/x);
} Give a value q (to 2 decimals) such that f(q) will return q:______Answer: 1.72 to 1.74
The function gives back x only when . This means . (The step x/2 + 1.5/x in the recursion is Newton's method used to find .)
Take q = 1.73. Then and so f(1.73) returns 1.73.
Answer: 1.73
Take q = 1.73. Then and so f(1.73) returns 1.73.
Answer: 1.73