Chapter 5
Theory of Computation
TU BSc CSIT past exam questions
Past questions and answers
69 questions set from this chapter. Most repeated first.
- 2076 · 10 marks
Define the NFA with ε-transition and ε-closure of a state. Show that for every regular expression r, representing a language L, there is ε-NFA accepting the same language. Also convert regular expression (a+b)ab into equivalent Finite Automata.
Answer
ε-NFA. An NFA with ε-transitions is a 5-tuple where is a finite set of states, the input alphabet, the start state, the final states and
so the machine may change state without reading input.
ε-closure. is the set of all states reachable from using zero or more ε-transitions: itself is in it, and if is in it and then is in it. For a set , .
Theorem. For every regular expression there is an ε-NFA with .
Proof (induction on the number of operators in ). We construct with exactly one final state, no transition into the start state and no transition out of the final state.
Basis.
- : two states .
- : two states and no transitions.
- (): .
Induction. Let have ε-NFAs and .
- : add a new start and new final with , , , . A string is accepted iff it is accepted by or .
- : add ; start is , final is . A path goes through (reading a string of ) and then (a string of ).
- : add new start and final with , , , . This accepts and any number of repetitions of strings of .
- : same automaton as .
Each step preserves the three properties and the language, so every regular expression has an equivalent ε-NFA.
Conversion of . Using the construction:
| State | |||
|---|---|---|---|
| 0 (start) | - | - | 1, 7 |
| 1 | - | - | 2, 4 |
| 2 | 3 | - | - |
| 3 | - | - | 6 |
| 4 | - | 5 | - |
| 5 | - | - | 6 |
| 6 | - | - | 1, 7 |
| 7 | - | - | 8 |
| 8 | 9 | - | - |
| 9 | - | - | 10 |
| 10 | - | - | 11, 13 |
| 11 | - | 12 | - |
| 12 | - | - | 11, 13 |
| 13 (final) | - | - | - |
States 0-7 realise (union of 2-3 and 4-5 with loop 6 to 1), 8-9 realise , and 10-13 realise .
Removing ε-moves and merging gives the compact equivalent automaton. The language is the set of strings that contain at least one (take the last ; everything after it is ):
| State | ||
|---|---|---|
Here is accepting: after the first any continuation, being in form, is accepted.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 10 marks
How can you define the language accepted by a PDA? Explain how a PDA accepting language by empty stack is converted into an equivalent PDA accepting by final state and vice-versa.
Answer
Language accepted by a PDA. Let be a PDA. An instantaneous description (ID) is : state, remaining input, stack (top on the left). Moves are written and for zero or more moves. There are two equivalent definitions.
-
Acceptance by final state: The input is consumed and the PDA is in an accepting state; the stack content is irrelevant.
-
Acceptance by empty stack: The input is consumed and the stack is empty; the final-state set is irrelevant.
The two classes of languages are the same (the context-free languages), as shown by the following conversions.
Empty stack to final state. Given with , build
- : push the original start symbol above a new bottom marker and start .
- All moves of are kept in .
- For every : .
If empties its stack on , it exposes and jumps to and accepts. prevents from getting stuck by popping the stack empty prematurely. So .
Final state to empty stack. Given with , build
- : new bottom marker guards against emptying its stack without accepting.
- All moves of are kept.
- For every and every stack symbol : .
- For every : .
When reaches a final state after reading , moves to and pops every symbol, including , ending with an empty stack. If does not accept, never enters , and the stack never becomes empty because stays at the bottom. So .
Hence languages accepted by final state and by empty stack coincide.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 10 marks
Define a Turing machine. Construct a TM that accept L = {wcw^R | w∈(0, 1) and c is ε or 0 or 1. Show that string 0110 is accepted by this TM with sequence of Instantaneous Description (ID).
Answer
Turing machine. A Turing machine is a 7-tuple
where is a finite set of states, the input alphabet, the tape alphabet, the blank, the start state, the accepting states and
the transition function. The machine has an infinite tape with a read/write head; in each move it reads the scanned symbol, writes a symbol, moves left or right and changes state.
Language. is the set of all palindromes over (even length when , odd length otherwise).
Idea. Repeatedly erase the first symbol (remembering it), run to the right end, compare it with the last symbol, erase that, and return to the left. If all symbols are erased (or one is left in the middle), accept.
| State | 0 | 1 | B |
|---|---|---|---|
| (start) | |||
| (carry 0, go right) | |||
| (carry 1, go right) | |||
| (last must be 0) | - | ||
| (last must be 1) | - | ||
| (return left) |
A missing entry means the machine halts without accepting. If or sees , the only remaining symbol was the one just erased (odd palindrome), so the string is accepted. If sees , everything was matched (even palindrome or empty string).
Acceptance of 0110. An ID is written with the head on the first symbol of .
The machine reaches the accepting state , so is accepted.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
Give the formal definition of DFA. Construct a DFA accepting all strings of {0, 1} with even number of 0’s and even number of 1’s.
Answer
Formal definition of a DFA. A deterministic finite automaton is a 5-tuple where
- is a finite set of states,
- is a finite input alphabet,
- is the transition function (exactly one next state for every state and symbol),
- is the start state,
- is the set of accepting (final) states.
A string is accepted if .
DFA for even number of 0s and even number of 1s. Each state records the parity of the 0s and 1s read so far:
- = (even 0s, even 1s), start and final
- = (odd 0s, even 1s)
- = (even 0s, odd 1s)
- = (odd 0s, odd 1s)
| State | 0 | 1 |
|---|---|---|
Reading a 0 flips the 0-parity and reading a 1 flips the 1-parity. Check with (two 0s, two 1s): , which is final, so it is accepted. The string goes , which is not final, so it is rejected.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
Define Chomsky Normal Form and Greibach Normal Form in reference to CFG. Give a suitable example of each.
Answer
Chomsky Normal Form (CNF). A context-free grammar is in CNF if every production has one of the forms
where are variables ( not the start symbol) and is a terminal. (The rule is allowed only if and does not appear on any right side.) Every CFG without can be converted to CNF by removing -productions, unit productions and useless symbols, then replacing terminals inside long right sides by new variables and breaking long right sides into pairs of variables. Derivation trees of CNF grammars are binary trees, and a string of length is derived in exactly steps.
Example. The grammar becomes
Greibach Normal Form (GNF). A CFG is in GNF if every production has the form
where is a terminal and is a (possibly empty) string of variables. Every derivation step therefore produces exactly one terminal at the left end, so a string of length is derived in steps, and the form is useful for building PDAs without ε-moves and for proving that left recursion can be removed.
Example. The same grammar in GNF:
Derivation of : .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
Give the regular expressions for following language over alphabet {0, 1}.
- Set of all strings with 2^nd symbol from right is 1.
- Set of all strings starting with 00 or 11 and ending with 10 or 01.
Answer
(a) Strings over whose 2nd symbol from the right is 1.
The string must end with 1 followed by exactly one more symbol (0 or 1); anything may precede:
Examples accepted: , , , . Rejected: , , .
(b) Strings starting with 00 or 11 and ending with 10 or 01.
For strings of length at least 4 the start and end parts do not overlap, so
generates them (e.g. , , ). The start and end can overlap in the middle symbol for length 3: (starts with 00, ends with 01) and (starts with 11, ends with 10) satisfy the condition but are not generated above, and no shorter string works. The complete expression is therefore
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
Show that language L={0^m1^m | m>=1} is not a regular language.
Answer
Claim. is not regular.
Proof by the pumping lemma. Pumping lemma: if is regular there is a constant such that every with can be written with (i) , (ii) , (iii) for all .
Assume is regular and let be the pumping length. Choose
Since , the substring lies inside the leading block of 0s. So
Pump with :
Because , the number of 0s () is greater than the number of 1s (), so . This contradicts condition (iii). Hence the assumption is false and is not regular.
(Intuitively, a finite automaton has only finitely many states and cannot remember the unbounded count of 0s needed to match the 1s.)
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
Describe the Turing machines with multiple tape, multiple track and storage in state.
Answer
These are variants of the basic Turing machine; none of them is more powerful than the standard single-tape TM, they only make programming easier.
1. Multiple-tape Turing machine. The machine has tapes, each with its own independent read/write head. The finite control reads the scanned symbols together, and in one move it changes state, writes a new symbol on each tape and moves each head left, right or keeps it still:
Input is placed on tape 1; the other tapes start blank. It is convenient, e.g. for or copying: copy the input to tape 2 and compare in reverse. Equivalence: a one-tape TM simulates a -tape machine by storing all tapes on one tape, separated by markers, and marking head positions; each move of the multitape machine takes steps, so a computation of steps is simulated in time. Hence the same languages are accepted.
2. Multiple-track Turing machine. There is one tape and one head, but the tape is divided into tracks, so each cell holds a -tuple of symbols that is read and written as a single symbol. The tape alphabet is . A typical use is marking: the first track holds the input and the second track holds check marks (e.g. primality or divisibility testing, or binary addition with operands on different tracks). It is only a notational convenience, as a standard TM with tape alphabet of tuples is the same.
3. Storage in the finite control (state). The state is made a tuple where is the control state and are stored data items (symbols remembered). Since both and the data are finite, the number of such states is still finite. Example: to test or the palindrome machine, the first symbol is remembered in the state as while the head travels to the other end, and then compared. The machine is still an ordinary TM with a larger set of states.
All three models accept exactly the recursively enumerable languages.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
Construct a NFA accepting language of {0, 1} with each string ending with 01 and convert it into equivalent DFA.
Answer
NFA for strings ending with 01 over .
| State | 0 | 1 |
|---|---|---|
The NFA loops in while reading anything, and guesses the last two symbols: 0 moves to , then 1 moves to .
Conversion to DFA (subset construction). Start with .
- : on 0 ; on 1 .
- : on 0 ; on 1 .
- : on 0 ; on 1 .
No new subsets appear. Final states are those containing : . Renaming , , :
| State | 0 | 1 |
|---|---|---|
Check: : accepted; : rejected.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
Construct a PDA accepting language over {0, 1} representing strings with equal no of 0s and1s. Show by sequence of IDs that 0101 is accepted by this PDA.
Answer
PDA for strings over with equal numbers of 0s and 1s.
Idea: the stack holds the surplus symbol. If the top is the same as the input symbol (or the stack holds only ), push; if it is the opposite symbol, pop (cancel one pair). When the input is finished and only remains, the counts are equal.
(Acceptance is by final state ; equivalently, rule 7 could pop to accept by empty stack.)
Acceptance of 0101 (top of stack on the left):
The input is consumed and the PDA is in the final state , so is accepted.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
Define complexity of a Turing machine. Explain about big Oh, big Omega and big Theta notation used for complexity measurement.
Answer
Complexity of a Turing machine. The complexity of a TM measures the resources it uses on an input of length .
- Time complexity : the maximum number of moves makes on any input of length before halting. is said to be of time complexity (language in ).
- Space complexity : the maximum number of tape cells scanned on any input of length .
For a nondeterministic TM the maximum is taken over all branches of the computation tree. Complexity is described for large using asymptotic notation.
Big Oh (upper bound). if there are constants and such that
It gives an upper bound (worst-case growth). Example: (take for ).
Big Omega (lower bound). if there are constants and such that
It gives a lower bound. Example: with .
Big Theta (tight bound). if there are constants and such that
that is, and . Example: .
Example for a TM: a single-tape machine recognising by repeatedly crossing off a 0 and a 1 takes about steps, so .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2076 · 5 marks
What do you mean by tractable and Intractable problems? Explain with reference to TM.
Answer
Tractable problems. A problem is tractable if it can be solved by a deterministic Turing machine in polynomial time, i.e. in steps for some constant on inputs of length . These problems form the class P:
Examples: sorting, shortest path, searching, matrix multiplication, testing whether a string is accepted by a DFA. A polynomial time algorithm stays practical as grows, and the class is robust: it does not change between reasonable models (multitape TM, RAM), because simulation costs only a polynomial factor.
Intractable problems. A problem is intractable if no polynomial-time algorithm is known, or can exist, so that every algorithm needs super-polynomial (typically exponential) time such as or . Even for moderate (say ) these are unusable, since steps is far beyond any computer.
- Problems solvable in polynomial time by a nondeterministic TM form NP: . A solution can be verified in polynomial time. Clearly ; whether is open.
- NP-complete problems are the hardest in NP: every NP problem reduces to them in polynomial time (Cook's theorem: Satisfiability, SAT). Others: Travelling Salesman (decision form), Hamiltonian circuit, Vertex cover, Clique, 0/1 knapsack. If any NP-complete problem is in P, then .
- Some problems are provably intractable (EXPTIME-complete), and others are undecidable (halting problem), so not solvable at all.
With reference to TM. A problem is tractable if a deterministic TM decides it in at most moves for a polynomial ; it is treated as intractable if the best known deterministic TM needs exponential moves (a nondeterministic TM may still solve it in polynomial time by guessing the solution and verifying it). Example: a deterministic TM trying all assignments for SAT takes exponential time, while a nondeterministic TM guesses an assignment and checks it in time.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 10 marks
Give the formal definition of DFA and NFA. How NFA can be converted into eqivalent DFA? Explain with suitable example.
Answer
DFA (formal definition). A deterministic finite automaton is a 5-tuple with a finite set of states , input alphabet , start state , accepting states and transition function
giving exactly one next state for every state and input symbol.
NFA (formal definition). A nondeterministic finite automaton is a 5-tuple where everything is as above except
so from a state on a symbol the machine may go to zero, one or several states. A string is accepted if at least one path ends in a state of .
Conversion of NFA to DFA (subset construction). Every NFA has an equivalent DFA :
- ; the start state is .
- For a DFA state and symbol : .
- Begin with , compute the transitions, and add each new subset obtained; repeat until no new subset appears.
- .
By induction on , , so . In the worst case the DFA has states.
Example. NFA over accepting strings whose second symbol from the right is 1.
| State | 0 | 1 |
|---|---|---|
Subset construction:
- : 0 , 1
- : 0 , 1
- : 0 , 1
- : 0 , 1
Final states are the subsets containing . Naming , , , :
| State | 0 | 1 |
|---|---|---|
Check: goes (final), accepted; the second symbol from the right is 1. : , rejected, as the second symbol from the right is 0.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 10 marks
Find the minimum state DFA for the given DFA below:
States Input 0 1 A B B E C B *D E E B F B
Answer
The DFA has states , start state , and the only final state is :
| State | 0 | 1 |
|---|---|---|
All six states are reachable from (; ; ), so no state is removed first. Use the partition-refinement (table-filling) method.
Step 0. Separate final from non-final: .
Step 1. For the non-final states look at the groups reached on 0 and 1 (group 1 = , group 2 = ):
| State | on 0 | on 1 |
|---|---|---|
| 1 | 1 | |
| 1 | 1 | |
| 1 | 2 | |
| 1 | 1 | |
| 1 | 1 |
reaches on 1, so it is distinguished: .
Step 2. Groups: , , .
| State | on 0 | on 1 |
|---|---|---|
go to on both symbols; go to on 0 and on 1. So .
Step 3. Check : on 0 both go to ; on 1, and , both in . Check : on 0, , , both in ; on 1 both go to . No further splitting, so .
Equivalent states: and .
Minimum DFA (4 states), with as start state and final:
| State | 0 | 1 |
|---|---|---|
It accepts the strings ending in (for example on ).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 10 marks
Construct a Turing Machine that accepts the language of odd length strings over alphabet {a, b}. Give the complete encoding for this TM as well as its input string w = abb in binary alphabet that is recognized by Universal Turing Machine.
Answer
TM for odd-length strings over .
Idea: the head moves right over the input, toggling between two states (even number of symbols read so far) and (odd number read). At the blank, accept if the machine is in .
| Transition | Meaning |
|---|---|
| even so far, read a symbol | |
| odd so far, read a symbol | |
| end of input with odd length, accept |
There is no move for (even length, including ), so the machine halts and rejects.
For : , accepted.
Encoding for the Universal Turing Machine. Number the states as (the index is the number of 0s), symbols , , , and directions , . A move is coded
(state numbers 1, 2, 3 for ):
| Move | Code |
|---|---|
| = 01010010100 | |
| = 0100100100100 | |
| = 00101010100 | |
| = 0010010100100 | |
| = 00100010001000100 |
The code of is the moves written one after another, separated by and enclosed by :
Input is encoded by writing each symbol as its number of 0s, separated by single 1s: , , so
The tape given to the universal TM is followed by :
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Define the term alphabet, prefix and suffix of string, concatenation and Kleen closure with example.
Answer
Alphabet. An alphabet is a finite, non-empty set of symbols. Examples: (binary), .
String. A finite sequence of symbols from ; is its length and is the empty string (). For , is a string with .
Prefix. A string obtained by removing zero or more symbols from the end of . Prefixes of : . A proper prefix is a prefix other than itself.
Suffix. A string obtained by removing zero or more symbols from the beginning of . Suffixes of : .
Concatenation. For strings and , is followed by , with and . If and then . For languages, ; e.g. .
Kleene closure. For a language (or alphabet ),
It is the set of all strings obtained by concatenating zero or more strings of . Example: for ,
and for , . The positive closure is (when ), e.g. .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Give the regular expressions for the following language over alphabet {a, b}.
- Set of all strings with substring bab or abb.
- Set of all strings whose 3^rd symbol is ‘a’ and 5^th symbol is ‘b’.
Answer
(a) Strings over containing the substring or .
Any string, then one of the two substrings, then any string:
Examples: , , , . Rejected: (no or ), .
(b) Strings whose 3rd symbol is and 5th symbol is .
Positions 1, 2 are free, position 3 is , position 4 is free, position 5 is , and the rest is arbitrary:
Examples: , , . Strings shorter than 5 symbols are not in the language.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Show that L = { a^n | n is a prime number } is not a regular language.
Answer
Claim. is not regular.
Proof by the pumping lemma. If were regular, there would be a pumping length such that any with can be written with , and for all .
Assume is regular and take as its pumping length. Choose a prime (primes are infinite) and let
Write with , , . Then .
Pump with :
Since , both factors are greater than 1: and . So is composite, hence . This contradicts the pumping lemma.
Therefore is not regular.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Explain about the Chomsky’s Hierarchy about the language and programs.
Answer
The Chomsky hierarchy classifies formal grammars, and therefore the languages they generate, into four nested classes according to the form of their production rules. Each class is recognised by a specific kind of machine, so the hierarchy links languages, grammars and the programs (automata) that process them.
A grammar is with variables , terminals , productions and start symbol .
| Type | Grammar | Production form | Language class | Recognising machine |
|---|---|---|---|---|
| 0 | Unrestricted (phrase-structure) | , contains at least one variable | Recursively enumerable | Turing machine |
| 1 | Context-sensitive | , (so ) | Context-sensitive | Linear-bounded automaton |
| 2 | Context-free | , | Context-free | Pushdown automaton |
| 3 | Regular | or (right linear), or the left-linear mirror | Regular | Finite automaton |
Containment. . Every regular language is context-free, every context-free language is context-sensitive, and so on, and each inclusion is proper.
Examples that separate the classes
- Type 3: , generated by . A finite automaton is enough because no counting is needed.
- Type 2: , generated by . It needs one stack to match the counts, so it is not regular.
- Type 1: . It needs two counts to be compared and is not context-free.
- Type 0: the halting language, which is only semi-decidable and needs a full Turing machine.
Relation to programs and programming languages
- Lexical analysis (identifiers, numbers, keywords) is described by regular expressions and implemented with finite automata.
- Syntax of a programming language (nested blocks, balanced brackets, expressions) is described by context-free grammars and implemented by parsers, which are pushdown automata.
- Context-sensitive features such as declaring a variable before use, or matching the number of arguments with the parameters, cannot be captured by a context-free grammar. Compilers check them in the semantic analysis phase.
- Turing machines model any algorithm that a general-purpose program can carry out.
Moving up the hierarchy increases expressive power, but decision problems such as emptiness, membership and equivalence become harder or undecidable.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Define a Push Down Automata. Construct a PDA that accepts L = {a^nb^n | n > 0}
Answer
Definition. A Push Down Automaton (PDA) is a finite automaton with an extra stack. It is a 7-tuple
where is a finite set of states, the input alphabet, the stack alphabet, the start state, the initial stack symbol, the set of final states and
is the transition function. A move means: in state , reading with on top of the stack, go to and replace by the string .
PDA for (acceptance by final state)
with
- (first : push )
- (further 's: push )
- (first : pop )
- (further 's: pop )
- (all 's matched: accept)
Idea: push one for each , pop one for each , and accept when the input is finished and only remains. Since no rule applies to in with on top, the empty string is rejected, as required by .
Trace for
The input is consumed and the PDA is in the final state , so is accepted.
Rejected strings. For the PDA ends in with on the stack and no move, so it is rejected. For the second meets on the stack with no rule for , so it is also rejected. For there is no rule for .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Construct the following grammer into Chomsky Normal Form.
S → abSb | a | aAb
A → bS | aAAb | ε
Answer
Given
Step 1. Remove -productions. Only is nullable. Replace each occurrence of by or nothing in every right-hand side:
- (from dropping one or both 's)
Step 2. Remove unit productions. There are none. All symbols are generating and reachable, so there are no useless symbols.
Step 3. Replace terminals inside longer right-hand sides. Introduce and :
Step 4. Break right-hand sides longer than two variables. Use :
- becomes with and
- becomes with
- becomes with
Grammar in Chomsky Normal Form
Every production now has the form or .
Check with . In the original grammar, . In CNF, , so the same string is generated.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Define Turing Machine and explain its different variations.
Answer
Definition. A Turing Machine (TM) is a mathematical model of computation consisting of a finite control, and an infinite tape divided into cells, with a read/write head that moves left or right one cell at a time. Formally it is a 7-tuple
- : finite set of states
- : input alphabet ()
- : tape alphabet,
- : transition function
- : start state
- : blank symbol
- : set of final (accepting) states
In one move the machine reads the symbol under the head, writes a symbol, moves the head left or right and changes state. The input is accepted if the machine reaches a final state. The class of languages accepted is the recursively enumerable languages.
Variations of the Turing machine
- Multitape TM. Has tapes, each with its own head. A move depends on the state and the scanned symbols, and each head writes and moves independently. It is more convenient to program, but it accepts the same languages as the standard TM. A single-tape machine simulates it with a quadratic slowdown.
- Nondeterministic TM (NTM). gives a set of possible moves. A string is accepted if some sequence of choices leads to acceptance. It has the same power as a deterministic TM, though the simulation may take exponential time.
- Two-way (bi-infinite) tape TM. The tape extends infinitely in both directions. It can be simulated by a standard TM that folds the tape in two tracks.
- Multi-track TM. Each cell holds a tuple of symbols (several tracks). It is a special case of one tape with a larger tape alphabet and is useful for marking.
- Multidimensional TM. The tape is a two- or higher-dimensional grid, and the head can also move up and down. It is again equivalent in power to the standard TM.
- Multihead TM. Several heads on one tape. This is equivalent in power.
- Offline TM and TM with a read-only input tape. Used to study space complexity.
- Restricted TMs. A TM whose tape is bounded by the input length is a linear-bounded automaton (context-sensitive languages). A TM with a stack is a PDA.
- Universal TM. A single machine that reads the description of any other TM and its input and simulates it. This is the theoretical basis of stored-program computers.
All the extended models recognise exactly the same class of languages as the basic TM. They differ only in convenience and efficiency, which supports the Church-Turing thesis.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Whar do you mean by computational Complexity? Explian about the time and space complexity of a Turing machine.
Answer
Computational complexity is the study of the resources, mainly time and space (memory), that an algorithm or machine needs to solve a problem, expressed as a function of the input size . It classifies problems according to how hard they are to solve, rather than just whether they can be solved at all.
Time complexity of a Turing machine. For a TM that halts on every input, the time complexity is
Thus is said to run in time if on every input of length it halts within steps. For a nondeterministic TM, is the maximum over all inputs of length of the length of the longest computation branch. The classes are
Space complexity of a Turing machine. The space complexity is
For a multi-tape TM with a read-only input tape, only the work-tape cells are counted, which allows sub-linear space such as . The classes are , , .
Example. A single-tape TM for that repeatedly crosses off one and one makes about passes of length about , so . It uses no cells beyond the input, so .
Important relations
- (each step touches at most one new cell), so .
- A deterministic machine using space runs in time at most .
- A -tape TM running in time can be simulated by a single-tape TM in time .
- A nondeterministic TM running in time can be simulated by a deterministic TM in time .
- Savitch's theorem: .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2078 · 5 marks
Explain the term Intractability. Is SAT problem is intractable? Justify
Answer
Intractability. A problem is tractable if it can be solved by an algorithm running in polynomial time, for some constant (the class ). A problem is intractable if no polynomial-time algorithm exists for it, or at least none is known, so that the running time grows exponentially (for example or ) and becomes infeasible even for moderate inputs. For an algorithm needs about steps, while a algorithm needs about steps. Such problems may be solvable in principle but not in practical time. Examples are the Travelling Salesman Problem, Hamiltonian Circuit, Vertex Cover and the Knapsack decision problem.
The SAT problem. Given a Boolean formula in the variables , decide whether some assignment of truth values makes true.
Is SAT intractable?
- Brute force is exponential. Trying all assignments takes time.
- SAT is in NP. A proposed assignment (the certificate) can be checked in polynomial time by evaluating the formula.
- SAT is NP-complete (Cook-Levin theorem, 1971). Every problem in NP can be reduced to SAT in polynomial time. Therefore, if SAT had a polynomial-time algorithm, then every problem in NP would, and .
- No polynomial-time algorithm for SAT is known despite decades of effort, and it is widely believed that .
Hence SAT is regarded as intractable. This is a conjecture, because it has not been proved that . Strictly, SAT is intractable if and only if . Restricted versions differ: 2-SAT is solvable in polynomial time (linear time), while 3-SAT remains NP-complete. In practice modern SAT solvers handle many large instances, but worst-case exponential behaviour cannot be ruled out.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 10 marks
Show that, For any NFA N=(Q, ∑, δ, q0, F) accepting language L=∑, There is a DFA D= (Q’, ∑’, q0′, δ’, F’) accepting the same language L.
Answer
Theorem. For every NFA there is a DFA with .
Construction (subset construction).
- : each DFA state is a set of NFA states.
- .
- for and .
- .
is a DFA, since for each and exactly one set is defined. It has at most states. Only the states reachable from need to be built.
Claim. For every string ,
Proof by induction on .
Basis : , and .
Induction step. Assume the claim for and let . Then
by the definition of the extended NFA transition. By the induction hypothesis , so
This proves the claim.
Language equality. For any :
Hence . So every language accepted by an NFA is accepted by a DFA, which means NFAs and DFAs have the same power. (If the NFA has -moves, use -closures in and .)
Example. NFA over accepting strings ending in : , , , .
| DFA state | on 0 | on 1 |
|---|---|---|
| (final) |
The DFA has three reachable states and accepts exactly the strings ending in .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 10 marks
State and prove the Pumping Lemma for regular languages. How can you show with example that pumping lemma is used to prove that a given language is not a regular? Explain.
Answer
Pumping Lemma for regular languages. If is a regular language, then there is a constant (the pumping length) such that every string with can be written as with
- ,
- ,
- for all .
Proof. Let be regular, so it is accepted by a DFA with states. Let with . Let the states visited be where and is final.
Among the first states there are entries but only distinct states, so by the pigeonhole principle for some . Put
Then and . Reading takes from to . Reading takes back to , so is a loop. Reading takes to the final state . Going around the loop times ( skips it) gives the path , so is accepted for every .
Using it to show a language is not regular. The lemma is a necessary condition only, so it can only prove non-regularity. It is used as a game against an adversary:
- Assume is regular, with pumping length (given by the adversary).
- Choose a string with (our choice, depending on ).
- The adversary splits with and . We must handle every such split.
- Choose so that . This contradicts the lemma, so is not regular.
Example. is not regular.
Assume it is regular with pumping length and take , . Since , both and lie entirely in the block of 0's, so with . Pump up with :
which has more 0's than 1's and is not in . This contradicts condition 3, so is not regular.
The same method (choosing or ) shows that , and the set of balanced parentheses strings are not regular.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 10 marks
Given the following expression grammar for simple arithematic expression with operator + and *.
E→ E+T | T
T → T+F | F
F → (E) | a
Remove the left recursion from this grammar then simplify and convert to CNF.
Answer
Grammar as given:
Step 1. Remove left recursion. A rule becomes .
Step 2. Simplify.
Remove -productions. and are nullable. Producing the variants with and without them:
Remove unit productions and . First is replaced by the productions of ; then by those of :
All symbols are reachable from and generate terminal strings, so there are no useless symbols.
Step 3. Convert to CNF. Introduce , , for terminals inside longer right-hand sides, and break long right-hand sides with , , :
Every production has the form or , so the grammar is in Chomsky Normal Form. The start symbol does not derive and the language is unchanged.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Explain the ε-closure of states on an ε-NFA with suitable examples.
Answer
An -NFA is an NFA that can change state without reading any input symbol (-transitions): .
Definition. The -closure of a state , written , is the set of all states reachable from by following zero or more -transitions. It is defined recursively:
- .
- If and , then .
For a set of states , .
Example. Consider the -NFA with transitions
- (via )
The -transition from is not followed, because only -moves count.
Use. The closure defines the extended transition function: and . It is also what is used to convert an -NFA to a DFA: the start state is , and . In the example, on from we reach .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Convert the following regular expression into equivalent Finite Automata
a. (0+1)10(1+0)
b. 10(0+1)*1
Answer
(a)
The language is all strings of length at least 3 whose third-last symbol is and second-last symbol is (any last symbol). The NFA guesses when the final three symbols begin.
States (start), with final.
| State | 0 | 1 |
|---|---|---|
Subset construction gives the equivalent DFA, with , , , , , final states :
| State | 0 | 1 |
|---|---|---|
Check on : , final, accepted. Check on : , final, accepted. Check on : , not final, rejected, since its last three symbols are , not .
(b)
The language is strings that, after any number of leading 1's, have a , then anything, and end with a .
States (start), , (final).
| State | 0 | 1 |
|---|---|---|
The equivalent DFA has , , (final):
| State | 0 | 1 |
|---|---|---|
Check: : , accepted. : , accepted. : ends in , rejected. : stays in , rejected.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Define the term: Parse Tree, left-most and right-most derivation, sentential form and ambiguity with example.
Answer
Consider the grammar : .
Parse tree (derivation tree). A tree showing how a string is derived from the start symbol. The root is the start symbol, each interior node is a variable, and its children are the symbols of the right-hand side of the production applied. The leaves, read left to right, form the derived string (the yield). For with the right , the tree for is
E
/ | \
E + E
| /|\
id E * E
| |
id id
Left-most derivation. At every step the left-most variable is replaced.
Right-most derivation. At every step the right-most variable is replaced.
Sentential form. Any string of terminals and variables derivable from the start symbol, such as , , . If it contains only terminals, it is a sentence of the language. A left-sentential form arises in a left-most derivation, and a right-sentential form in a right-most derivation.
Ambiguity. A grammar is ambiguous if some string in its language has two or more distinct parse trees, or equivalently two or more distinct left-most (or right-most) derivations. The grammar above is ambiguous for . The second left-most derivation is
Its tree groups the string as , whereas the first tree groups it as . The two trees give different meanings, which is why ambiguity is a problem in compilers. It is removed by rewriting the grammar to enforce precedence and associativity, for example .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Give the formal definiton of Push Down Automata. How CFG can be converted into equivalent PDA. Explain with an example.
Answer
Formal definition. A Push Down Automaton is a 7-tuple
- : finite set of states
- : input alphabet
- : stack alphabet
- finite subsets of : transition function
- : start state
- : initial stack symbol
- : final states
It accepts either by final state, , or by empty stack, .
Converting a CFG to an equivalent PDA. Let . Build a PDA with one state that accepts by empty stack:
- For each variable : (replace the top variable by the right-hand side of a production).
- For each terminal : (match the input symbol with the top of the stack and pop it).
The stack holds the unprocessed part of a left-most derivation, so accepts exactly when , giving .
Example. : , generating . The PDA has
Accepting (top of stack on the left):
where the move uses . The stack is empty with the input consumed, so is accepted, matching the derivation .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Define regular grammar. Also explain the method of converting right linear grammar into equivalent finite automata.
Answer
Regular grammar. A grammar is regular if all its productions are of one of the two restricted forms:
- Right linear: or (or ), with and .
- Left linear: or .
A grammar must use only one of the two forms to be regular. The languages generated by regular grammars are exactly the regular languages, those accepted by finite automata.
Converting a right-linear grammar to a finite automaton. Build an NFA as follows.
- : one state for each variable plus a new final state .
- The start state is .
- For each production , add to .
- For each production , add to .
- For each production , make a final state as well.
- (plus any with ).
A derivation corresponds exactly to a path in the NFA that reads and ends in . The NFA can then be converted to a DFA by the subset construction.
Example. .
Transitions: , , , and .
| State | ||
|---|---|---|
The language is (a block of 's, or any number of 's followed by at least two 's).
Check on : , accepted. It matches the derivation . The string ends in the non-final state and is rejected, which agrees with the grammar since must still produce at least one more .
A left-linear grammar can be handled by reversing its productions, building the automaton for the reversed language, and then reversing that automaton.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Construct a Turing machine that accepts the language, L = { a^n b^n | n≥0}
Answer
Idea. Mark one with and then the matching with , and repeat. When no is left, check that no unmarked remains.
Meaning of states
- : look for the next unmarked at the left.
- : move right to find the first unmarked .
- : move left back to the last .
- : all 's are marked; verify only 's remain.
- : accept.
Transitions (written as )
| State | |||||
|---|---|---|---|---|---|
| , | , | ||||
| , | , | ||||
| , | , | ||||
| , | , | , |
A blank entry means no move, so the machine halts and rejects. The empty string () is accepted directly by on .
Trace for (the head position is shown by the state before the scanned symbol):
The machine reaches , so is accepted.
Rejection examples. For : after marking both 's and the single , returns to , which finds , goes to , reaches with no rule and halts. For : after one pair is marked, reads , goes to , finds an unmarked and halts with no rule. For : reads and halts.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Define Turing machine and its roles.
Answer
Definition. A Turing machine is an abstract computing device made of a finite control, an infinite tape divided into cells, and a read/write head. In each move, depending on the current state and the scanned symbol, it writes a symbol, moves the head one cell left or right, and changes state. Formally it is a 7-tuple
where is the set of states, the input alphabet, the tape alphabet, the transition function, the start state, the blank, and the accepting states.
Roles of the Turing machine
- Language acceptor (recogniser). A TM accepts exactly the recursively enumerable languages. If the string belongs to the language the machine halts in an accepting state. Otherwise it halts and rejects or runs forever.
- Language decider. A TM that halts on every input decides a recursive language, so it can answer yes/no problems.
- Computer of functions. The TM can compute any function that is computable. For example, it can compute addition, subtraction and multiplication in unary, by leaving the result on the tape. Such functions are called Turing-computable (partial recursive).
- Model of an algorithm. By the Church-Turing thesis, anything that can be computed by an algorithm can be computed by a TM, so the TM gives a precise definition of "algorithm" and "computable".
- Basis for decidability. It is used to show that some problems, such as the halting problem, are undecidable.
- Basis for complexity theory. Time and space are measured as the number of moves and tape cells used, which defines the classes , and .
- Universal machine. A universal TM simulates any other TM, which is the model of the stored-program computer.
- Generator (enumerator). A TM can list all the strings of a language.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Explain about the complexity classes p, NP and NP-Complete.
Answer
Complexity classes group decision problems by the resources (time and space) a Turing machine needs to solve them.
Class P. The set of decision problems solvable by a deterministic Turing machine in polynomial time, . These are regarded as tractable. Examples are sorting, shortest path, searching, primality testing, and checking whether a graph is connected.
Class NP. The set of decision problems solvable by a nondeterministic Turing machine in polynomial time, . Equivalently, a "yes" answer has a certificate (a proof) that a deterministic machine can verify in polynomial time. Examples are Satisfiability, Hamiltonian Circuit, Clique, Vertex Cover, Subset Sum and the decision form of the Travelling Salesman Problem. Clearly , and whether is still an open problem.
NP-hard. A problem is NP-hard if every problem in NP reduces to in polynomial time ( for all ).
NP-complete. A problem is NP-complete if
- , and
- is NP-hard.
NP-complete problems are the hardest problems in NP. Cook's theorem (1971) shows that SAT is NP-complete, and other problems are shown to be NP-complete by reducing a known NP-complete problem to them in polynomial time: . A polynomial-time algorithm for any one NP-complete problem would imply .
Relation. . If (the widely held belief), then NP-complete problems lie in . If , then every problem in NP (other than the trivial ones) is NP-complete. NP-hard problems need not be in NP (the halting problem is an example).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 · 5 marks
Write short notes ( Any two ) :
a) Big Oh, Big Omega and Big Theta
b) Tractable and Intractable Problems
c) Chomsky Hierarchy
Answer
(a) Big Oh, Big Omega and Big Theta
These notations describe the growth rate of an algorithm's running time for large .
- Big Oh (upper bound). if there exist constants and such that for all . It gives the worst-case bound. For example, since for .
- Big Omega (lower bound). if there exist and such that for all . For example, .
- Big Theta (tight bound). if there are constants and such that for all . This is equivalent to and . So .
(b) Tractable and intractable problems
A problem is tractable if it has an algorithm that runs in polynomial time in the input size; these problems are in the class and are solvable in practice for large inputs (sorting, shortest path, matrix multiplication). A problem is intractable if the best known algorithms need super-polynomial (typically exponential) time, such as or , which makes them infeasible for large (Travelling Salesman, Hamiltonian Circuit, SAT, Knapsack decision). Most NP-complete problems are considered intractable unless . Some problems, like the halting problem, are even undecidable, which is a stronger form of unsolvability than intractability.
(c) Chomsky hierarchy
It classifies grammars into four nested types by the form of their productions: Type 3 regular (), recognised by finite automata; Type 2 context-free (), recognised by pushdown automata; Type 1 context-sensitive (), recognised by linear-bounded automata; Type 0 unrestricted (), recognised by Turing machines. Then . For example, is regular, is context-free but not regular, and is context-sensitive but not context-free.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 10 marks
How does Turing machine accept a string? Design a Turing Machine over the alphabet {0,1,a} that processes the string defined by L = {a01a,a10a,a0101a}. Show both transition diagram and table. Show acceptance of a0101a.
Answer
How a TM accepts a string. The string is written on the tape, with blanks elsewhere, and the head starts on its first symbol in the start state . The machine follows . The string is accepted if the machine enters an accepting (final) state, at which point it halts. It is rejected if the machine halts in a non-final state, or reaches a configuration with no defined move. The language of the TM is the set of accepted strings.
Design. The language is finite, so the TM reads the string left to right and checks it against a tree of the three strings. It never writes anything new (it rewrites the scanned symbol) and always moves right. After the final it checks for a blank so that nothing extra follows.
Transition table (, blank cell means no move)
| State | ||||
|---|---|---|---|---|
| , | , | , | ||
| , | , | |||
| (read ) | , | , | , | |
| (read ) | , | , | ||
| (end read) | , | , | , | |
| (read ) | , | , | , | |
| (read ) | , | , | , | |
| (read ) | , | , | , | |
| (read ) | , | , | , | |
| , | , | , | , |
Transition diagram (edges labelled )
q0 --a/a,R--> q1 --0/0,R--> q2 --1/1,R--> q3 --a/a,R--> q4 --B/B,R--> (qf)
| | ^ ^
| +--0/0,R--> q6 --1/1,R--> q7 --a/a,R--+
| |
+--1/1,R--> q5 --0/0,R--> q8 --a/a,R---------------------------------+
(the arrows from and both lead to ).
The three accepted paths are
- :
- :
- :
Acceptance of (the head is on the symbol after the state):
The machine halts in the final state , so is accepted. Any other string, for example , reaches a configuration with no move (here reading ) and is rejected.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 10 marks
Define context free grammar with an example. Explain with example, how context free grammar is converted to Chomsky Normal Form.
Answer
Context-free grammar (CFG). A CFG is a 4-tuple where is a finite set of variables, a finite set of terminals, a finite set of productions of the form with and , and the start symbol. The left side is always a single variable, which makes it "context free".
Example. : generates . A derivation is .
Chomsky Normal Form (CNF). Every production is either (two variables) or (one terminal). Every CFG whose language does not contain has an equivalent CNF grammar.
Conversion steps
- Add a new start symbol if appears on a right-hand side.
- Remove -productions: find nullable variables and add the versions of each production with them omitted.
- Remove unit productions by copying the productions of to .
- Remove useless symbols (non-generating and unreachable).
- Replace each terminal occurring in a right-hand side of length by a new variable with .
- Break right-hand sides of more than two variables: becomes .
Example. Convert .
Step 1. New start: .
Step 2. Nullable: (as ), then (as ). is not nullable. Remove :
The rule is dropped as trivial.
Step 3. Unit productions , , :
Step 5 and 6. Add and (to shorten to ):
All productions are now of the form or , so the grammar is in CNF.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
Define string, substring, empty string, and empty language over alphabet {a,b}.
Answer
Let the alphabet be , a finite non-empty set of symbols.
String. A finite sequence of symbols chosen from , for example , , , . The number of symbols is its length, . The set of all strings over is .
Substring. A string is a substring of if for some strings , that is, occurs as a contiguous block in . The substrings of are . The string is not a substring of (it is only a subsequence). A prefix is a substring at the start () and a suffix is a substring at the end ().
Empty string. The string with no symbols, written (or ), with . It is the identity for concatenation: . It belongs to every .
Empty language. The language containing no strings at all, written or . It is different from the language , which contains exactly one string, the empty string. Over , has strings, whereas has . For any language , and .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
Design a DFA that accepts single line and multi-line comments of the C-Language.
Answer
Comment forms in C
- Single line: starts with
//and continues to the end of the line (newline). - Multi-line: starts with
/*and ends at the first*/. It may contain newlines, and the body can contain*and/characters.
The DFA accepts a string if it is exactly one complete comment. Input classes: /, *, n (newline) and o (any other character).
States
- : start.
- : read
/. - : inside a single-line comment.
- : inside a multi-line comment.
- : inside a multi-line comment, just read
*. - : read the closing
*/(final). - : the newline ended a single-line comment (final).
- : dead (trap) state.
Transition table
| State | / | * | n | o |
|---|---|---|---|---|
Final states: .
Diagram
q0 --/--> q1 --/--> q2 (loop on / * o) --n--> ((q6))
|
+--*--> q3 (loop on / n o) --*--> q4 (loop on *) --/--> ((q5))
^ |
+-------- o, n -----------+
Tests.
/* hi **/: , loops on the text, then*to ,*stays ,/to . Accepted.// x*/ yfollowed by a newline: , stays in on all characters until the newline moves it to . Accepted./* a /: ends in , not final, rejected./*/: (the/loops in ), not final, so correctly rejected as an unterminated comment.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
Write regular expression over {a,b} that represents
a. Strings having exactly two a’s and atleast two b’s.
b. Strings having an even number of a’s and each a followed by at least one b.
Answer
(a) Exactly two 's and at least two 's
The two 's split the string into three blocks of 's: with . The condition holds when some block has at least two 's, or two different blocks each have at least one . Taking the union of all these cases:
Check: has the blocks , matched by the third term. has only 2 's in blocks , matched by the fifth term. has only one and is not matched. has 's at the ends with 2 's in the middle, matched by the second term.
(b) Even number of 's, each followed by at least one
Each must be immediately followed by , so the string consists only of the blocks and (so there is no and the string does not end with ). It must contain an even number of blocks, so these come in pairs:
Here each is followed by any number of further 's, and the blocks are grouped in pairs, which gives an even count of 's. It also includes and all strings of 's (zero 's). For example , , are accepted, while (odd count), and are not.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
Using pumping lemma, prove that the language L = {a^ib^jc^k | j=i+k} is not regular.
Answer
Let . Assume is regular. Then by the pumping lemma there is a pumping length such that every with can be written with , and for all .
Choice of string. Take and , so :
Splitting. Since , the substring lies entirely within the first symbols, which are all 's. So for some , and
Pumping. For :
In this string , and , so because . Hence . (Pumping down with gives , which also fails.)
This contradicts the pumping lemma, so the assumption is false. Therefore is not regular.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
Design a PDA over {x,y} which accepts strings defined by the language L = {x^ny^nxy | n>=0}. Show acceptance of xyxy.
Answer
Language. contains (), (), (), and so on. The idea is to push an for each leading , pop one for each , and then check that the remaining input is exactly . For the very first is the one in the suffix, so on the first the PDA guesses nondeterministically whether it is part of or the final .
, accepting by final state.
Transitions
- (first : push, or guess it is the final when )
- (push more 's)
- (first : pop)
- (pop for each further )
- (stack empty of 's: the number of 's equals the number of 's, read the final )
- (read the final , accept)
Acceptance of (; the top of the stack is on the left):
The input is consumed in the final state , so is accepted. The other branch from the first move, , has no further move with input left, so it dies and does not affect acceptance.
Other checks. : , accepted (). : after pushing and popping one , the next meets in , where there is no move, so it is rejected. fails because has no move on with on top.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
Design a Turing machine that computes a function f(n)=0.
Answer
Idea. Represent the natural number in unary as on the tape (the rest blank ). The function must output the unary form of , i.e. an empty (all-blank) tape. So the machine simply erases every and halts.
Machine. with
| State | Symbol read | Move |
|---|---|---|
Working. In the head overwrites each by and moves right. When it meets the first blank all the s have been erased, so it enters the halting state .
Example, (input ):
The tape is now blank, which is the unary representation of , so the machine computes . For the head sees immediately and halts with a blank tape, so as well.
(If the convention is that the output is written as a single symbol, replace the move by with ; the rest is unchanged.)
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
How abstract, decision and optimization problems are different from each other?
Answer
Abstract problem. An abstract problem is a binary relation between a set of problem instances and a set of problem solutions. It states what is to be solved without fixing any encoding, e.g. "given a graph and vertices , relate it to the paths from to ". An instance may have many solutions.
Decision problem. An abstract problem whose answer is only YES/NO, i.e. . Example: : "Is there a path from to in with at most edges?"
Optimization problem. An abstract problem in which every instance has many feasible solutions, each with a value, and we must find one with the best (minimum or maximum) value. Example: "Find a shortest path from to in ."
| Basis | Abstract problem | Decision problem | Optimization problem |
|---|---|---|---|
| Nature | General relation instance solution | Special case with answer in | Special case asking for best solution |
| Output | Any solution(s) | One bit | A solution and its optimal value |
| Example | Paths in a graph | Is there a path of length ? | Shortest path |
| Use in complexity | Needs encoding to be analysed | Classes P, NP are defined on these | Converted to decision form for study |
Relation. Complexity theory studies decision problems because they fit languages: the set of YES-instances (suitably encoded as strings) is a language. An optimization problem is turned into a decision problem by adding a bound ("is there a solution of value ?"). If the decision version is hard, the optimization version is at least as hard.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
How is PDA to CFG conversion done? Consider a PDA that accepts by empty stack, P=({p,q},{0,1},{Z},δ,p,z); with δ defined as
δ(p,0,z)=(p,0z), δ(p,0,0)=(p,00), δ(p,1,0)=(p,ε), δ(p,ε,z)=(q,ε),
Now construct an equivalent CFG.
Answer
PDA to CFG conversion. Let accept by empty stack. The grammar has variables
- (start symbol), and
- for all , . The variable generates exactly the strings that take from state with on top of the stack to state having popped (net effect) while reading .
Productions:
- For every state : .
- If contains with (), then for all choices of states :
- If contains then .
Given PDA. (the stack alphabet must contain and , since both are used), with
Productions.
Start: .
From :
From :
From : .
From : .
Simplification. There are no moves out of , so have no productions and are non-generating. Removing every production that uses them also makes and non-generating (each needs one of the dead variables or itself only). What remains:
Renaming , :
Check. The string : . The PDA does it by pushing twice, popping on each , then popping by the -move into (stack empty). Hence .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 · 5 marks
What is the meaning of the term “Context Free” in context free grammar? Justify with a suitable example. What is the need of a parse tree?
Answer
Meaning of "context free". In a context free grammar every production has the form with a single variable on the left. The variable can be replaced by wherever it occurs, regardless of the symbols (the context) surrounding it. Contrast this with a context sensitive grammar, whose rules allow to be rewritten only when it appears between and .
Example. generates . The symbol is rewritten in the same way whether it is the first symbol, in the middle of , or anywhere else:
The step never looks at the neighbours of ; this independence from context is what "context free" means. Such grammars generate exactly the languages accepted by pushdown automata.
Need for a parse tree. A parse tree is a tree with root , internal nodes labelled by variables, and leaves labelled by terminals or ; the children of a node are the right-hand side of the production applied there. It is needed because
- it shows the structure of a string (how it is derived) independently of the order in which variables are expanded;
- the yield (leaves read left to right) is the derived string;
- it is used to detect ambiguity: two different parse trees for one string means the grammar is ambiguous;
- compilers use it to check syntax and to attach meaning (code generation, expression evaluation, operator precedence).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 10 marks
Mention the transition function of PDA. List the two ways that PDA accepts the string. Convert the following CFG to PDA.
S → AS | ε
A → Ab | Bb | ab
Answer
Transition function of a PDA. A PDA is and
(finite subsets). means: in state , reading input ( means no input consumed) with on top of the stack, the PDA may move to and replace by the string (top at the left).
Two ways of acceptance.
- Acceptance by final state: , the input is consumed and the PDA is in a final state, whatever the stack holds.
- Acceptance by empty stack: , the input is consumed and the stack is empty. The two methods accept the same class of languages (the context free languages).
CFG to PDA. Grammar:
(There is no production for , so can never be removed from the stack; the production is therefore never used in a successful run. It is still converted as written.)
Construct the one-state PDA accepting by empty stack: where
- For each variable, an -move replaces it by the right side of one of its productions:
- For each terminal, a matching move pops it:
Check. Input ():
The stack is empty after all input is read, so is accepted.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 10 marks
Define Turing machine as enumerators of strings of a language. Encode the Turing machine TM = ({q_0, q_1, q_2} , {a, b}, {a, b, B}, δ, q_2, B, F) with input w = ba and δ is defined as follows:
δ(q_0, b) → (q_1, b, R), δ(q_1, a) → (q_2, a, R), δ(q_2, a) → (q_1, a, R), δ(q_2, b) → (q_2, b, L)
Answer
Turing machine as an enumerator. An enumerator is a Turing machine with a work tape and an extra output tape (printer). Started on a blank tape, it runs (possibly forever) and, from time to time, writes a string of the language on the output tape followed by a separator. The language of the enumerator is the set of all strings it ever prints. Strings may be printed in any order and may be repeated. A language is recursively enumerable exactly when some enumerator prints it:
- Enumerator TM: on input , run and accept as soon as is printed.
- TM Enumerator: for generate every string up to length and run on it for steps; print if accepts within the limit.
Encoding the TM. Use the standard binary code: each state , each tape symbol and each direction is written as a block of s, and the blocks are separated by single s.
| Item | Code | Item | Code | |
|---|---|---|---|---|
A move is coded as (using the block lengths above). Hence:
| Move | Code |
|---|---|
The moves are written one after another separated by , and the whole description is enclosed by at both ends:
The input is coded symbol by symbol with as separator: . The encoded pair for a universal machine is
(The start state is given as and is not listed, so these are supplied to the simulator as extra header fields.)
Behaviour on . Starting in on : moves the head left of the input onto a blank, and no move is defined for , so the machine halts without reaching a final state (the input is rejected).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
Does machine always refer to hardware? Justify. Define positive closure and Kleene closure.
Answer
Does machine always refer to hardware? No. In the theory of computation a "machine" is an abstract mathematical model of computation, not a physical device. Finite automata, pushdown automata and Turing machines are defined by states, symbols and transition rules and are studied on paper; they can be realised in hardware, in software, or not at all. Software artefacts such as a virtual machine (JVM), an interpreter or a compiler's lexical analyser (a finite automaton) are also "machines" even though they contain no new hardware. Their purpose is to reason about what can be computed, and how efficiently, independent of any particular computer.
Positive closure. For an alphabet , the positive closure is the set of all strings of length at least one:
For a language : (one or more concatenations of strings of ).
Kleene closure. It also includes the empty string:
Example: for , and . For : and . Thus iff .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
What is undecidable problem? Discuss about Post Correspondence Problem.
Answer
Undecidable problem. A decision problem is decidable if some Turing machine (algorithm) halts on every input and answers YES/NO correctly. It is undecidable if no such algorithm exists: the language of its YES-instances is not recursive. A problem may be semi-decidable (a TM halts on YES but may loop on NO), e.g. the halting problem and the question "is ?" is undecidable too. Other undecidable problems: whether a CFG is ambiguous, whether two CFGs generate the same language.
Post Correspondence Problem (PCP). An instance consists of two lists of strings over of equal length:
The question: is there a sequence of indices (, repetitions allowed) such that
Example with a solution. , . Take the sequence :
The two strings are equal, so this instance has a solution.
Example without a solution. , : the -string is always longer than the -string.
Undecidability. There is no algorithm that decides, for every instance, whether a solution exists. Proof idea: first show that the Modified PCP (the match must start with pair 1) is undecidable by reducing the acceptance problem to it. Given and , build pairs so that a partial match simulates the successive configurations of on , with the -string running one configuration ahead; a complete match exists iff reaches an accepting configuration. Then MPCP reduces to PCP. Since is undecidable, so is PCP. PCP is the standard tool for proving that problems about CFGs (ambiguity, equivalence, emptiness of intersection) are undecidable.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
Define the language of a grammar. For the grammar S → 0S0 | 1 | ε, show the leftmost derivation for the string 00100 with its parse tree.
Answer
Language of a grammar. For a grammar the language is the set of all terminal strings derivable from the start symbol:
Grammar: . It generates (), i.e. even-length strings of s and palindromes with a single in the centre.
Leftmost derivation of (there is only one variable at each step, so every step is leftmost):
The first two steps use , the last uses .
Parse tree.
S
/ | \
0 S 0
/ | \
0 S 0
|
1
Reading the leaves left to right gives the yield , so .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
Define ε-closure of a state. Differentiate between Moore and Mealy machine.
Answer
-closure. In an NFA with -transitions, is the set of all states reachable from by following zero or more -transitions. It always contains itself, and if is in it and then is in it. For a set of states , .
Example: if and then .
Moore vs Mealy machine. Both are finite state machines with output (no final states).
| Basis | Moore machine | Mealy machine |
|---|---|---|
| Output depends on | Present state only | Present state and present input |
| Definition | with | Same, but |
| Output attached to | States | Transitions |
| Output length for input of length | (includes output of initial state) | |
| Number of states | Usually more | Usually fewer |
| Output timing | Changes only on a state change (after clock) | Can change as soon as the input changes |
| Response to input | Delayed by one step | Immediate |
Every Moore machine has an equivalent Mealy machine and vice versa (ignoring the extra first output of the Moore machine).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
Represent the following regular grammar to finite automata.
S → aA | aB | ε
A → aA | aS
B → bB | ε
Answer
Method. The grammar is right-linear (each production is or ). Build an NFA whose states are the variables:
- gives the transition ;
- makes a final state;
- the start state is .
Grammar: .
NFA :
| State | ||
|---|---|---|
( marks final states: and .)
Transitions as edges: , , , , .
Equivalent DFA (subset construction): start .
| State | ||
|---|---|---|
All subsets containing or are final; is the dead state. The language is : for example , , , are accepted, while is rejected.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
Design the DFA that accepts binary string ending with “00” and show its extended transition function for the string 111000.
Answer
Design. Track how many trailing s the string read so far ends with (up to two).
- : start; the last symbol is not a (or nothing read yet).
- : the string ends with exactly one .
- : the string ends with (final state).
| State | ||
|---|---|---|
A always returns to ; a moves and stays at .
Extended transition function on , using :
Since , the string is accepted.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
Convert the following grammar to CNF.
S → AAB, A → aA | ε, B → ab | a
Answer
Grammar: .
Step 1: remove -productions. Only is nullable. Replace each production containing by all versions with and without :
- (dropping the first , the second , or both)
Step 2: remove unit productions. is replaced by the productions of : .
(No useless symbols; since is never empty.)
Step 3: terminals in long bodies. Introduce , and replace in bodies of length :
Step 4: break bodies longer than 2. becomes , .
Chomsky Normal Form:
Every production is of the form or .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
- For the following Turing Machine, test whether the string “( ) ( )” is accepted or rejected and represent it in transition diagram. [5]
| State | ( | ) | X | Y | B |
|---|---|---|---|---|---|
| q0 | (q1, X, R) | – | – | (q0, Y, R) | (q3, B, R) |
| q1 | (q1, (, R) | (q2, Y, L) | – | (q1, Y, R) | – |
| q2 | (q2, (, L) | – | (q0, X, R) | (q2, Y, L) | – |
| q3 | – | – | – | (q3, Y, R) | (q4, B, R) |
| q4 | – | – | – | – | – |
Answer
Reading the machine. From the table (start state , has no moves and is the accepting state):
- : on
(write , go to , move R; on skip right; on go to (all brackets matched). - : skip right over
(and ; on)write , go to , move L. - : move left over
(and ; on go to , move R. - : skip s; on go to (accept).
This marks each ( with and the first following unmatched ) with : it accepts balanced parentheses.
Test on ( ) ( ). Tape: ( ) ( ) B. Instantaneous descriptions (the state is written just before the scanned symbol):
The machine reaches with no further moves, so the string ( ) ( ) is accepted.
Transition diagram (edges labelled read / write, move):
q0 --( / X,R--> q1 q0 --Y / Y,R--> q0 q0 --B / B,R--> q3
q1 --( / (,R--> q1 q1 --Y / Y,R--> q1 q1 --) / Y,L--> q2
q2 --( / (,L--> q2 q2 --Y / Y,L--> q2 q2 --X / X,R--> q0
q3 --Y / Y,R--> q3 q3 --B / B,R--> q4 q4 : accepting (no moves)
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 · 5 marks
Differentiate between Class P and Class NP problem. Mention the transition function of DFA, NFA, and ε-NFA.
Answer
Class P vs Class NP.
| Basis | Class P | Class NP |
|---|---|---|
| Meaning | Decision problems solvable by a deterministic TM in polynomial time | Decision problems solvable by a non-deterministic TM in polynomial time, equivalently, a proposed solution (certificate) can be verified in polynomial time |
| Time | for some constant | Non-deterministic ; verification in |
| Examples | Sorting, shortest path, searching, 2-SAT | Satisfiability (SAT), Hamiltonian cycle, subset sum, clique |
| Relation | Whether is an open problem | |
| Practicality | Considered tractable | Best known algorithms for hard members are exponential |
Transition functions.
- DFA: (exactly one next state).
- NFA: (a set of next states, possibly empty).
- -NFA: (as the NFA, but moves on without reading input are allowed).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 10 marks
Define yield in parse tree with example. Convert the following grammar to CNF:
Answer
Yield of a parse tree. The yield is the string obtained by concatenating the labels of the leaves of the tree from left to right. When the root is the start symbol and all leaves are terminals (or ), the yield is a string of the language.
Example: grammar .
S
/ | \
a S b
/ | \
a S b
|
ε
The leaves read left to right are , so the yield is .
Conversion to CNF. Grammar (taking as a terminal symbol):
Step 1: remove -productions. The only nullable variable is . Add the versions without and delete :
(The language of the CNF grammar is .)
Step 2: remove unit productions. The only one is ; replace it by the productions of :
Step 3: replace terminals in bodies of length . Add and :
Step 4: shorten bodies longer than 2. Add , , :
CNF grammar:
Every production now has the form or .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 10 marks
Distinguish between multi-tape and multi-track Turing Machine. Design a TM that accepts a string over the alphabet , such that .
Answer
Multi-tape vs multi-track Turing machine.
| Basis | Multi-tape TM | Multi-track TM |
|---|---|---|
| Structure | Several separate tapes, each with its own independent head | One tape divided into several tracks; a single head reads all tracks at one position |
| Tape symbol | One symbol per tape; the transition reads symbols (one from each tape) | One composite symbol |
| Head movement | Each head may move independently | All tracks move together |
| Transition | (same as a one-tape TM over tuple alphabet) | |
| Power | Same as the standard TM (simulated with slowdown) | Same as the standard TM |
| Use | Faster algorithms (copying, comparing) | Marking, e.g. checking primes, storing flags |
TM for . Idea: repeatedly mark the leftmost unmarked by , then the leftmost unmarked by . Accept when no remains and no remains.
| State | |||||
|---|---|---|---|---|---|
| – | – | – | |||
| – | – | ||||
| – | – | ||||
| – | – | – | |||
| – | – | – | – | – |
- : replace the leftmost by and go right (). If instead a is met, all s are matched; go to to check that only s remain.
- : move right over s and s to the first ; change it to and go left ().
- : move left to the last , step right and repeat from .
- : skip s; on blank, accept ().
Trace for :
Accepted. Strings such as (no move from on ), (no move from on ) and (no move from on ) are rejected, so the machine accepts exactly .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
Why do we need asymptotic notation? Discuss about alphabet and power of alphabet.
Answer
Why asymptotic notation? The exact running time of an algorithm depends on the machine, the language, the compiler and the input. We want a measure that
- is independent of the machine and implementation details (constants and lower-order terms are ignored),
- describes how the cost grows with the input size , which matters for large inputs,
- lets algorithms be compared: an algorithm eventually beats an one,
- gives upper, lower and tight bounds on best, average and worst cases.
The main notations are: if for all (upper bound); if (lower bound); if both hold (tight bound). Example: .
Alphabet. An alphabet is a finite, non-empty set of symbols. Examples: (binary), .
Power of an alphabet. is the set of all strings of length exactly over :
For : , , has strings. The union of all powers gives (Kleene closure) and .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
Define ambiguous grammar. How do you use parse tree to show the ambiguity of a grammar?
Answer
Ambiguous grammar. A context free grammar is ambiguous if some string has more than one parse tree. Equivalently, has more than one leftmost derivation (or more than one rightmost derivation). Otherwise the grammar is unambiguous.
Using parse trees to show ambiguity. To prove a grammar ambiguous, find one string and draw two different parse trees for it, both with root and the same yield.
Example: and the string .
Tree 1 (the is applied last, so the tree means ):
E
/ | \
E + E
| / | \
id E * E
| |
id id
Tree 2 (the is applied last, so the tree means ):
E
/ | \
E * E
/ | \ |
E + E id
| |
id id
Both trees have the yield but different structure (and different meaning), so the grammar is ambiguous. Equivalent leftmost derivations: and .
Ambiguity can often be removed by rewriting with precedence levels: , which gives only the first tree.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
Given the non-deterministic Turing machine, TM = ({q0, q1, q2, qf}, {0, 1}, {0, 1, B}, δ, q0, B, {qf}) with the following transition rules, describe the language accepted by the given Turing machine:
Answer
Analysis of the machine. Moves:
- : on a , write , move right, and guess whether to stay in or go to .
- : in a is rewritten as and the head steps left.
- : the cell to the left holds the just written by ; the head steps right again, onto the cell now holding , in state .
- : in on a blank, accept.
There is no move for on or on , so a run dies there.
Behaviour.
- A computation can only start with a : if the input begins with (or is empty), has no move and the string is rejected.
- Suppose is scanning a (an original or a rewritten one). If the next cell is , choose and continue. If the next cell is , choose : the is rewritten to , the head goes back and forward through and returns to scanning that new . So every that follows a processed is turned into a and processing continues.
- At the last symbol (which is, after the rewriting, scanned by as a ), choose ; it now sees and the machine moves to and accepts.
Hence every non-empty string that begins with is accepted by some computation, e.g. , , , . Example : .
i.e. all binary strings that start with .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
Given two DFAs M1 and M2 over the same alphabet Σ, design a third DFA M3 such that M3 will accept the string w ∈ Σ* if it is accepted by both M1 and M2.
Answer
Product construction (intersection of two DFAs). Let
Define where
- (pairs of states),
- ,
- for all , ,
- (both components final).
runs and in parallel on the same input.
Proof of correctness. By induction on , . For both sides are . For :
Therefore iff and iff .
Example. : even number of s (), : even number of s (). has four states ; reading toggles the first component, reading the second; the start and only final state is , so accepts strings with an even number of both s and s. The number of states is at most .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
Differentiate between Moore and Mealy machines.
Answer
Moore vs Mealy machine. Both are finite automata that produce an output string, and neither has final states.
| Basis | Moore machine | Mealy machine |
|---|---|---|
| Formal definition | , | , |
| Output depends on | Present state only | Present state and present input |
| Output is associated with | States | Transitions |
| Length of output for input of length | ||
| Number of states | Generally more | Generally fewer |
| Reaction to input | Output appears one step later (after entering the state) | Output appears immediately with the input |
| Initial output | Produces an output even before any input | None |
| Circuit | Output is a function of state only: more stable, glitch-free | Output may change with input in the middle of a cycle |
Every Moore machine can be converted to an equivalent Mealy machine (give each transition the output of its target state) and every Mealy machine to an equivalent Moore machine (split states by output).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
Design a DFA that accepts odd length binary strings.
Answer
Design. Only the parity of the length matters, so two states suffice.
- : an even number of symbols read so far (start state, includes the empty string).
- : an odd number of symbols read (final state).
| State | ||
|---|---|---|
Every symbol, or , toggles the state.
Check. : (accept). : (reject). : (accept). The empty string stays in (reject).
The language is , with regular expression .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
How do you convert CFG to PDA? Explain.
Answer
CFG to PDA conversion. Every context free language is accepted by a PDA. Given a CFG , build a PDA with a single state that accepts by empty stack and simulates a leftmost derivation on its stack:
where the transitions are:
- For each variable : , i.e. pop the variable and push the right-hand side of a chosen production (with its leftmost symbol on top).
- For each terminal : , i.e. if the top of the stack equals the next input symbol, pop it and consume the input.
The initial stack symbol is the start symbol .
Why it works. The stack always holds the unmatched part of a sentential form (the leftmost variable on top). Rule 1 performs one derivation step on the leftmost variable, rule 2 removes terminals that have been generated and match the input. The PDA empties its stack with the whole input read exactly when a derivation exists, so .
Example. : . The PDA:
Input :
(the step uses ). The stack is empty, so is accepted.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
Why do we need ε transition? Give the formal definition of PDA.
Answer
Need for -transitions. An -transition lets an automaton change state (and, in a PDA, change the stack) without reading any input symbol. It is needed because
- it allows non-determinism by guessing: e.g. a PDA for palindromes must guess the middle of the string, which it does by an -move from the "push" phase to the "pop" phase;
- the stack can be manipulated at the end of input (popping the bottom marker to empty the stack or to reach a final state), and variables can be expanded without consuming input in the CFG-to-PDA construction;
- in -NFAs it makes constructions simple: union, concatenation and Kleene star of automata (Thompson's construction) and regular expression to automaton conversion;
- it makes some machines smaller and easier to design.
For example, lets the PDA change phase without input.
Formal definition of a PDA. A pushdown automaton is a 7-tuple
where
- is a finite set of states,
- is the finite input alphabet,
- is the finite stack alphabet,
- is the transition function (a finite set of pairs: new state and string pushed in place of the top symbol),
- is the start state,
- is the initial stack symbol,
- is the set of final states.
A move is written when . The language accepted by final state is , and by empty stack .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 · 5 marks
Describe abstract, decision and optimization problems.
Answer
Abstract problem. An abstract problem is a binary relation on a set of problem instances and a set of problem solutions. It only states which solutions are acceptable for which instances, without saying how the instances are represented or how a solution is computed.
For example, the shortest-path problem maps an instance (a graph with two vertices and ) to a solution (a path of fewest edges from to ). One instance may have several valid solutions, since there may be several shortest paths. To solve an abstract problem on a computer, its instances are encoded as binary strings, which gives a concrete problem.
Decision problem. A decision problem is an abstract problem whose solution set is (yes or no). Each instance has exactly one answer, so the problem can be viewed as a function .
Examples:
- Is a given integer prime?
- Does a graph contain a Hamiltonian cycle?
- Given , , and an integer , is there a path from to with at most edges?
Decision problems are the basis of complexity classes such as P, NP and NP-complete, because these classes are defined over languages (the set of strings for which the answer is yes).
Optimization problem. An optimization problem asks for the best solution among many feasible solutions, where "best" means the minimum or maximum value of some objective function. Each feasible solution has an associated cost or value.
Examples:
- Shortest path: find the path with the minimum number of edges.
- Travelling salesman problem: find the tour of minimum total length.
- 0/1 knapsack: select items to maximise total profit within the capacity.
- Graph colouring: colour the vertices using the minimum number of colours.
Relation between them. Every optimization problem can be turned into a decision problem by adding a bound . For example, "find the shortest path" becomes "is there a path of length at most ?". If the decision version is hard, the optimization version is at least as hard, because solving the optimization problem immediately answers the decision problem (compare the optimal value with ). This is why NP-completeness theory is stated for decision problems.
| Feature | Decision problem | Optimization problem |
|---|---|---|
| Output | Yes or no | Best feasible solution or its value |
| Example | Is there a tour of length ? | Find the shortest tour |
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
Questions from TU BSc CSIT 2076 Fourth Semester Artificial Intelligence (TU IOST board exam, 2076), TU BSc CSIT 2078 Fourth Semester Artificial Intelligence (TU IOST board exam, 2078), TU BSc CSIT 2079 Fourth Semester Artificial Intelligence (TU IOST board exam, 2079), TU BSc CSIT 2080 Fourth Semester Artificial Intelligence (TU IOST board exam, 2080), TU BSc CSIT 2081 Fourth Semester Artificial Intelligence (TU IOST board exam, 2081), TU BSc CSIT 2082 Fourth Semester Artificial Intelligence (TU IOST board exam, 2082), TU BSc CSIT 2076 Fourth Semester Computer Networks (TU IOST board exam, 2076), TU BSc CSIT 2078 Fourth Semester Computer Networks (TU IOST board exam, 2078), TU BSc CSIT 2079 Fourth Semester Computer Networks (TU IOST board exam, 2079), TU BSc CSIT 2080 Fourth Semester Computer Networks (TU IOST board exam, 2080), TU BSc CSIT 2081 Fourth Semester Computer Networks (TU IOST board exam, 2081), TU BSc CSIT 2082 Fourth Semester Computer Networks (TU IOST board exam, 2082), TU BSc CSIT 2076 Fourth Semester Database Management System (TU IOST board exam, 2076), TU BSc CSIT 2078 Fourth Semester Database Management System (TU IOST board exam, 2078), TU BSc CSIT 2079 Fourth Semester Database Management System (TU IOST board exam, 2079), TU BSc CSIT 2080 Fourth Semester Database Management System (TU IOST board exam, 2080), TU BSc CSIT 2081 Fourth Semester Database Management System (TU IOST board exam, 2081), TU BSc CSIT 2082 Fourth Semester Database Management System (TU IOST board exam, 2082), TU BSc CSIT 2076 Fourth Semester Operating System (TU IOST board exam, 2076), TU BSc CSIT 2078 Fourth Semester Operating System (TU IOST board exam, 2078), TU BSc CSIT 2079 Fourth Semester Operating System (TU IOST board exam, 2079), TU BSc CSIT 2080 Fourth Semester Operating System (TU IOST board exam, 2080), TU BSc CSIT 2081 Fourth Semester Operating System (TU IOST board exam, 2081), TU BSc CSIT 2082 Fourth Semester Operating System (TU IOST board exam, 2082), TU BSc CSIT 2076 Fourth Semester Theory of Computation (TU IOST board exam, 2076), TU BSc CSIT 2078 Fourth Semester Theory of Computation (TU IOST board exam, 2078), TU BSc CSIT 2079 Fourth Semester Theory of Computation (TU IOST board exam, 2079), TU BSc CSIT 2080 Fourth Semester Theory of Computation (TU IOST board exam, 2080), TU BSc CSIT 2081 Fourth Semester Theory of Computation (TU IOST board exam, 2081) and TU BSc CSIT 2082 Fourth Semester Theory of Computation (TU IOST board exam, 2082). Answers are written for this site; check them against your class notes.