All mock tests are FREE till 31 December — register to save your progress
UGC NET · PAPER 2

UGC NET Paper 2 Computer Science – Unit 8: Theory of Computation and Compilers PYQ (June 2025)

10 questions · answer key at the end · updated 11 Oct 2026
Q14. Which of the following Grammars is/are only Context Free (i.e. context-free but not regular grammars)?
GrammarProductions
AS → Ab
aS → aA
A → a
BS → Ab
A → Sa
A → a
CS → AS
S → aA
A → a
DS → Ab
S → aA
A → a
ES → Sb
A → Aa
A → ε
  1. A, B Only
  2. C, D Only
  3. C, E Only
  4. A, B, D, E Only
Answer & explanation →
Q50. Consider the following DFA over Σ = {a, b, c}. Start state q0; final states q2, q3, q4, q5. Transitions (any missing transition goes to a dead state):
Stateabc
→ q0q1––
q1q2q3q4
* q2q2q3q4
* q3q5–q3
* q4q0––
* q5q1––
Which of the following NFAs is valid (equivalent) for the given DFA?
  1. NFA-A: states q0–q4, start q0, final {q2, q3}. q0 –a→ q0, q0 –a→ q1; q1 –b→ q2, q1 –a,c→ q3; q2 –c→ q2, q2 –a→ q0, q2 –a→ q3, q2 –a→ q4; q4 –c→ q3; q3 –a→ q0
  2. NFA-B: same as NFA-A but final states {q2, q3, q4}
  3. NFA-C: states q0–q3, start q0, final {q3} only. q0 –a→ q0, q0 –a→ q1; q1 –b→ q2, q1 –a,c→ q3; q2 –c→ q2, q2 –a→ q0, q2 –a→ q3; q3 –a→ q0
  4. NFA-D: states q0–q3, start q0, final {q2, q3}. q0 –a→ q0, q0 –a→ q1; q1 –b→ q2, q1 –a,c→ q3; q2 –c→ q2, q2 –a→ q0, q2 –a→ q3; q3 –a→ q0
Answer & explanation →
Q75. Consider the following DFA over Σ = {a, b, c}. Start state q0, which is also the only final state. Transitions:
Stateabc
→* q0q1q0q0
q1q1q2q0
q2q1q0q3
q3q4q3q3
q4q4q5q3
q5q4q3q0
Which of the following is the best description of the language of this DFA?
  1. L = (a* + b* + c*)⁺
  2. L = (a + b + c)* (abc)⁺ (a + b + c)*
  3. L = {set of strings all starting with 'a, b, c' but ending with 'c'}
  4. L = {set of strings having an even count (including 0) of substring 'abc'}
Answer & explanation →
Q76. Match List I with List II
List IList II
A. Type 3 GrammarI. V → (V ∪ Σ)*
B. Type 2 GrammarII. αVβ → α(V ∪ Σ)⁺β, where α, β ∈ (V ∪ Σ)*
C. Type 1 GrammarIII. (V ∪ Σ)* → (V ∪ Σ)*
D. Type 0 GrammarIV. V → VΣ | Σ
  1. A → II, B → III, C → IV, D → I
  2. A → III, B → I, C → IV, D → II
  3. A → IV, B → I, C → II, D → III
  4. A → III, B → II, C → I, D → IV
Answer & explanation →
Q88. Arrange the following parsers in increasing order of their power of handling grammars, i.e. from the least powerful parser to the most powerful parser.
A. LR(0)
B. LR(1)
C. LALR(1)
D. LL(0)
E. SLR
Choose the correct answer from the options given below:
  1. LL(0) → LR(0) → SLR → LR(1) → LALR(1)
  2. SLR → LR(0) → LL(0) → LR(1) → LALR(1)
  3. LL(0) → LR(0) → SLR → LALR(1) → LR(1)
  4. LR(0) → LL(0) → SLR → LR(1) → LALR(1)
Answer & explanation →

Directions (Q91–95): Consider the following Three Address Code sample for solving the questions:

100: t1 = y + 2
101: initial = x / t1
102: limit = 10
103: if i > j goto 105
104: goto 111
105: if num > b goto 107
106: goto 111
107: num = limit - 1
108: b = y + 2
109: i = i - num
110: goto 103
111: j = i - num
112: k = j + b
Q91. What are the various LEADERS (leading statements) for the TAC given in the passage?
  1. 100, 102, 103, 104, 105, 107, 110
  2. 100, 103, 105, 107, 111, 112
  3. 100, 103, 105, 106, 107, 111
  4. 100, 103, 104, 105, 106, 107, 111
Answer & explanation →
Q92. Which of the following is the optimized version of the TAC given in the passage?
  1. 100: t1 = y + 2
    101: initial = x / t1
    102: limit = 10
    103: if i > j goto 105
    104: goto 111
    105: if num > b goto 110
    106: goto 111
    107: b = y + 2
    108: i = i - limit - 1
    109: goto 103
    110: k = i + b
  2. 100: t1 = y + 2
    101: initial = x / t1
    102: limit = 10
    103: if i > j goto 105
    104: if num < b goto 111
    105: num = limit - 1
    106: b = t1
    107: i = i - num
    108: goto 103
    109: k = i + b
  3. 100: t1 = y + 2
    101: limit = 10
    102: num = 9
    103: b = t1
    104: if i > j goto 106
    105: goto 110
    106: if num > b goto 108
    107: goto 110
    108: i = i - num
    109: goto 104
    110: j = i - num
    111: k = j + b
  4. 100: t1 = y + 2
    101: initial = x / t1
    102: limit = 10
    103: if i > j goto 105
    104: goto 111
    105: if num < b goto 111
    106: num = limit - 1
    107: b = t1
    108: i = i - num
    109: goto 103
    110: k = i + b
Answer & explanation →
Q93. Which of the following is the correct high level code for the TAC given in the passage?
  1. t1 = y+2;
    init = x/t1;
    limit = 10;
    if (i>j || num>b)
    {
      num = limit-1;
      b = y+2;
      i = i-num;
    }
    j = i-num;
    k = k+b;
  2. init = x/(y+2);
    limit = 10;
    while (i>j || num>b)
    {
      num = limit-1;
      b = y+2;
      i = i-num;
    }
    j = i-num;
    k = k+b;
  3. init = x/(y+2);
    limit = 10;
    if (i>j)
    {
      while (num>b)
        num = limit-1;
    }
    else
    {
      b = y+2;
      i = i-num;
    }
    j = i-num;
    k = k+b;
  4. init = x/(y+2);
    limit = 10;
    while (i>j && num>b)
    {
      num = limit-1;
      b = y+2;
      i = i-num;
    }
    j = i-num;
    k = k+b;
Answer & explanation →
Q94. What blocks do Block 3 and Block 5 dominate in the flow graph for the TAC given in the passage? (Basic blocks: B1 = 100–102, B2 = 103, B3 = 104, B4 = 105, B5 = 106, B6 = 107–110, B7 = 111–112)
  1. Block 3: 3; Block 5: 5
  2. Block 3: 3, 4, 5, 6; Block 5: 5, 6
  3. Block 3: 3, 7; Block 5: 5, 7
  4. Block 3: 3, 4, 7; Block 5: 5, 6, 7
Answer & explanation →
Q95. Which of the following is the correct flow graph (adjacency matrix of basic blocks B1–B7, row → column means an edge) for the TAC given in the passage?
  1. 0100000
    0011000
    0000001
    0000110
    0000001
    0100000
    0000000
  2. 010000
    001000
    101000
    010001
    000001
    000001
  3. 010000
    001000
    101000
    010001
    000001
    000001
  4. 0100000
    0001010
    0000001
    0010010
    0000001
    0100000
    0100000
Answer & explanation →

Answer key

  1. 14 – B
  2. 50 – D
  3. 75 – D
  4. 76 – C
  5. 88 – C
  6. 91 – D
  7. 92 – C
  8. 93 – D
  9. 94 – A
  10. 95 – A