Theory of Computation PCCST302 KTU 2024 Scheme - Model Question Paper and Answers
🔍 Step 1: What happens when you Google something
When you type a keyword, say "Turing Machine", Google:
-
Looks through its index of web pages (a huge database of text).
-
Searches for matches — web pages that contain the keyword "Turing Machine".
-
Returns those pages (ranked by relevance).
This is a pattern-matching task — find whether the keyword appears in a document or not.
💡 Step 2: Casting this as a Decision Problem
In automata theory, a decision problem is one that has a yes/no answer.
So, we can define the problem as follows:
Decision Problem:
Given a web page (or document) and a search keyword (pattern) ,
decide whether the keyword appears anywhere in the web page .
✅ Output YES — if appears in
❌ Output NO — if does not appear in
Formal Definition
Let’s define it formally as a decision problem:
PATTERN-MATCHING Problem:
Input: Two strings and , where is the pattern (keyword) and is the text (web page content).
Question: Does occur as a substring of ?
🧩 Step 3: Defining the Language
Every decision problem can be represented as a language —
the set of all inputs for which the answer is “YES”.
So, for this problem, the language is:
That is:
-
Each element of the language is a pair ⟨pattern, text⟩.
-
The pair is in the language if and only if the pattern appears in the text.
🧠 Example
Let’s take:
Since “data” occurs in the web page text,
But:
Then,
⚙️ Step 4: Is this Problem Decidable?
✅ Yes — pattern matching is decidable.
Because:
-
There exists a finite, mechanical procedure (like the Knuth-Morris-Pratt algorithm or even a simple scan)
that can determine in finite time whether appears in .
So, a Turing machine can be constructed to:
-
Read both and
-
Slide along
-
Compare character by character
-
Halt and accept if a match is found, else reject
📘 Final Answer
Concept | Description |
---|---|
Decision Problem | Given a pattern and text , determine whether appears in |
Language | |
Output | YES (accept) if is in ; NO (reject) otherwise. |
Decidability | Decidable — a Turing Machine can check this in finite time. |
However, the class of languages recognized by NFAs (the regular languages) is closed under complement,
because any NFA can be converted to a DFA, and DFAs are closed under complement.
Thus, we can always convert the NFA to an equivalent DFA, complement that DFA, and get an NFA (since DFAs are special cases of NFAs).
Give a context-free grammar that generates the language: Lpair = {a^i b^j c^k} | i = j or j = k, where i, j, k ≥ 0}
this language is the union of two simple context-free patterns:
-
's and 's, arbitrary number of 's), and
-
(equal number of 's and 's, arbitrary number of 's).
A straightforward CFG for
Grammar
Nonterminals: S,S1,S2,A,B,C,DTerminals: {a,b,c}
Start symbol: S
Productions:
S → S1 | S2Construct a PDA to recognize the language generated by the
following grammar:
S → aA
A → aABC | bB | a
B → b
C → c
following grammar:
S → aA
A → aABC | bB | a
B → b
C → c
PDA = (Q, Σ, Γ, δ, q, S, accept-by-empty-stack) where:
-
Q = {q}
-
Σ = {a, b, c}
-
Γ = {S, A, B, C, a, b, c} (we push terminals on the stack too)
-
Start state q, initial stack symbol S. Accept when input is consumed and stack is empty.
Transitions (informal description):
-
For each production
X → α
, add an ε-transition that replaces X on top of stack by the string α (pushed so that the leftmost symbol of α becomes the new top at the time of matching). Concretely (we list pop X then push the RHS in reverse so the terminal that should be matched next is on top):
-
δ(q, ε, S) ⊢ (q, A a)
(replace S byaA
, so pushA
thena
soa
is on top) -
δ(q, ε, A) ⊢ (q, C B A a)
(replace A byaABC
, push in reverse:C
,B
,A
,a
soa
is top) -
δ(q, ε, A) ⊢ (q, B b)
(replace A bybB
, pushB
thenb
) -
δ(q, ε, A) ⊢ (q, a)
(replace A bya
) -
δ(q, ε, B) ⊢ (q, b)
(replace B byb
) -
δ(q, ε, C) ⊢ (q, c)
(replace C byc
)
-
For matching terminals: when the top of the stack is a terminal equal to the current input symbol, consume it and pop it:
-
δ(q, a, a) ⊢ (q, ε)
(reada
, popa
) -
δ(q, b, b) ⊢ (q, ε)
(readb
, popb
) -
δ(q, c, c) ⊢ (q, ε)
(readc
, popc
)
(Other combinations have no moves.)
Trace for input aaabc
Convention: show each configuration as (remaining input, stack)
with the stack top on the left. Start with stack containing the start symbol S
. Accept by empty stack.
Initial: (aaabc, [S])
-
Apply
S → aA
(replaceS
withaA
, pushingA
thena
soa
is top):
(aaabc, [a, A])
-
Match terminal
a
(consume inputa
, popa
):
(aabc, [A])
-
Apply
A → aABC
(replaceA
witha A B C
, pushingC, B, A, a
soa
is top):
(aabc, [a, A, B, C])
-
Match terminal
a
(consumea
, popa
):
(abc, [A, B, C])
-
Apply
A → a
(replaceA
with terminala
, pusha
):
(abc, [a, B, C])
-
Match terminal
a
(consumea
, popa
):
(bc, [B, C])
-
Replace
B → b
(push terminalb
):
(bc, [b, C])
-
Match terminal
b
(consumeb
, popb
):
(c, [C])
-
Replace
C → c
(push terminalc
):
(c, [c])
-
Match terminal
c
(consumec
, popc
):
(ε, [])
Stack is empty and input is consumed → accepted.
If G is a context free grammar and w is a string of length l in L(G), how long is a derivation of w in G, if G is in Chomsky normal form? How would your answer change if G is in Greibach normal form?
If is in Chomsky Normal Form (CNF) and has length , then any complete derivation of uses exactly production applications (steps).(If and CNF allows as the only ε-rule, that derivation has 1 step.)
-
If is in Greibach Normal Form (GNF) and , then there is a leftmost derivation of of exactly steps (one production per terminal). GNF cannot generate except by special convention, so the case is separate.
Brief proofs / reasoning:
CNF. In CNF every non-start production is either or . Let be the number of uses of in a derivation and the number of uses of . Each increases the number of nonterminals on the sentential form by , while each decreases it by . Starting with one nonterminal and ending with zero nonterminals gives
But every terminal in the final string is produced by an application, so . Hence and the total number of productions applied is
GNF. In GNF every production has the form where is a terminal and is (possibly empty) a string of nonterminals. In a leftmost derivation each application replaces the leftmost nonterminal by a production whose first symbol is a terminal, thereby producing exactly one terminal in the leftmost part of the sentential form. So to produce terminals you need exactly leftmost steps. Thus there exists (and naturally we take) a leftmost derivation of length .
For each of the following decision problems about a Turing machine M, indicate whether it is decidable or not.
1. Does M take more than 1008 steps on some input?
2. Does M accept ε?
3. Is L(M) context free?
1. Algorithm: enumerate all strings with (finitely many); simulate on each for 1009 steps. If any simulation reaches step 1009, answer YES; if all simulations finish within ≤1008 steps (or reject) then answer NO. This procedure always halts and is correct. Hence the property is decidable
2. This is the classical acceptance problem restricted to a fixed input. The general acceptance problem
is undecidable. Reduce from it: given build a machine that on input first writes on its tape (or otherwise simulates having as input) and then simulates on ; accepts iff accepts . Thus a decider for “does a TM accept ?” would decide , contradiction. So undecidable.
3.This is a nontrivial language property about the (recursively enumerable) language of a TM. By Rice’s theorem any nontrivial semantic property of the language recognized by a TM (a property that holds for some recursively enumerable languages and fails for others) is undecidable. Being context-free is such a nontrivial property: there exist RE languages that are context-free and RE languages that are not context-free. Therefore it is undecidable to test, given⟨M⟩, whether L(M) is a context-free language.
Let L1 and L2 be Turing-recognizable languages over the same alphabet Σ. Prove that L1 ∩ L2 is also Turing-recognizable.
💡 Step 1. What it means to be Turing-recognizable
A language is Turing-recognizable (or recursively enumerable) if there exists a Turing Machine (TM) that:
-
Accepts every string in .
-
May run forever (does not have to halt) for strings not in .
So the machine doesn’t have to decide; it only needs to recognize.
💡 Step 2. Given two such languages
Let:
-
recognize
-
recognize
We want a new TM that recognizes , i.e.,
it accepts a string only if both and accept it.
💡 Step 3. The key idea — run both machines in parallel
If we just run completely first, it might never halt!
So instead, we simulate both gradually:
-
On input :
-
Run for 1 step.
-
Run for 1 step.
-
Run for another step.
-
Run for another step.
-
Continue alternating forever (this is called dovetailing).
-
Whenever both machines have accepted , our new machine accepts.
💡 Step 4. Why this works
-
If is in both :
Eventually, both and will accept — so our new machine will also accept. -
If is not in both:
At least one of or will never accept,
so our machine will never reach the “both accepted” condition — it runs forever.
(That’s allowed for recognizers.)
✅ Therefore:
The intersection of two Turing-recognizable languages is also Turing-recognizable.
Comments
Post a Comment