|Theory of Computation and Compilers PYQs

UGC NET Computer Science Theory of Computation and Compilers Previous Year Questions (PYQs)

Practise 46 Theory of Computation and Compilers questions asked in UGC NET Computer Science from 2020–2025. Questions cover Finite automata, Regular expressions, Context-free grammars, Turing machines, Chomsky hierarchy of languages and Compiler phases and lexical analysis. Every question is shown with its options and the correct answer, free to read.

46 PYQs2020–2025Answers includedFree

Practise Theory of Computation and Compilers as timed sets

Focused 10-question sets with instant scoring, explanations, and weak-area analysis.

Start practice

All 46 Theory of Computation and Compilers PYQs

Ordered newest exam first. Each question links back to the full paper it came from.

  1. The kinds of symbols for basic syntactic elements of first-order logic are:

    A. Constant
    B. Domain
    C. Predicate
    D. Temporal
    E. Function

    1. AB and D only
    2. BA, B and C only
    3. CA, C and E only
    4. DC and D only

    Answer: (C) A, C and E only

    Explanation

    Sign in to read the full explanation
  2. Which statement is true about the pumping lemma for regular languages?

    1. AIt applies to all regular languages
    2. BIt applies only to infinite regular languages
    3. CIt applies to all context-free languages
    4. DIt applies to all recursively enumerable languages

    Answer: (A) It applies to all regular languages

    Explanation

    Sign in to read the full explanation
  3. Regarding code optimisation, choose the correct sequence.

    A. Algebraic simplification
    B. Use of machine idioms
    C. Redundant-instruction elimination
    D. Flow-of-control optimisation
    E. Improved target code

    1. AA, C, B, D, E
    2. BB, C, D, A, E
    3. CC, D, A, B, E
    4. DD, B, A, C, E

    Answer: (C) C, D, A, B, E

    Explanation

    Sign in to read the full explanation
  4. Match List-I with List-II.

    List-IList-II
    A. Conflict resolution
    B. Common subexpression
    C. Quadruples
    D. L-attributed definitions
    I. Three-address code
    II. Precedence
    III. Syntax-directed translations
    IV. Directed acyclic graph
    1. AA-III, B-II, C-IV, D-I
    2. BA-II, B-IV, C-I, D-III
    3. CA-II, B-III, C-I, D-IV
    4. DA-IV, B-I, C-II, D-III

    Answer: (B) A-II, B-IV, C-I, D-III

    Explanation

    Sign in to read the full explanation
  5. Which of the following CFG(s) is/are in Chomsky Normal Form? All capital letters are variables and lower-case letters are terminals.

    GrammarProductions
    AS → ABC | AB; A → a; B → b; C → d
    BX → RT | TR; T → l; R → XT | r
    CP → qP | sQ; M → MN | MP
    DN → nmin; P → P
    1. AA and B only
    2. BB only
    3. CC only
    4. DB and D only

    Answer: (B) B only

    Explanation

    Sign in to read the full explanation
  6. Choose the correct statements.

    A. A problem which is NP-complete can be solved in polynomial time.
    B. All NP-complete problems are NP-hard problems.
    C. If an NP-hard problem can be solved in polynomial time, then all NP-complete problems can be solved in polynomial time.
    D. All NP-hard problems are not NP-complete.

    1. AA and C only
    2. BB and D only
    3. CA, B and C only
    4. DA, B, C and D

    Answer: (D) A, B, C and D

    Explanation

    Sign in to read the full explanation
  7. Which language is represented by the displayed Turing-machine transition function?

    1. A{aⁿbⁿ | n ≥ 0}
    2. B{abⁿ | n ≥ 1}
    3. C{ab* | n > 0}
    4. D{aⁿb* | n > 1}

    Answer: (B) {abⁿ | n ≥ 1}

    Explanation

    Sign in to read the full explanation
  8. Match List-I with List-II.

    List-IList-II
    A. Type-0 grammar
    B. Type-1 grammar
    C. Type-2 grammar
    D. Type-3 grammar
    I. Linear grammar
    II. GNF
    III. x → y, |x| ≤ |y|; x,y ∈ (V ∪ T)*
    IV. Recursively enumerable
    1. AA-I, B-II, C-III, D-IV
    2. BA-II, B-I, C-III, D-IV
    3. CA-III, B-II, C-IV, D-I
    4. DA-IV, B-III, C-I, D-II

    Answer: (D) A-IV, B-III, C-I, D-II

    Explanation

    Sign in to read the full explanation
  9. Yacc is which of the following parsers?

    1. APredictive parser
    2. BSLR parser
    3. CCLR parser
    4. DLALR parser

    Answer: (D) LALR parser

    Explanation

    Sign in to read the full explanation
  10. For the automaton described in the accompanying comprehension passage, which displayed diagram represents the minimum-state DFA?

    DFA options 1-4 for Question 141

    DFA options 1-4 for Question 141

    1. ADFA diagram 1
    2. BDFA diagram 2
    3. CDFA diagram 3
    4. DDFA diagram 4

    Answer: (D) DFA diagram 4

    Explanation

    Sign in to read the full explanation
  11. For the automaton in the preceding comprehension passage, which displayed diagram is correct?

    DFA options 1-4 for Question 142

    DFA options 1-4 for Question 142

    1. ADFA diagram 1
    2. BDFA diagram 2
    3. CDFA diagram 3
    4. DDFA diagram 4

    Answer: (C) DFA diagram 3

    Explanation

    Sign in to read the full explanation
  12. For the preceding automaton passage, which displayed DFA represents the language accepted by the machine?

    DFA options 1-4 for Question 143

    DFA options 1-4 for Question 143

    1. ADFA diagram 1
    2. BDFA diagram 2
    3. CDFA diagram 3
    4. DDFA diagram 4

    Answer: (C) DFA diagram 3

    Explanation

    Sign in to read the full explanation
  13. For the automaton described in the comprehension passage, which regular expression represents its accepted language?

    1. A(a+b)*aab
    2. Baba(a+b)*
    3. Cb(a+b)*b(a+b)a(a+b)
    4. D(a+b)abb(a+b)

    Answer: (D) (a+b)abb(a+b)

    Explanation

    Sign in to read the full explanation
  14. For the automaton described in the comprehension passage, which grammar represents the language accepted by the machine?

    1. AS → AabbB, A → aA | ε, B → bB | ε
    2. BS → abbA, A → aA | ε | bA
    3. CS → AabbA, A → aA | bA | ε
    4. DS → Aabb, A → aA | bA | ε

    Answer: (C) S → AabbA, A → aA | bA | ε

    Explanation

    Sign in to read the full explanation
  15. Consider the grammar:

    S → A
    A → $B$ | id
    B → B, A | A

    If I₀ = CLOSURE({[S → .A]}), how many items are in GOTO(I₀, $)?

    1. A3
    2. B4
    3. C5
    4. D6

    Answer: (C) 5

    Explanation

    Sign in to read the full explanation
  16. 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?

    1. A{x,y}
    2. B{y,z}
    3. C{z,x}
    4. D{ϵ}

    Answer: (C) {z,x}

    Explanation

    Sign in to read the full explanation
  17. 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 are more powerful than
    context-free grammars and can express any type
    of language.
    C. There is a direct correspondence between
    regular grammar and finite automata.
    D. Regular grammars can generate languages
    that are not recognised by any type of automata.

    1. A(A) and (B) Only
    2. B(B) and (C) Only
    3. C(C) and (D) Only
    4. D(A) and (C) Only

    Answer: (D) (A) and (C) Only

    Explanation

    Sign in to read the full explanation
  18. If L₁ and L₂ are context free languages, which one of the following is true about L₁ ∩ L₂?

    1. AL1 L2 is context free.
    2. BL1 L2 is Regular
    3. CL1 L2 is Recursive Enumerable
    4. DL1 L2 is Context Sensitive

    Answer: (C) L1 L2 is Recursive Enumerable

    Explanation

    Sign in to read the full explanation
  19. 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

    1. A(A), (B), (C) Only
    2. B(B), (C), (D) Only
    3. C(A), (C), (D) Only
    4. D(A), (B), (D) Only

    Answer: (A) (A), (B), (C) Only

    Explanation

    Sign in to read the full explanation
  20. Match List-I with List-II.

    List-IList-II
    (A) HTML(I) Allow for dynamic and interactive web pages.
    (B) DHTML(II) Defines the structure of web pages.
    (C) XML(III) Object-oriented programming language for web applications.
    (D) JAVA(IV) Used for data storage and transport.
    1. A(A)-(I), (B)-(III), (C)-(II), (D)-(IV)
    2. B(A)-(II), (B)-(III), (C)-(IV), (D)-(I)
    3. C(A)-(II), (B)-(I), (C)-(IV), (D)-(III)
    4. D(A)-(III), (B)-(I), (C)-(IV), (D)-(II)

    Answer: (C) (A)-(II), (B)-(I), (C)-(IV), (D)-(III)

    Explanation

    Sign in to read the full explanation
  21. 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 to right
    C. Reading a symbol from the tape
    D. Transitioning to a new state based on the
    current state and symbol read
    E. Halting and accepting or rejecting the input

    1. A(C), (A), (B), (D), (E)
    2. B(C), (B), (A), (D), (E)
    3. C(C), (D), (A), (B), (E)
    4. D(C), (D), (B), (A), (E)

    Answer: (C) (C), (D), (A), (B), (E)

    Explanation

    Sign in to read the full explanation
  22. 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₂ = {w ∈ {0,1}* | the length of w is odd}
    C. L₃ = {w ∈ {0,1}* | all 0s precede all 1s in w}
    D. L₄ = {w ∈ {0,1}* | w contains an equal number of 0s and 1s}
    E. L₅ = {w ∈ {0,1}* | all 1s precede all 0s in w}

    1. A(A) and (B) only
    2. B(B) and (C) only
    3. C(C) and (D) only
    4. DNone of the above

    Answer: (D) None of the above

    Explanation

    Sign in to read the full explanation
  23. Arrange the following stages of parsing in the
    correct order as they typically occur in the
    compilation process.
    A. Lexical Analysis
    B. Sematic Analysis
    C. Syntax Analysis
    D. Intermediate Code Generation
    E. Code Optimization

    1. A(A), (B), (C), (D), (E)
    2. B(A), (C), (B), (D), (E)
    3. C(A), (D), (B), (C), (E)
    4. D(A), (C), (D), (B), (E)

    Answer: (B) (A), (C), (B), (D), (E)

    Explanation

    Sign in to read the full explanation
  24. Arrange the following Language Classes in
    ascending order according to their expressive
    power, as defined by Chomsky hierarchy:
    A. Context-free languages
    B. Context-sensitive languages
    C. Regular languages
    D. Unrestricted Grammars

    1. A(C), (A), (B), (D)
    2. B(C), (A), (D), (B)
    3. C(A), (C), (B), (D)
    4. D(A), (D), (B), (C)

    Answer: (A) (C), (A), (B), (D)

    Explanation

    Sign in to read the full explanation
  25. Which of the following languages are context-free?

    A. {wⁱxʲyᵏzˡ | i + k = j + l; i, j, k, l ≥ 0}
    B. {wⁱxʲyᵏzˡ | i = j and k = l; i, j, k, l ≥ 0}
    C. {wⁱxʲyᵏzˡ | i = j = k and k ≠ l; i, j, k, l ≥ 0}
    D. {wⁱxʲyᵏzˡ | i = j = k + l; i, j, k, l ≥ 0}
    E. {wⁱxʲyᵏzˡ | i = j = l and k ≠ l; i, j, k, l ≥ 0}

    1. A(A) and (B) only
    2. B(B) and (C) only
    3. C(C) and (D) only
    4. D(D) and (E) only

    Answer: (A) (A) and (B) only

    Explanation

    Sign in to read the full explanation
  26. Practise Theory of Computation and Compilers in a timed set
  27. Let L={ab, aa, baa}. Which of the following strings are not in L*.

    1. Aabaabaaabaa
    2. Baaaabaaaa
    3. Cbaaaaabaaaab
    4. Dbaaaaabaa

    Answer: (C) baaaaabaaaab

    Explanation

    Sign in to read the full explanation
  28. Let A={a, b} and L=A*. Let x={a"b", n>0}. The languages L U X and X are respectively :

    1. ANot regular, Regular
    2. BRegular, Regular
    3. CRegular, Not regular
    4. DNot Regular, Not Regular

    Answer: (C) Regular, Not regular

    Explanation

    Sign in to read the full explanation
  29. Which of the following symbol table implementation is best suited if access time is to be minimum ?

    1. A_ Linear list
    2. BSearch tree
    3. CHash Table
    4. DSelf organisation list

    Answer: (C) Hash Table

    Explanation

    Sign in to read the full explanation
  30. Consider a Grammar E>E+n|ExXn|n for a sentence n+n Xn, the handles in the right-sentential form of the reduction are ?

    1. An,E+nandE+nxn
    2. Bn,E+nand E+Exn
    3. Cn,n+nandn+nxn
    4. Dn,E+nand Exn

    Answer: (D) n,E+nand Exn

    Explanation

    Sign in to read the full explanation
  31. One of the purposes of using intermediate code in compilers is to :

    1. Amake parsing and semantic analysis simpler
    2. Bimprove error recovery and error reporting
    3. Cincrease the chances of reusing the machine independent code optimizer in other compilers
    4. Dimprove the register allocation

    Answer: (C) increase the chances of reusing the machine independent code optimizer in other compilers

    Explanation

    Sign in to read the full explanation
  32. The sum of minimum and maximum number of final states for a Deterministic Finite Automata (DFA) having 'P" state is equal to : () Pp

    1. Ap
    2. Bp-1
    3. Cp+1
    4. Dp+2

    Answer: (C) p+1

    Explanation

    Sign in to read the full explanation
  33. Three address codes 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 :

    1. A(A) and (B) Only
    2. B(A), (B) and (D) Only
    3. C(B) and (C) Only
    4. D(B), (Cand (D) Only

    Answer: (B) (A), (B) and (D) Only

    Explanation

    Sign in to read the full explanation
  34. Which of the statement 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 equivalent Moore machine.
    D. Moore machine is not a finite state machine. Choose the correct answer from the options given below :

    1. A(A) and (B) Only
    2. B(A), (B) and (©) Only
    3. C(B) and (D) Only
    4. D(A), (B) and (D) Only

    Answer: (B) (A), (B) and (©) Only

    Explanation

    Sign in to read the full explanation
  35. Arrange the following phases of a compiler as per 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 answer from the options given below :

    1. A(B), (B), (D), (A), ©)
    2. B(&), (D), @), (A), (©
    3. C(&), (B), (D), (©), (A)
    4. D(B), (D), (E), (A), ©)

    Answer: (C) (&), (B), (D), (©), (A)

    Explanation

    Sign in to read the full explanation
  36. The prototyping model has the sequence :
    A. Customer Evaluation
    B. Quick design
    C. Requirements
    D. Implement
    E. Design Choose the correct answer from the options given below :

    1. AC → A → D → B → E
    2. BB → C → A → D → E
    3. CC → B → D → A → E
    4. DE → B → C → D → A

    Answer: (C) C → B → D → A → E

    Explanation

    Sign in to read the full explanation
  37. Consider L = L₁ ∩ L₂, where L₁ = {0ᵐ1ᵐ20ⁿ1ⁿ | m, n ≥ 0} and L₂ = {0ᵐ1ⁿ2ᵏ | m, n, k ≥ 0}. Then L is

    1. ARecursively enumerable but not context-free
    2. BRegular
    3. CContext-free but not regular
    4. DNot recursive

    Answer: (C) Context-free but not regular

    Explanation

    Sign in to read the full explanation
  38. Let L₁ and L₂ over Σ = {a, b} be represented by (a* + b)* and (a + b)* respectively. Which statement is true?

    1. AL₁ ⊂ L₂
    2. BL₂ ⊂ L₁
    3. CL₁ = L₂
    4. DL₁ ∩ L₂ = ∅

    Answer: (C) L₁ = L₂

    Explanation

    Sign in to read the full explanation
  39. Which statement is true?

    1. AThe union of two context-free languages is context-free.
    2. BThe intersection of two context-free languages is context-free.
    3. CThe complement of a context-free language is context-free.
    4. DEvery context-free language can be accepted by a deterministic pushdown automaton.

    Answer: (A) The union of two context-free languages is context-free.

    Explanation

    Sign in to read the full explanation
  40. Which of the following is not an intermediate code form?

    1. ASyntax trees
    2. BThree-address codes
    3. CQuadruples
    4. DPostfix notation

    Answer: (A) Syntax trees

    Explanation

    Sign in to read the full explanation
  41. Which of the following are applications of a compiler symbol table?
    A. Storage allocation
    B. Checking type compatibility
    C. Suppressing duplicate-error messages

    1. A(A) and (B) only
    2. B(A) and (C) only
    3. C(B) and (C) only
    4. D(A), (B), and (C)

    Answer: (D) (A), (B), and (C)

    Explanation

    Sign in to read the full explanation
  42. Let G₁ and G₂ be arbitrary context-free grammars and R an arbitrary regular language. Which problems are undecidable?
    A. Is L(G₁) = L(G₂)?
    B. Is L(G₁) ⊂ L(G₂)?
    C. Is L(G₁) = R?

    1. A(A) only
    2. B(B) only
    3. C(A) and (B) only
    4. D(A), (B), and (C)

    Answer: (D) (A), (B), and (C)

    Explanation

    Sign in to read the full explanation
  43. Consider the languages

    L₁ = {aᶻ | z is an integer},
    L₂ = {a²ᶻ | z > 0}, and
    L₃ = {ww | w ∈ {a,b}*}.

    Which are regular?

    1. AL₁ and L₂ only
    2. BL₁ and L₃ only
    3. CL₂ only
    4. DL₃ only

    Answer: (A) L₁ and L₂ only

    Explanation

    Sign in to read the full explanation
  44. Which grammars are ambiguous?
    A. S → SS | aSb | bSa | a
    B. S → aSbS | bSaS | ε
    C. S → aAB; A → bBb; B → A | ε

    1. A(A) and (C) only
    2. B(A) and (B) only
    3. C(B) and (C) only
    4. D(A), (B), and (C)

    Answer: (D) (A), (B), and (C)

    Explanation

    Sign in to read the full explanation
  45. Match List I with List II:
    Lz: Regular language. LCF: Context free language

    Lec: Recursive language, Lpz: Recursively enumerable language.

    List I List II
    A. Recursively Enumerable language @ LpecULnx
    B. Recursive language CQ). ‘Fee Base
    C. Context Free language (II) Le A Ler

    List IList II
    Items are listed in the question stem.Match each item to its stated description or complexity.
    1. AOCR review required
    2. BOCR review required
    3. CALI, B-II, C-II (4) A-II, B-I, C-III
    4. DOCR review required

    Answer: (C) ALI, B-II, C-II (4) A-II, B-I, C-III

    Explanation

    Sign in to read the full explanation
  46. Consider the following regular expressions:
    (a) r=a(b+a)*

    (b) s=a(a+b)*

    (c) t=aa*b

    1. AOCR review required
    2. BOCR review required
    3. CL(r)DL(t)D L(s) (4) L(s)aL(t)DL(r)
    4. DOCR review required

    Answer: (B) OCR review required

    Explanation

    Sign in to read the full explanation
  47. Given below are two statements:
    Statement I: The problem "Is L; AL; = $?" is undecidable for context sensitive languages
    L, and L3.
    Statement II: The problem "Is WeL?" is decidable for context sensitive language L, (where
    W isa string).
    In the light of the above statements, choose the correct answer from the options given below
    qd) Both Statement I and Statement II are true

    1. AOCR review required
    2. BBoth Statement I and Statement II are false
    3. CStatement I is correct but Statement II is false
    4. DStatement I is incorrect but Statement II is true.

    Answer: (A) OCR review required

    Explanation

    Sign in to read the full explanation

Frequently asked questions

How many Theory of Computation and Compilers questions have been asked in UGC NET Computer Science?

46 Theory of Computation and Compilers questions appear in the UGC NET Computer Science papers held between 2020–2025, and all of them are on this page with their answer key.

Are the answers on this page free?

Yes. Every question, its options, and the correct answer are free to read with no account. Signing in additionally unlocks the detailed explanation under each question.

Is Theory of Computation and Compilers an important topic for UGC NET Computer Science?

Theory of Computation and Compilers appears in every recent UGC NET Computer Science paper, across all 4 sittings covered here. Its share of the paper makes it worth revising thoroughly rather than sampling.

How should I practise Theory of Computation and Compilers after reading these questions?

Attempt the Theory of Computation and Compilers topic-wise sets, which put the same questions into a timed interface with instant scoring and weak-area analysis afterwards.

More Computer Science PYQs by topic

More Computer Science practice

Ready for a full paper?

Attempt Paper 1 + Paper 2 (Computer Science) together in a single timed session.

Full Mock Tests →