Theory of Computation Questions with Answers

25 practice questions on Theory of Computation (Computer Fundamentals) with answers and step-by-step solutions. Try 10 samples below, then practise all 25 free in the AptiNest app.

Sample questions

Question 1Easy

Which type of automaton recognises regular languages?

  1. Pushdown automaton
  2. Finite automaton
  3. Turing machine
  4. Linear bounded automaton

Answer: B. Finite automaton

Explanation

Regular languages are exactly those accepted by DFAs and NFAs.

Step-by-step solution

  1. Regular languages are exactly those accepted by DFAs and NFAs.
  2. So the answer is: Finite automaton.

Why the other options are wrong

  • A. A pushdown automaton recognises context-free languages.
  • C. A Turing machine recognises recursively enumerable languages.
  • D. A linear bounded automaton recognises context-sensitive languages.

Question 2Easy

The set of all strings over alphabet {a} including the empty string is written

  1. a*
  2. a+
  3. a?
  4. a^2

Answer: A. a*

Explanation

The Kleene star allows zero or more repetitions.

Step-by-step solution

  1. The Kleene star allows zero or more repetitions.
  2. So the answer is: a*.

Why the other options are wrong

  • B. a+ excludes the empty string.
  • C. a? is zero or one a.
  • D. a^2 is the string aa.

Question 3Easy

A DFA and an NFA are

  1. Equal in power for recognising languages
  2. DFA is more powerful
  3. NFA is more powerful
  4. They recognise different language classes

Answer: A. Equal in power for recognising languages

Explanation

NFAs may be smaller, but they accept the same class of languages.

Step-by-step solution

  1. NFAs may be smaller, but they accept the same class of languages.
  2. So the answer is: Equal in power for recognising languages.

Why the other options are wrong

  • B. Every NFA can be converted to a DFA.
  • C. An NFA is not more powerful.
  • D. They recognise exactly the regular languages.

Question 4Medium

Regular languages are closed under

  1. Union only
  2. Complement only
  3. Union, intersection and complement
  4. None of these

Answer: C. Union, intersection and complement

Explanation

Regular languages are closed under union, intersection, complement, concatenation, star and reversal.

Step-by-step solution

  1. Regular languages are closed under union, intersection, complement, concatenation, star and reversal.
  2. So the answer is: Union, intersection and complement.

Why the other options are wrong

  • A. They are also closed under intersection and complement.
  • B. They are also closed under union.
  • D. They are closed under union, intersection and complement, so 'none' is wrong.

Question 5Medium

Which language is context-free but not regular?

  1. a*b*
  2. { a^n b^n c^n | n >= 0 }
  3. { a^n b^n | n >= 0 }
  4. (ab)*

Answer: C. { a^n b^n | n >= 0 }

Explanation

A PDA pushes a for each a and pops for each b, so a^n b^n is context-free.

Step-by-step solution

  1. A PDA pushes a for each a and pops for each b, so a^n b^n is context-free.
  2. So the answer is: { a^n b^n | n >= 0 }.

Why the other options are wrong

  • A. a*b* is regular.
  • B. a^n b^n c^n is not context-free.
  • D. (ab)* is regular.

Question 6Medium

Which regular expression denotes strings over {a,b} that end with abb?

  1. a*b*abb
  2. (a|b)*abb
  3. (ab)*abb
  4. (a|b)abb

Answer: B. (a|b)*abb

Explanation

Any prefix over {a,b} followed by abb gives the language.

Step-by-step solution

  1. Any prefix over {a,b} followed by abb gives the language.
  2. So the answer is: (a|b)*abb.

Why the other options are wrong

  • A. a*b*abb restricts the prefix too much.
  • C. (ab)*abb only allows ab repetitions.
  • D. (a|b)abb has exactly four symbols.

Question 7Medium

Context-free languages are NOT closed under

  1. Intersection
  2. Union
  3. Concatenation
  4. Kleene star

Answer: A. Intersection

Explanation

The intersection of two CFLs need not be context-free. For example a^n b^n c^m and a^m b^n c^n.

Step-by-step solution

  1. The intersection of two CFLs need not be context-free.
  2. For example a^n b^n c^m and a^m b^n c^n.
  3. So the answer is: Intersection.

Why the other options are wrong

  • B. CFLs are closed under union.
  • C. CFLs are closed under concatenation.
  • D. CFLs are closed under star.

Question 8Medium

The worst-case number of DFA states from a 4-state NFA is

  1. 16
  2. 8
  3. 4
  4. 24

Answer: A. 16

Explanation

2^4 = 16 subsets.

Step-by-step solution

  1. 2^4 = 16 subsets.
  2. So the answer is: 16.

Why the other options are wrong

  • B. 8 is 2^3.
  • C. 4 is the NFA size.
  • D. 24 is 4!.

Question 9Hard

How many strings of length 4 over {a,b} do NOT contain "aa" as a substring?

  1. 6
  2. 10
  3. 12
  4. 8

Answer: D. 8

Explanation

The count follows the Fibonacci pattern: lengths 1,2,3,4 give 2,3,5,8 strings.

Step-by-step solution

  1. The count follows the Fibonacci pattern: lengths 1,2,3,4 give 2,3,5,8 strings.
  2. So the answer is: 8.

Why the other options are wrong

  • A. 6 undercounts.
  • B. 10 overcounts.
  • C. 12 overcounts.

Tip: To count strings with no 'aa', add the two previous totals: 2, 3, 5, 8 for lengths 1 to 4.

Question 10Hard

Context-sensitive languages are recognised by

  1. Finite automata
  2. Pushdown automata
  3. Mealy machines
  4. Linear bounded automata

Answer: D. Linear bounded automata

Explanation

An LBA is a Turing machine whose tape is limited to the input length.

Step-by-step solution

  1. An LBA is a Turing machine whose tape is limited to the input length.
  2. So the answer is: Linear bounded automata.

Why the other options are wrong

  • A. Finite automata recognise regular languages.
  • B. PDAs recognise CFLs.
  • C. Mealy machines transduce.

Tip: Context-sensitive languages go with a linear bounded automaton, a machine whose tape is limited to the input length.

Practise all 25 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Computer Fundamentals topics · All topics