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. For the above specified passage, which of the following represents the grammar for the language accepted by the machine?
    Answer: C. S → AabbA, A → aA | bA | ε Paper 2 CS · December 2024
  2. Which of the following represents the minimum-state DFA for the above specified passage?
    Answer: D. All are NFA Paper 2 CS · December 2024
  3. For the above specified passage, which of the following is a DFA for the language accepted by the machine?
    Answer: C. States 1–6, final {4, 5, 6}: 1 –b→ 1, 1 –a→ 2, 2 –a→ 2, 2 –b→ 3, 3 –a→ 2, 3 –b→… Paper 2 CS · December 2024
  4. For the above specified passage, which of the following represents the regular expression?
    Answer: D. (a + b)* abb (a + b)* Paper 2 CS · December 2024
  5. Consider the grammar: S → A A → $B$ | id B → B, A | A If I₀ = CLOSURE({[S → ·A]}), then how many items will be in the set GOTO(I₀, $)?
    Answer: C. 5 Paper 2 CS · June 2024 Re-Exam
  6. Consider the grammar: T → Qx Q → RS R → y | ε S → z | ε Here x, y, z are terminals and T, Q, R, S are non-terminals. What will be the FOLLOW set of the non-terminal R?
    Answer: C. {z, x} Paper 2 CS · June 2024 Re-Exam
  7. Which of the following properties correctly describe a Regular Grammar? (A) All production rules are of the form A → xB or A → x, where A and B are non-terminal symbols and x is a terminal symbol. (B) Regular grammars a…
    Answer: D. (A) and (C) Only Paper 2 CS · June 2024 Re-Exam
  8. If L₁ and L₂ are context-free languages, which one of the following is true about L₁ ∩ L₂?
    Answer: C. L₁ ∩ L₂ is recursively enumerable Paper 2 CS · June 2024 Re-Exam
  9. Which of the following tasks could be attained using syntax trees in compiler design? (A) Type Checking (B) Code Generation (C) Code Optimization (D) Error Handling Choose the correct answer from the options given below:
    Answer: A. (A), (B), (C) Only Paper 2 CS · June 2024 Re-Exam
  10. Arrange the following stages of a Turing Machine (TM) operation in the correct order as they occur during computation. (A) Writing a symbol on the tape (B) Moving the tape head left or right (C) Reading a symbol from th…
    Answer: C. (C), (D), (A), (B), (E) Paper 2 CS · June 2024 Re-Exam
  11. Which of the following languages can be recognized by a Non-Deterministic Finite Automaton (NFA) but cannot be recognized by a Deterministic Finite Automaton (DFA)? (A) L₁ = {w ∈ {0,1}* | the length of w is even} (B) L₂…
    Answer: D. None of the above Paper 2 CS · June 2024 Re-Exam
  12. Arrange the following phases in the correct order as they typically occur in the compilation process. (A) Lexical Analysis (B) Semantic Analysis (C) Syntax Analysis (D) Intermediate Code Generation (E) Code Optimization…
    Answer: B. (A), (C), (B), (D), (E) Paper 2 CS · June 2024 Re-Exam
  13. Arrange the following language classes in ascending order of their expressive power, as defined by the Chomsky hierarchy: (A) Context-free languages (B) Context-sensitive languages (C) Regular languages (D) Unrestricted…
    Answer: A. (C), (A), (B), (D) Paper 2 CS · June 2024 Re-Exam
  14. Which of the following are context-free languages? (A) {wⁱ xʲ yᵏ zˡ | i + k = j + l, where i, j, k, l ≥ 0} (B) {wⁱ xʲ yᵏ zˡ | i = j, k = l, where i, j, k, l ≥ 0} (C) {wⁱ xʲ yᵏ zˡ | i = j = k and k ≠ l, where i, j, k, l…
    Answer: A. (A) and (B) Only Paper 2 CS · June 2024 Re-Exam
  15. Let L = {ab, aa, baa}. Which of the following strings is NOT in L*?
    Answer: C. baaaaabaaaab Paper 2 CS · December 2023
  16. Let A = {a, b} and L = A*. Let X = {aⁿbⁿ | n > 0}. The languages L ∪ X and X are respectively:
    Answer: C. Regular, Not regular Paper 2 CS · December 2023
  17. Which of the following symbol-table implementations is best suited if access time is to be minimum?
    Answer: C. Hash table Paper 2 CS · December 2023
  18. Consider the grammar E → E + n | E × n | n. For the sentence n + n × n, the handles in the right-sentential forms of the reduction are:
    Answer: D. n, E + n and E × n Paper 2 CS · December 2023
  19. One of the purposes of using intermediate code in compilers is to:
    Answer: C. increase the chances of reusing the machine-independent code optimizer in other… Paper 2 CS · December 2023
  20. The sum of the minimum and maximum number of final states for a DFA having P states is equal to:
    Answer: C. P + 1 Paper 2 CS · December 2023
  21. Three-address code can be represented in special structures known as: (A) Quadruples (B) Triples (C) Patterns (D) Indirect Triples Choose the correct answer from the options given below:
    Answer: B. (A), (B) and (D) Only Paper 2 CS · December 2023
  22. Which of the statements is/are CORRECT? (A) Moore and Mealy machines are finite state machines with output capabilities. (B) Any given Moore machine has an equivalent Mealy machine. (C) Any given Mealy machine has an eq…
    Answer: B. (A), (B) and (C) Only Paper 2 CS · December 2023
  23. Match List I with List II according to the input to the compiler phase that processes it:List I List II (a) Syntax tree (I) Code generator (b) Intermediate representation (II) Semantic analyzer (c) Token stream (III) Le…
    Answer: B. (a)-(II), (b)-(I), (c)-(IV), (d)-(III) Paper 2 CS · December 2023
  24. Arrange the following phases of a compiler in their order of execution (start to end): (a) Target code generation (b) Syntax analysis (c) Code optimization (d) Semantic analysis (e) Lexical analysis Choose the correct a…
    Answer: C. (e), (b), (d), (c), (a) Paper 2 CS · December 2023
  25. Consider a finite automaton F1 with three states C (start), S and E (final), in which there are transitions in both directions between every pair of states (C ⇄ S, S ⇄ E, C ⇄ E). Let F2 be the finite automaton obtained…
    Answer: B. L(F1) = L(F2) Paper 2 CS · June 2023
  26. The maximum yield length of the following CNF CFG is S → AB A → CD B → e C → a D → b
    Answer: C. 4 Paper 2 CS · June 2023
  27. Consider the language L = {w ∈ {a, b, c}* : nₐ(w) + n_b(w) = n_c(w)}. L is
    Answer: A. Context free but not linear Paper 2 CS · June 2023
  28. Consider the following statements: A. A context-free language is generated by an LR(0) grammar if and only if it is accepted by a deterministic pushdown automaton and has the prefix property. B. If M1 is a single-tape T…
    Answer: C. D only Paper 2 CS · June 2023
  29. Which phase of the compiler checks the grammar of the program?
    Answer: D. Syntax analysis Paper 2 CS · June 2023
  30. Consider the following statements: A. The set of Turing machine codes for TMs that accept all inputs that are palindromes (possibly along with other inputs) is decidable. B. The language of codes for TMs M that, when st…
    Answer: D. B and D only Paper 2 CS · June 2023