GATE / CS ARCHIVE

SUBJECT COLLECTION

Theory of Computation · Other / Mixed Topics

9 questions, newest first

Browse topics
2 marks · MCQ
Report issue

Counting descriptions and languages

Other / Mixed Topics

Question 34, GATE 2019: Which sets are uncountable? S1: recursively enumerable languages over {0,1}; S2: syntactically valid C programs; S3: all languages over {0,1}; S4: all nonregular languages over {0,1}. Options A S1/S2, B S3/S4, C S2/S3, D S1/S4.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. A set is countable if its members can be listed using natural-number indices. Finite strings over any finite alphabet can be listed by length and then lexicographic order, so their collection is countable.
2. Each Turing machine has a finite description. There are therefore only countably many such machines and only countably many languages they recognize. Every recursively enumerable language is recognized by a machine, so S1 is countable.
3. Each C program is also a finite string. Restricting the countable set of all strings to those obeying C syntax cannot make it uncountable, so S2 is countable.
4. The set {0,1}* of words is countably infinite, but a language is an arbitrary subset of that set. Its power set is uncountable by Cantor's theorem. Hence S3 is uncountable; confusing words with sets of words is the main trap.
5. Regular languages have finite automaton descriptions, so there are only countably many of them. If S4 were countable too, all languages would be a union of two countable sets, contradicting step 4. Thus S4 is uncountable and the answer is B.

Original paper, page 11 · Answer key

2 marks · NAT
Report issue

Other / Mixed Topics

Question 37, GATE 2014: For A="qpqrr" and B="pqprqrp", let x be the length of a longest common subsequence, not necessarily contiguous, and y the number of distinct such longest subsequence strings. Find x+10y. The source says “number of such longest common subsequences”; the distinct-string convention is used by the keyed result.
Tap to enlarge
Answer & solution

Official answer: 34

Step through it (37 steps)

1. Set up the reasoning. Try to embed the entire five-letter A in B first. After choosing q,p,q in order in B, only one trailing r remains, so no length-five common subsequence exists. Then enumerate the distinct strings obtained by deleting one character from A.

2. Derive the result. The longest common subsequence length for qpqrr and pqprqrp is 4. The distinct length 4 common strings are pqrr, qpqr, qprr. The entire 5-letter first string is not a subsequence of the second, so no longer one exists. Therefore x+10y=4+30=34, counting distinct subsequence strings rather than embeddings.

3. Check the interpretation. Deleting the first, second, or third character gives pqrr, qqrr, qprr; deleting either final r gives qpqr. Of these, qqrr is not a subsequence of B, leaving three distinct length-four strings. Repeated embeddings of one string are not counted separately.

Original paper, page 39 · Answer key

1 mark · MCQ
Report issue

Other / Mixed Topics

Question 16, GATE 2014: For a finite nonempty alphabet Σ, let Σ* be all finite strings and 2^(Σ*) its power set. Which is true? A both countable; B power set countable and Σ* uncountable; C power set uncountable and Σ* countable; D both uncountable.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Step 1: For each length k there are finitely many strings, |Σ|^k. Listing by increasing length and lexicographically within a length enumerates every finite string. Thus Σ* is countably infinite, including when Σ has only one symbol. Step 2: Cantor’s theorem states that the power set of any set has strictly larger cardinality than that set. The power set of a countably infinite set is uncountable. Step 3: Therefore C holds. A language is a subset of Σ*, and there are uncountably many such languages despite only countably many strings.

Original paper, page 56 · Answer key

1 mark · MCQ
Report issue

Determinism and language expressive power

Other / Mixed Topics

Question 8, GATE 2011: Which pair of computational models has DIFFERENT expressive power?

(A) DFA and NFA
(B) Deterministic PDA and nondeterministic PDA
(C) Deterministic single-tape Turing machine and nondeterministic single-tape Turing machine
(D) Single-tape and multitape Turing machines
Tap to enlarge
Your answer
Answer & solution

Official answer: B

DFA and NFA recognize exactly the regular languages. Deterministic/nondeterministic and single/multitape Turing machines recognize the same class, though their efficiencies can differ. DPDAs recognize only deterministic CFLs, a proper subclass of the CFLs recognized by NPDAs. Hence B.

Expressive power asks which languages can be recognized, not how many states are needed or how fast a simulation runs. Subset construction turns an NFA into a DFA, possibly increasing its size. Turing machines can simulate nondeterministic branches by systematic exploration and can simulate extra tapes. A single stack plus deterministic choices is more restrictive: some context-free languages require the nondeterministic choice of how to parse or where to change phases.

Original paper, page 3 · Answer key

2 marks · MCQ
Report issue

Context dependence in C programs

Other / Mixed Topics

Question 2.18, GATE 2002: Classify the C programming language.
(A) Context-free; (B) Context-sensitive; (C) Regular; (D) Fully parsable only by a Turing machine.
Tap to enlarge
Your answer
Answer & solution

Answer: B under the usual syntax-plus-static-constraints interpretation (no official key was published)

Step 1: Distinguish parsing from all static validity checks.

Step 2: A phrase-structure grammar can describe expression and statement shapes while a symbol table checks whether identifier uses agree with their declarations. The latter checks depend on context not captured by merely recognizing those shapes. The answer’s scope is this conventional language-classification question, not a claim that a context-free parser alone proves a C program fully valid or that it decides termination.

Conclusion: C includes context-dependent restrictions such as consistent declarations and uses of identifiers, beyond a context-free phrase-structure grammar. The usual classification including such static checks is context-sensitive, B. A compiler may still use a context-free parser supplemented by symbol-table analysis; this does not make all well-formed C programs a context-free syntax-only language. Runtime behavior and whether a program halts are separate from this classification.

Original paper, page 5

1 mark · MCQ
Report issue

Limits of nondeterminism

Other / Mixed Topics

Question 1.11, GATE 1998: Which GFG claim is false: NFA=DFA, NPDA=DPDA, NTM=DTM, multitape TM=single-tape TM in recognized languages?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Subset construction converts NFAs to DFAs. Turing-machine computation branches can be dovetailed, and tapes can be encoded on one tape, preserving recognized languages though not necessarily runtime. But deterministic PDAs recognize a proper subclass of CFLs: nondeterminism genuinely adds recognition power there. Thus the the paper false statement is B. That source error is disclosed rather than using its letters interchangeably.

Original paper, page 2

2 marks · MCQ
Report issue

Prefixes of equal-count binary strings

Other / Mixed Topics

Question 2.9, GATE 1996: Let init(L)={u:uv∈L for some v}. If L is the set of nonempty binary words with equally many 0s and 1s, determine init(L).
Question 2.9, GATE 1996: Let init(L)={u:uv∈L for some v}. If L is the set of nonempty binary words with equally many 0s and 1s, determine init(L).
Tap to enlarge
Your answer
Answer & solution

Answer: B: {0,1}* (no official key was published)

Take any binary word u. If it has more zeros than ones, append exactly enough ones to balance the counts; if it has more ones, append zeros instead. If its counts are already equal and u is nonempty, append ε; if u=ε, append 01 so the resulting balanced word is nonempty. In every case there exists a suffix v with uv∈L, so every binary word is in init(L). Conversely, every prefix of a binary word is binary. The two inclusions prove init(L)={0,1}*, without requiring the prefix itself to have balanced counts.

Original paper, page 4

Report issue

Counting substring occurrences

Other / Mixed Topics

Question 1.15, GATE 1994: For a character string of length n, how many nonempty contiguous substrings are there when counted by position?
Tap to enlarge
Your answer
Answer & solution

Answer: D: n(n+1)/2 (no official key was published)

A substring of length k can start in n−k+1 positions. Summing for k=1 through n gives n+(n−1)+…+1=n(n+1)/2. Equivalently choose its two boundaries among n+1 boundary positions. This counts occurrences, not necessarily distinct string values: repeated characters can make different positions yield the same word. It also excludes ε. If “substrings of all lengths” includes the empty word or means distinct values, the answer needs that additional convention.

Original paper, page 2

Report issue

When nondeterminism adds recognition power

Other / Mixed Topics

Question 2(xx), GATE 1992: For which machine models does every nondeterministic machine have an equivalent deterministic machine: finite automata, PDAs, TMs, or none?
Question 2(xx), GATE 1992: For which machine models does every nondeterministic machine have an equivalent deterministic machine: finite automata, PDAs, TMs, or none?
Tap to enlarge
Select all that apply
Answer & solution

Answer: A, C (no official key was published)

The subset construction converts an NFA to a DFA recognizing the same language. A deterministic TM can explore the finitely branching computation tree breadth-first or by dovetailing, accepting whenever some nondeterministic branch accepts. Thus nondeterministic TMs recognize no additional languages, though complexity can change. NPDAs recognize all CFLs, while DPDAs recognize only deterministic CFLs, a strict subclass. Consequently the universal equivalence holds for finite automata and Turing machines, but not pushdown automata.

Original paper, page 4