Computer Science and Information Technology
2024 · Paper 2
Take it one question at a time. Try an answer, then check your understanding.
Complete GATE CSE 2024 Paper 2 overview, original pages and practice · Timed previous-paper practice
Questions 40–42 of 65. Imported answers require review unless explicitly marked reviewed.
Question 40
Open questionCSMCQ2 marksNeeds review
Consider the following context-free grammar where the start symbol is S and the set of terminals is .
The following is a partially-filled LL(1) parse table.
| a | b | c | d | $ |
|---|---|---|---|---|---|
S | | | (1) | (2) | |
A | | (3) | | | |
B | (4) | | | | |
Which one of the following options represents the CORRECT combination for the numbered cells in the parse table?
Note: In the options, “blank” denotes that the corresponding cell is empty.
Your answerChoose one option.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 41
Open questionCSMCQ2 marksNeeds review
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?
Your answerChoose one option.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answerQuestion 42
Open questionCSMCQ2 marksNeeds review
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 labeled (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.)
Your answerChoose one option.
Log in to check the answer
You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer