All mock tests are FREE till 31 December — register to save your progress
Paper 2 CS · UNIT 08

Theory of Computation and Compilers – Previous Year Questions

250 questions from past UGC NET Paper 2 – Computer Science papers, each with the correct answer. Open any question for its explanation.

  1. Which of the following is not a part of the general activation record of a procedure?
    Answer: B. Global data Paper 2 CS · 22 June 2026
  2. Match the LIST-I with LIST-II. LIST-I (Language) LIST-II (Type of Language) A. L₁ = {aⁿbᵐ | n, m ≥ 0} I. Unrestricted B. L₂ = {aⁿbᵐ | (n − m) ≥ 0} II. Context Sensitive C. L₃ = {aⁿbⁿcⁿdⁿ | n ≥ 1} III. Regular D. L₄ = {a…
    Answer: B. A-III, B-IV, C-I, D-II Paper 2 CS · 22 June 2026
  3. If L1 is a regular language and L2 is a context free language, which of the following statement is correct?
    Answer: B. L1∩L2 is a context free language. Paper 2 CS · 22 June 2026
  4. Given the functions: Predecessor function: Pred(x) = x − 1 and T(x, y+1) = Pred(T(x, y)), T(x, 0) = x. Which of the following operations is a candidate for T?
    Answer: A. Subtraction Operation Paper 2 CS · 22 June 2026
  5. Arrange the following families of languages from specialization to generalization, defined over alphabet Σ: A. Family of all regular languages B. Family of all Turing acceptable languages C. Family of all Turing decidab…
    Answer: C. A, D, C, B Paper 2 CS · 22 June 2026
  6. Which of the following statements is incorrect?
    Answer: B. Given a context free language L, its complement is also context free. Paper 2 CS · 22 June 2026
  7. The minimum state DFA of the following would be the following: (a DFA with states q0 (start), q1, q2, q3 and q4 (accepting) is given, with transitions q0→0 q1, q0→1 q3, q1→0 q1 (self-loop), q1→1 q4, q3→0 q2, q3→1 q4, q2…
    Answer: A. A –(0,1)→ B, B has a self-loop on 0, B –1→ C Paper 2 CS · 22 June 2026
  8. Find the Follow (A) & Follow (C).
    Answer: B. Follow (A) = { +, ], $ }; Follow (C) = { *, +, ], $ } Paper 2 CS · 22 June 2026
  9. In the LL(1) Parsing table of the given CFG, how many valid non-blank entries will be there in the rows for variables 'B' and 'D'?
    Answer: A. B = 3 entries; D = 4 entries Paper 2 CS · 22 June 2026
  10. Identify the correct statement from the following.
    Answer: C. [[x * x] + x] is a valid sentence of this grammar Paper 2 CS · 22 June 2026
  11. What will be the FIRST(S) & FIRST(D)?
    Answer: C. FIRST (S) = { [, x }; FIRST (D) = { *, ε } Paper 2 CS · 22 June 2026
  12. The I0 state of the canonical LR(0) set of the SLR(1) parser of this CFG has how many productions?
    Answer: C. 5 Paper 2 CS · 22 June 2026
  13. Which of the following Grammars is/are only Context Free (i.e. context-free but not regular grammars)?Grammar Productions A S → Ab aS → aA A → a B S → Ab A → Sa A → a C S → AS S → aA A → a D S → Ab S → aA A → a E S → Sb…
    Answer: B. C, D Only Paper 2 CS · June 2025
  14. 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):State a b c → q0 q1 – – q1 q2 q3 q4 * q2 q2 q3 q4 * q3 q5 – q3 * q4 q…
    Answer: D. NFA-D: states q0–q3, start q0, final {q2, q3}. q0 –a→ q0, q0 –a→ q1; q1 –b→ q2,… Paper 2 CS · June 2025
  15. Consider the following DFA over Σ = {a, b, c}. Start state q0, which is also the only final state. Transitions:State a b c →* q0 q1 q0 q0 q1 q1 q2 q0 q2 q1 q0 q3 q3 q4 q3 q3 q4 q4 q5 q3 q5 q4 q3 q0 Which of the followin…
    Answer: D. L = {set of strings having an even count (including 0) of substring 'abc'} Paper 2 CS · June 2025
  16. Match List I with List IIList I List II A. Type 3 Grammar I. V → (V ∪ Σ)* B. Type 2 Grammar II. αVβ → α(V ∪ Σ)⁺β, where α, β ∈ (V ∪ Σ)* C. Type 1 Grammar III. (V ∪ Σ)* → (V ∪ Σ)* D. Type 0 Grammar IV. V → VΣ | Σ
    Answer: C. A → IV, B → I, C → II, D → III Paper 2 CS · June 2025
  17. 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 ans…
    Answer: C. LL(0) → LR(0) → SLR → LALR(1) → LR(1) Paper 2 CS · June 2025
  18. What are the various LEADERS (leading statements) for the TAC given in the passage?
    Answer: D. 100, 103, 104, 105, 106, 107, 111 Paper 2 CS · June 2025
  19. Which of the following is the optimized version of the TAC given in the passage?
    Answer: C. 100: t1 = y + 2 101: limit = 10 102: num = 9 103: b = t1 104: if i > j goto 106… Paper 2 CS · June 2025
  20. Which of the following is the correct high level code for the TAC given in the passage?
    Answer: D. init = x/(y+2); limit = 10; while (i>j && num>b) { num = limit-1; b = y+2; i =… Paper 2 CS · June 2025
  21. 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)
    Answer: A. Block 3: 3; Block 5: 5 Paper 2 CS · June 2025
  22. 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?
    Answer: A. 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0… Paper 2 CS · June 2025
  23. Which of the following is TRUE about the Pumping Lemma for regular languages?
    Answer: A. It is a property used to prove that languages are not regular Paper 2 CS · December 2024
  24. Regarding code optimization (peephole optimization), choose the correct sequence A. Algebraic Simplification B. Use of machine idioms C. Redundant-instruction elimination D. Flow of control optimization E. Improved targ…
    Answer: C. C, D, A, B, E Paper 2 CS · December 2024
  25. Which of the following represents the language accepted by the Turing machine with the transition function (δ): δ(q0, a) = (q1, x, R) δ(q1, a) = (q1, a, R) δ(q1, y) = (q1, y, R) δ(q1, b) = (q2, y, L) δ(q2, y) = (q2, y,…
    Answer: B. L = {aⁿbⁿ | n ≥ 1} Paper 2 CS · December 2024
  26. Match List I with List IIList I List II A. Conflict Resolution I. Three-Address Code B. Common Subexpression II. Precedence C. Quadruples III. Syntax Directed Translations D. L-Attributed definitions IV. Directed Acycli…
    Answer: B. A-II, B-IV, C-I, D-III Paper 2 CS · December 2024
  27. Match List I with List IIList I List II A. Type-0 Grammar I. Linear Grammar B. Type-1 Grammar II. GNF C. Type-2 Grammar III. x → y, |x| ≤ |y|; x, y ∈ (V ∪ T)* D. Type-3 Grammar IV. Recursively Enumerable
    Answer: D. A-IV, B-III, C-I, D-II Paper 2 CS · December 2024
  28. Which of the following CFG(s) is/are in Chomsky Normal Form? (All capital letters are variables & lower case letters are terminals) A. S → ABC | AB, A → a, B → b, C → d B. X → RT | TR, T → t, R → XT | r C. P → qP | sQ,…
    Answer: B. B only Paper 2 CS · December 2024
  29. yacc is which of the following parsers?
    Answer: D. LALR Parser Paper 2 CS · December 2024
  30. For the above-mentioned passage, which of the following automata is correct? Each option is described by its transitions (start state 1).
    Answer: C. States 1–4, final {4}: 1 –a,b→ 1, 1 –a→ 2, 2 –b→ 3, 3 –b→ 4, 4 –a,b→ 4 Paper 2 CS · December 2024