GATE 2024 (Session 2)
65 questions
MCQ 32 · MSQ 18 · NAT 151-mark 30 · 2-mark 35
Questions 41–45 of 65
Let M be the 5-state NFA with -transitions shown in the diagram below:
Which one of the following regular expressions represents the language accepted by M ?
Which one of the following regular expressions represents the language accepted by M ?
Answer: (B)
From state 1, an move goes to 2 (final) or to 4.
- Through 2: 0 swaps between 2 and 3. Ending at 2 gives . From 3 (after ), take to 5, then .
- Through 4: read 1 to reach 5, then .
Union: . As :
(The other options miss "0" or , or wrongly accept "11".)
Answer:
- Through 2: 0 swaps between 2 and 3. Ending at 2 gives . From 3 (after ), take to 5, then .
- Through 4: read 1 to reach 5, then .
Union: . As :
(The other options miss "0" or , or wrongly accept "11".)
Answer:
Consider an array X that contains n positive integers. A subarray of X is defined to be a sequence of array locations with consecutive indices.
The C code snippet given below has been written to compute the length of the longest subarray of X that contains at most two distinct integers. The code has two missing expressions labelled (P) and (Q).
(Hint: At the end of the i-th iteration, the value of len1 is the length of the longest subarray ending with X[i] that contains all equal values, and len2 is the length of the longest subarray ending with X[i] that contains at most two distinct values.)
The C code snippet given below has been written to compute the length of the longest subarray of X that contains at most two distinct integers. The code has two missing expressions labelled (P) and (Q).
int first=0, second=0, len1=0, len2=0, maxlen=0;
for (int i=0; i < n; i++) {
if (X[i] == first) {
len2++; len1++;
} else if (X[i] == second) {
len2++;
len1 = (P) ;
second = first;
} else {
len2 = (Q) ;
len1 = 1; second = first;
}
if (len2 > maxlen) {
maxlen = len2;
}
first = X[i];
} Which one of the following options gives the CORRECT missing expressions?(Hint: At the end of the i-th iteration, the value of len1 is the length of the longest subarray ending with X[i] that contains all equal values, and len2 is the length of the longest subarray ending with X[i] that contains at most two distinct values.)
Answer: (B)
Here first = X[i1], which is the previous element. second is the other value in the current window.
- X[i] == second (and not first): the window still holds only two values, so len2++. The run of equal values ends and a new run starts with X[i]. So len1 = 1 (P) = 1.
- X[i] is a new value: the new window can keep only the last run of equal values (the run of first, of length len1) and X[i]. So len2 = len1 + 1 (Q) = len1+1.
Answer: (P) 1, (Q) len1+1
- X[i] == second (and not first): the window still holds only two values, so len2++. The run of equal values ends and a new run starts with X[i]. So len1 = 1 (P) = 1.
- X[i] is a new value: the new window can keep only the last run of equal values (the run of first, of length len1) and X[i]. So len2 = len1 + 1 (Q) = len1+1.
Answer: (P) 1, (Q) len1+1
Consider the following expression: . The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6).
Which one of the following options fills in the missing entries CORRECTLY?
Which one of the following options fills in the missing entries CORRECTLY?
Answer: (A)
Expression: . The triples, in the order they are evaluated:
- (0) + p r
- (1) =[] s i this fetches s[i]
- (2) uminus (1)
- (3) * (0) (2) this is (p+r) * (s[i])
- (4) / u w
- (5) + (3) (4)
- (6) []= x i this is the location x[i] where the result is stored
- (7) = (6) (5)
Answer: (1) =[] s i, (3) * (0) (2), (6) []= x i
- (0) + p r
- (1) =[] s i this fetches s[i]
- (2) uminus (1)
- (3) * (0) (2) this is (p+r) * (s[i])
- (4) / u w
- (5) + (3) (4)
- (6) []= x i this is the location x[i] where the result is stored
- (7) = (6) (5)
Answer: (1) =[] s i, (3) * (0) (2), (6) []= x i
Let and be random variables, not necessarily independent, that take real values in the interval . Let and let the mean values of be , respectively. Which one of the following statements is TRUE?
Answer: (D)
Here and (both are in [0, 1]). Multiplying by gives for every outcome. Taking the mean of both sides, . This is always true, so (D) is TRUE.
The others depend on how x and y are related:
- (A) and (B): take with x uniform on [0, 1]. Then and . So , and both "=" and "" fail.
- (C): take . Then . So "" fails.
Answer: (D)
The others depend on how x and y are related:
- (A) and (B): take with x uniform on [0, 1]. Then and . So , and both "=" and "" fail.
- (C): take . Then . So "" fails.
Answer: (D)
The relation schema, Person(pid,city), describes the city of residence for every person uniquely identified by pid. The following relational algebra operators are available: selection, projection, cross product, and rename.
To find the list of cities where at least 3 persons reside, using the above operators, the minimum number of cross product operations that must be used is
To find the list of cities where at least 3 persons reside, using the above operators, the minimum number of cross product operations that must be used is
Answer: (B)
There is no aggregation here. So "at least 3 persons in a city" means we must find 3 different pids that share the same city. For this, one tuple must hold 3 copies of Person:
Here cond is: P1.city = P2.city = P3.city, and P1.pid, P2.pid, P3.pid are all different.
To combine 3 copies we need 2 cross products. With just one cross product, we can compare only 2 tuples.
Answer: 2
Here cond is: P1.city = P2.city = P3.city, and P1.pid, P2.pid, P3.pid are all different.
To combine 3 copies we need 2 cross products. With just one cross product, we can compare only 2 tuples.
Answer: 2