GATE 2012
82 questions
MCQ 821-mark 39 · 2-mark 43
Questions 41–45 of 82
Which of the following problems are decidable?
1) Does a given program ever produce an output?
2) If L is a context-free language, then, is also context-free?
3) If L is a regular language, then, is also regular?
4) If L is a recursive language, then, is also recursive?
1) Does a given program ever produce an output?
2) If L is a context-free language, then, is also context-free?
3) If L is a regular language, then, is also regular?
4) If L is a recursive language, then, is also recursive?
Answer: (D)
1. Undecidable. Given a Turing machine and input , build a program that runs on and prints something only after halts. This program ever produces output exactly when halts, so a decider for 1 would decide the halting problem.
2. Undecidable. CFLs are not closed under complement, and no algorithm can decide, for a given CFL, whether its complement is also context-free (a standard result, shown by reduction from Turing machine computation histories).
3, 4. Regular languages are closed under complement (swap the final and non-final states of a DFA). Recursive languages are closed under complement (swap accept and reject in a decider). So the answer is always "yes", and a question with a fixed answer is decidable.
Answer: (D)
2. Undecidable. CFLs are not closed under complement, and no algorithm can decide, for a given CFL, whether its complement is also context-free (a standard result, shown by reduction from Turing machine computation histories).
3, 4. Regular languages are closed under complement (swap the final and non-final states of a DFA). Recursive languages are closed under complement (swap accept and reject in a decider). So the answer is always "yes", and a question with a fixed answer is decidable.
Answer: (D)
For the grammar below, a partial LL(1) parsing table is also presented along with the grammar. Entries that need to be filled are indicated as E1, E2, and E3. is the empty string, $ indicates end of input, and, | separates alternate right hand sides of productions.
The appropriate entries for E1, E2, and E3 are
The appropriate entries for E1, E2, and E3 are
Answer: (C)
Find FIRST and FOLLOW first. FIRST(S) = {a, b, ε}.
FOLLOW(S): S is the start symbol, so . From , b follows A; from , a follows A; so FOLLOW(A) = {a, b}. Since , FOLLOW(S) contains FOLLOW(A). B ends the S productions, so FOLLOW(B) = FOLLOW(S). Hence .
Rule: put in M[A, t] for every t in FIRST(α); if α can give ε, also for every t in FOLLOW(A).
- E1 = M[S, a]: because a is in its FIRST; because a is in FOLLOW(S).
- E2 = M[S, b]: because b is in its FIRST; because b is in FOLLOW(S).
- E3 = M[B, ]: , because S can give ε and is in FOLLOW(B).
Option A leaves out in E1 and E2. Option B writes "", which is not a production. Option D puts A and B productions in row S.
Answer: (C)
FOLLOW(S): S is the start symbol, so . From , b follows A; from , a follows A; so FOLLOW(A) = {a, b}. Since , FOLLOW(S) contains FOLLOW(A). B ends the S productions, so FOLLOW(B) = FOLLOW(S). Hence .
Rule: put in M[A, t] for every t in FIRST(α); if α can give ε, also for every t in FOLLOW(A).
- E1 = M[S, a]: because a is in its FIRST; because a is in FOLLOW(S).
- E2 = M[S, b]: because b is in its FIRST; because b is in FOLLOW(S).
- E3 = M[B, ]: , because S can give ε and is in FOLLOW(B).
Option A leaves out in E1 and E2. Option B writes "", which is not a production. Option D puts A and B productions in row S.
Answer: (C)
For the grammar below, a partial LL(1) parsing table is also presented along with the grammar. Entries that need to be filled are indicated as E1, E2, and E3. is the empty string, $ indicates end of input, and, | separates alternate right hand sides of productions.
The FIRST and FOLLOW sets for the non-terminals A and B are
The FIRST and FOLLOW sets for the non-terminals A and B are
Answer: (A)
FIRST sets: gives FIRST(S) = {a, b, }. Since and , FIRST(A) = FIRST(B) = {a, b, }.
FOLLOW(A): in A is followed by b, and in A is followed by a. So FOLLOW(A) = {a, b}.
FOLLOW(B): B is the last symbol of the productions of S, so FOLLOW(S) is added to FOLLOW(B).
FOLLOW(S): is in it because S is the start symbol. Also gives FOLLOW(A) FOLLOW(S), and gives FOLLOW(B) FOLLOW(S). So FOLLOW(S) = {} {a, b} FOLLOW(B), and FOLLOW(S) = FOLLOW(B) = {a, b, }.
This also fills the table: E3 = M[B, ] is , because is in FIRST(S) and is in FOLLOW(B).
Option (B) is wrong because cannot be in FIRST(A) (FIRST has only terminals and ), and FOLLOW(B) is not just {}.
Answer: (A)
FOLLOW(A): in A is followed by b, and in A is followed by a. So FOLLOW(A) = {a, b}.
FOLLOW(B): B is the last symbol of the productions of S, so FOLLOW(S) is added to FOLLOW(B).
FOLLOW(S): is in it because S is the start symbol. Also gives FOLLOW(A) FOLLOW(S), and gives FOLLOW(B) FOLLOW(S). So FOLLOW(S) = {} {a, b} FOLLOW(B), and FOLLOW(S) = FOLLOW(B) = {a, b, }.
This also fills the table: E3 = M[B, ] is , because is in FIRST(S) and is in FOLLOW(B).
Option (B) is wrong because cannot be in FIRST(A) (FIRST has only terminals and ), and FOLLOW(B) is not just {}.
Answer: (A)
Consider the program given below, in a block-structured pseudo-language with lexical scoping and nesting of procedures permitted.
Consider the calling chain: Main A1 A2 A21 A1
The correct set of activation records along with their access links is given by
Program main;
Var ...
Procedure A1;
Var ...
Call A2;
End A1
Procedure A2;
Var ...
Procedure A21;
Var ...
Call A1;
End A21
Call A21;
End A2
Call A1;
End main.Consider the calling chain: Main A1 A2 A21 A1
The correct set of activation records along with their access links is given by
Answer: (D)
An access link points to the activation record of the procedure that lexically encloses it.
- A1 and A2 are both declared in Main, so each one has its link to Main.
- A21 is declared inside A2, so it has its link to A2.
- The second A1, called from A21, is still declared in Main, so it has its link to Main. Access links follow the nesting in the program, not the calling order.
This matches figure (D). In (A) and (B) the last A1 links to A21, and (C) shows only four records, with no record for the second call of A1.
Answer: (D)
- A1 and A2 are both declared in Main, so each one has its link to Main.
- A21 is declared inside A2, so it has its link to A2.
- The second A1, called from A21, is still declared in Main, so it has its link to Main. Access links follow the nesting in the program, not the calling order.
This matches figure (D). In (A) and (B) the last A1 links to A21, and (C) shows only four records, with no record for the second call of A1.
Answer: (D)
A process executes the code
fork();
fork();
fork();
The total number of child processes created is
fork();
fork();
fork();
The total number of child processes created is
Answer: (C)
Every fork call makes the number of processes twice as large. After three forks there are processes altogether, and this count includes the first process.
Number of child processes = 8 1 = 7
Answer: 7
Number of child processes = 8 1 = 7
Answer: 7