Last Minute Notes – Theory of Computation
Last Updated :
24 Jan, 2025
The Theory of Computation (TOC) is a critical subject in the GATE Computer Science syllabus. It involves concepts like Finite Automata, Regular Expressions, Context-Free Grammars, and Turing Machines, which form the foundation of understanding computational problems and algorithms.
This article provides Last Minute Notes for TOC, focusing on the most important topics that are frequently asked in GATE.
Basics
1. Symbol and Alphabet
- Symbol: A single character or entity, e.g.,
a, b, 1, 0. - Alphabet (ÎĢ): A finite set of symbols, e.g.,
ÎĢ = {a, b}.
2. String
- String: A finite sequence of symbols from an alphabet, e.g.,
abba. - Empty String (Îĩ): A string with no symbols.
3. Operations on Strings
- Concatenation: Joining two strings.
Example: w1 = ab, w2 = ba â w1.w2 = abba. - Length (|w|): Number of symbols in a string.
Example: |abba| = 4. - Reverse (w^R): Reversing the order of symbols.
Example: w = abba â w^R = abba.
4. Prefix, Suffix, and Substring
- Prefix: Any leading part of a string.
Example: For w = abba, prefixes are {Îĩ, a, ab, abb, abba}. - Suffix: Any trailing part of a string.
Example: For w = abba, suffixes are {Îĩ, a, ba, bba, abba}. - Substring: Any continuous part of a string.
Example: For w = abba, substrings are {Îĩ, a, b, ab, ba, bb, abb, bba, abba}.
5. Language
- Language (L): A set of strings over an alphabet.
Example: L = {w â ÎĢ* | w starts with a and ends with b}.
For ÎĢ = {a, b}, L = {ab, aab, abb, ...}.
Types of Languages
âĒ Finite Language âĒ Infinite Language âĒ Regular language âĒ DCFL (Deterministic CFL) âĒ CFL âĒ CSL âĒ Recursive Language âĒ Recursive Enumerable Language (REL)

Relation Between Symbol, Alphabet, String, and Language
- Symbol: The smallest unit, e.g.,
a, b, 0, 1. - Alphabet (ÎĢ): A finite set of symbols, e.g.,
ÎĢ = {a, b}. - String: A sequence of symbols from an alphabet, e.g.,
abba. - Language: A set of strings over an alphabet, e.g.,
L = {ab, aab, abb}.
Chomsky Hierarchy

Chomsky Hierarchy
Read more about Chomsky Hierarchy in TOC.
Finite Automata
Finite Automata (FA) is a simple mathematical model used to represent and recognize regular languages. FA = (Q, ÎĢ, Îī, q0 , F)
Finite Automaton can be categorized into two types:
Acceptor (Without Output)
- DFA (Deterministic Finite Automaton)
- NFA (Non-Deterministic Finite Automaton)
Transducer (With Output)
- Moore Machine
- Mealy Machine
Types of FA:
- Deterministic Finite Automata (DFA): Transition function: Îī: Q Ã ÎĢ â Q
(Maps a state and input symbol to a single next state). - Non-Deterministic Finite Automata (NFA):
- Without Îĩ-moves: Îī: Q Ã ÎĢ â 2^Q
(Maps a state and input symbol to a set of possible states). - With Îĩ-moves: Îī: Q à (ÎĢ âŠ {Îĩ}) â 2^Q
(Maps a state and input symbol or Îĩ to a set of possible states).
Read more about Introduction to FA.
Note:
- Language accepted by NDFA and DFA are same.
- Power of NDFA and DFA is same.
- No. of states in NDFA is less than or equal to no. of states in equivalent DFA.
- For NFA with n-states, in worst case, the maximum states possible in DFA is 2n
- Every NFA can be converted to corresponding DFA.
Steps to Construct a DFA:
- Identify the input alphabet (ÎĢ) and the states (Q).
- Define the initial state and the final states.
- Create a transition table or diagram ensuring every input symbol from each state leads to exactly one state.
- Ensure the DFA accepts all strings of the given language and rejects others.
Steps to Construct an NFA:
- Identify the pattern or condition the NFA should accept.
- Create states for each stage of processing the input.
- Start from an initial state.
- Define one or more final states based on acceptance criteria.
- Allow multiple transitions for the same input symbol.
- Include Îĩ-transitions if needed (moves without consuming input).
- Check if it accepts all strings in the language and rejects others.
Simple and flexible, NFAs are easier to design than DFAs.
NFA to DFA Conversion
Step 1: Convert the given NFA to its equivalent transition table.
Step 2: Create the DFAâs start state.
Step 3: Create the DFAâs transition table.
Step 4: Create the DFAâs final states.
Step 5: Simplify the DFA.
Step 6: Repeat steps 3-5 until no further simplification is possible.
Read more about NFA to DFA Conversion, Here.
Minimization of DFAÂ
Suppose there is a DFA D < Q, Î, q0, Î, F > which recognizes a language L. Then the minimized DFA D < Qâ, Î, q0, Î, Fâ > can be constructed for language L as:Â
Step 1:Â We will divide Q (set of states) into two sets. One set will contain all final states and other set will contain non-final states. This partition is called P0.Â
Step 2:Â Initialize k = 1Â
Step 3: Find Pk by partitioning the different sets of Pk-1. In each set of Pk-1, we will take all possible pair of states. If two states of a set are distinguishable, we will split the sets into different sets in Pk.Â
Step 4: Stop when Pk = Pk-1 (No change in partition)Â
Step 5:Â All states of one set are merged into one. No. of states in minimized DFA will be equal to no. of sets in Pk.Â
How to find whether two states in partition Pk are distinguishable ?Â
Two states ( qi, qj ) are distinguishable in partition Pk if for any input symbol a, Π( qi, a ) and Π( qj, a ) are in different sets in partition Pk-1.
Read more about Minimization of DFA.
Moore and Mealy Machine
Moore Machine:
- Output depends on the state only.
- Output is produced when entering a state.
- Example: Output =
{q0 â 0, q1 â 1}. - Representation: M=(Q,ÎĢ,Î,Îī,Îŧ,q0) Where Îŧ is the output function.
Mealy Machine:
- Output depends on the state and input.
- Output is produced during transitions.
- Example: Transition
q0 â q1 on a produces 1. - Representation: M=(Q,ÎĢ,Î,Îī,Îŧ,q0) Where Îŧ is the transition-based output function.
Note: Mealy Machines often require fewer states than Moore Machines for the same functionality.
Read about Mealy and Moore Machine, Here.
Regular Expression
A regular expression represents a regular language and describes a regular set.
Operators of Regular Expressions
OR (|): Binary Operator, Combines two patterns, Example: a|b â {a, b}.
Concatenation (.): Binary Operator, Joins two patterns in sequence, Example: ab â {ab}.
Kleene Star (*): Unary Operator, Allows repetition (zero or more times), Example: a* â {Îĩ, a, aa, aaa, ...}.
Kleene Plus (+): Unary Operator, Allows repetition (one or more times), Example: a+ â {a, aa, aaa, ...}.
Language Over ÎĢ
Languages over an alphabet (ÎĢ) can be classified as:
Finite Set:
- Always a Regular Language.
Infinite Set:
- L Over |ÎĢ| = 1:
- If it forms an Arithmetic Progression (AP) â Regular Language.
- If it does not form an AP â Non-Regular.
- L Over |ÎĢ| > 1:
- Can be either a Regular Language or a Non-Regular Language, depending on the conditions.
Identification of Regular Languages
1. Finite Languages are Always Regular
2. Infinite Languages are Regular if they Follow Patterns
- Infinite languages are regular if they can be expressed with a finite automaton or a regular expression.
- Example:
L = {a^n | n âĨ 0} (Strings with any number of as) â Regular, as it can be represented by a DFA with loops.L = {a^n b^m | n, m âĨ 0} â Regular because it doesnât require memory to match n with m.
3. Closure Properties of Regular Languages
- Regular languages are not closed under subset operation and the six infinite operations because these operations often require memory, context, or infinite processing, which finite automata lack.
- Finite operations, like union, concatenation, and intersection (over finite languages), are closed because they can be managed within the scope of finite automata.
Read about Closure Properties of Regular Languages, Here.
4. How to Identify Non-Regular Languages
A language is not regular if:
- Memory is required: The language needs to keep track of counts or comparisons.
Example: L = {a^n b^n | n âĨ 0} â Non-regular, as it requires matching the number of as and bs. - Nested Patterns: The language contains self-referencing structures like palindromes.
Example: L = {ww^R | w â ÎĢ*} â Non-regular.
5. Pumping Lemma Test
- Purpose: To prove that a language is not regular.
- Statement: For any regular language
L, there exists a pumping length p such that any string w in L with |w| âĨ p can be split into xyz where: xy^iz â L for all i âĨ 0.|y| > 0.|xy| âĪ p.
Read about Properties of RegEx, Here.
Arden’s Theorem
Statement:
- Arden’s Theorem provides a method to solve regular expression equations of the form:
R=Q+RP, where R,Q,P are regular expressions.
Solution:
- The solution for R is:
R=QP^*if P does not contain Îĩ (epsilon).
Example:
Given R=a+Rb:
- Using Arden’s Theorem: R = a(b^*).
Read about Arden’s Theorem, Here.
Regular Grammar
Definition: A regular grammar is a formal grammar that generates regular languages.
Types of Regular Grammar:
- Right-Linear Grammar:
Productions are of the form:
AâaB or Aâa, where A,B are non-terminals and a is a terminal. - Left-Linear Grammar:
Productions are of the form:
AâBa or Aâa.
Properties:
- Regular grammars correspond to finite automata.
- Right-linear grammars are used for DFA/NFA construction.
Example :
Grammar :
Language (L): L={aa,bb}
- Regular languages generated from grammars are calculated bottom-to-top (from the base rules upward).
- Use substitution to derive the final language.
Read about Regular Grammar, Here.
Push Down Automata

Context Free Grammar
Definition: A context-free language is generated by a Context-Free Grammar (CFG) where each production rule follows:
V â (V ⊠T)*
- LHS (Left-Hand Side): Only one variable (non-terminal).
- RHS (Right-Hand Side): A combination of terminals and/or non-terminals.
Derivations to Generate Strings:
- Linear Derivation:
(a) Left Most Derivation (LMD): Expand the leftmost variable first.
(b) Right Most Derivation (RMD): Expand the rightmost variable first. - Non-Linear Derivation:
- Also called Parse Tree or Derivation Tree.
- Represents a hierarchical structure of derivation.
Types of Context-Free Grammars (CFG)
Ambiguous Grammar:
- A CFG is ambiguous if a string has more than one parse tree or derivation.
- Example: SâSSâĢa.
Unambiguous Grammar:
- A CFG is unambiguous if every string has exactly one parse tree or derivation.
Left-Recursive Grammar:
- A grammar is left-recursive if a production rule has the form AâAÎą, where Îą is a string.
- Example: SâSaâĢb.
Right-Recursive Grammar:
- A grammar is right-recursive if a production rule has the form AâÎąA, where Îą is a string.
- Example: SâaSâĢb.
Regular Grammar:
- A special type of CFG where rules are either right-linear or left-linear.
Read about Context Free Grammar, Here.
PDA
A PDA is a computational model that extends a finite automaton by using a stack for additional memory. It recognizes context-free languages (CFLs).
Read about Introduction to Pushdown Automata, Here.
Types of Pushdown Automata (PDA)
Pushdown Automata (PDA) are used to recognize context-free languages (CFLs), classified into deterministic context-free languages (DCFLs) and general CFLs.
1. Deterministic Pushdown Automata (DPDA)
- Definition: A DPDA allows at most one transition for each combination of input symbol, current state, and stack symbol.
- Recognizes: Deterministic Context-Free Languages (DCFLs), which are a subset of CFLs.
- Characteristics:
- Cannot handle ambiguity (e.g., ambiguous grammars).
- Requires deterministic parsing.
- Example language: L =[Tex] \{a^n b^n | n \geq 0\} [/Tex](balanced strings).
- Usage:
- Recognizes languages with clear, unambiguous structures.
2. Non-Deterministic Pushdown Automata (NPDA)
- Definition: An NPDA allows multiple transitions for the same input symbol, current state, and stack symbol.
- Recognizes: All Context-Free Languages (CFLs).
- Characteristics:
- Can handle ambiguity (e.g., ambiguous grammars).
- Example language: L = [Tex]\{a^n b^m c^n | n, m \geq 0\}[/Tex].
- Supports more complex structures than DPDAs.
- Usage:
- Recognizes all CFLs, including ambiguous languages.
Note:
- Power of NPDA is more than DPDA.
- It is not possible to convert every NPDA to corresponding DPDA.
- Language accepted by DPDA is subset of language accepted by NPDA.
- The languages accepted by DPDA are called DCFL (Deterministic Context Free Languages) which are subset of NCFL (Non Deterministic CFL) accepted by NPDA.
Key Difference Between DPDA and NPDA
| Feature | DPDA | NPDA |
|---|
| Language Recognized | DCFL (Subset of CFL) | CFL (All Context-Free Languages) |
| Transitions | Single transition per input | Multiple transitions allowed |
| Ambiguity | Cannot handle ambiguous grammars | Can handle ambiguous grammars |
Read about Difference Between DPDA and NPDA, Here.
Closure Properties of CFLs and DCFLs
| Operation | CFL | DCFL |
|---|
| Union (L1âŠL2) | Closed | Not Closed |
| Concatenation (L1â
L2) | Closed | Not Closed |
| Kleene Star (L*) | Closed | Not Closed |
| Intersection (L1âĐL2) | Not Closed | Closed with Regular |
| Complement (Lc) | Not Closed | Closed |
| Reversal (LR) | Closed | Not Closed |
| Homomorphism | Closed | Not Closed |
| Substitution | Closed | Not Closed |
| Intersection with Regular | Closed | Closed |
| Difference (L1âL2) | Not Closed | Not Closed |
Read about Closure Properties of CFLs, Here.

Key Points:
- DCFL ⊠Regular = DCFL
- DCFL âĐ Regular = DCFL
- DCFL – Regular = DCFL
- Regular – DCFL = Regular
- DCFL ⊠CFL = CFL (Need not be DCFL)
- DCFL âĐ CFL = Need not be CFL
- DCFL – CFL = Need not be CFL
- CFL – DCFL = Need not be CFL
- DCFL ⊠Finite = DCFL
- DCFL âĐ Finite = Finite
- DCFL – Finite = DCFL
- Finite – DCFL = Finite
Turing Machine
- Definition:
A Turing Machine (TM) is a mathematical model of computation used to define what can be computed.
Components:
- Q: Finite set of states.
- ÎĢ: Input alphabet (does not include the blank symbol).
- Î: Tape alphabet (ÎĢâÎ, includes the blank symbol).
- Îī: Transition function.
- qâ: Initial state (q0âQ\).
- q_accept: Accepting state.
- q_reject: Rejecting state (q_acceptâ q_reject).
Transition Function:
- DTM: Îī:QÃÎâQÃÎÃ{L,R}
- NTM: Îī:QÃÎâ2QÃÎÃ{L,R}
Types of Turing Machines:
- DTM (Deterministic TM): One transition for each state-symbol pair.
- NTM (Non-Deterministic TM): Multiple transitions for each state-symbol pair.
Language Classification:
- Turing Recognizable (Recursively Enumerable):
Languages accepted by a TM (TM halts for strings in the language but may loop for others). - Turing Decidable (Recursive):
Languages for which the TM halts on every input.
Special Types of TMs:
- Multi-Tape TM: Multiple tapes and heads; equivalent in power to a single-tape TM.
- Multi-Track TM: Single tape divided into multiple tracks.
- Non-Deterministic TM: Simulates multiple computation paths; equivalent in power to DTM.
- Universal TM: Simulates any TM by encoding its description.
Key Properties:
- TM can simulate Finite Automata and Pushdown Automata.
- TM is more powerful than DFA, NFA, and PDA.
- TM accepts Recursively Enumerable Languages.
Read more about Turing Machine in TOC, Here.
Church-Turing Thesis:
- Any computation performed by a mechanical process can be simulated by a Turing Machine.
Read about Chruch-Turing Thesis, Here.
Important Points:
- TMs are used to define Decidability and Undecidability.
- Halting Problem: Classic example of an undecidable problem.
- Equivalence of DTM and NTM: Both recognize the same set of languages.
- Multi-tape TMs are computationally equivalent to single-tape TMs but more efficient.
- Language accepted by NTM, multi-tape TM and DTM are same.
- Power of NTM, Multi-Tape TM and DTM is same.
- Every NTM can be converted to corresponding DTM.
Time Complexity:
- Deterministic TM: O(f(n)) for time complexity f(n).
- Non-Deterministic TM: O(2O(f(n))) in the worst case when converted to DTM.
Recursive and Recursive Enumerable Language
Recursive Language (Decidable Language): A language is recursive if there exists a Turing Machine (TM) that halts on every input and correctly decides whether the input is in the language.
Recognizable or Recursively Enumerable Language (Semi-Decidable Language): A language is recursively enumerable if there exists a Turing Machine (TM) that halts and accepts inputs that belong to the language, but it may loop forever for inputs not in the language.
Read about Recursive and Recursive Enumerable Language in TOC, Here.
Complement Property of Rec and RE Language:
Complement of Recursive set is Recursive.
Complement of RE is either Recursive or non-RE.
Complement of RE never be âRE which is not recursiveâ.
Closure Properties of RE and Rec Language
| Operation | Recursive Languages (Rec) | Recursively Enumerable Languages (RE) |
|---|
| Union | Closed | Closed |
| Intersection | Closed | Not Closed |
| Complement | Closed | Not Closed |
| Concatenation | Closed | Closed |
| Kleene Star | Closed | Closed |
| Difference | Closed | Not Closed |
| Reversal | Closed | Closed |
| Intersection with Regular | Closed | Closed |
Decidable Problems (Recursive Languages):
- A problem is decidable if there exists a Turing Machine (TM) that halts for all inputs (accepts for “yes” and rejects for “no”).
- Examples include membership and equivalence problems for regular and context-free languages.
Undecidable Problems:
- Problems for which no Turing Machine (HTM) exists to solve them for all inputs.
- Further classified into:
- Recursively Enumerable (RE) but not Recursive:
- The problem is semi-decidable (a TM exists that halts for “yes” cases but may loop forever for “no”).
- Not Recursively Enumerable (Not RE):
- No Turing Machine exists to even semi-decide the problem.
Read about Decidable and Undecidable Problem in TOC, Here.

Countability in Turing Machines
- Countable Set of Turing Machines:
- The set of all possible Turing Machines is countable because each Turing Machine can be encoded as a finite string (its description can be encoded using a finite alphabet, making it possible to enumerate all possible TMs).
- Uncountable Set of Languages:
- The set of all possible languages (subsets of all possible strings) is uncountable, as there are more possible languages than there are Turing Machines. This is due to the fact that we can define languages using infinite sets, and there are more subsets of an infinite set than the number of elements in the set.
Read more about Determining Countability in TOC, Here.
See Last Minute Notes on all subjects , here.
Similar Reads
Automata Tutorial
Automata Theory is a branch of the Theory of Computation. It deals with the study of abstract machines and their capacities for computation. An abstract machine is called the automata. It includes the design and analysis of automata, which are mathematical models that can perform computations on str
3 min read
Regular Expression and Finite Automata
Introduction of Finite Automata
Finite automata are abstract machines used to recognize patterns in input sequences, forming the basis for understanding regular languages in computer science. They consist of states, transitions, and input symbols, processing each symbol step-by-step. If the machine ends in an accepting state after
4 min read
Arden's Theorem in Theory of Computation
Arden's Theorem is a fundamental result in the Theory of Computation used to solve regular expressions from a given linear equation. It is particularly useful when converting finite automata into regular expressions Statement of Arden's Theorem Let R and S be two regular expressions over an alphabet
6 min read
Solving Automata Using Arden's Theorem
Arden's Theorem states that, if P & Q are two regular expressions over âââ, and if P does not contain âââ, then the following equation R given by R = Q + RP has a unique solution ; R = QP* For certain examples provided below, itâs fairly simple to derive them. But for the following example, i
7 min read
L-graphs and what they represent in TOC
In Theory of Computation (TOC), Finite Automata (DFA/NFA) are mathematical models used to recognize Regular Languages. However, not all programming languages can be represented using Finite Automata because they require more computational power than what FA can provide. Languages like C, Pascal, Has
4 min read
Hypothesis (language regularity) and algorithm (L-graph to NFA) in TOC
Prerequisite - Finite automata, L-graphs and what they represent L-graphs can generate context sensitive languages, but itâs much harder to program a context sensitive language over programming a regular one. This is why Iâve came up with a hypothesis about what kind of L-graphs can generate a regul
7 min read
Regular Expressions, Regular Grammar and Regular Languages
To work with formal languages and string patterns, it is essential to understand regular expressions, regular grammar, and regular languages. These concepts form the foundation of automata theory, compiler design, and text processing. Regular ExpressionsRegular expressions are symbolic notations use
7 min read
How to identify if a language is regular or not
Prerequisite - Regular Expressions, Regular Grammar and Regular Languages, Pumping Lemma There is a well established theorem to identify if a language is regular or not, based on Pigeon Hole Principle, called as Pumping Lemma. But pumping lemma is a negativity test, i.e. if a language doesn't satisf
8 min read
Designing Finite Automata from Regular Expression (Set 1)
In this article, we will see some popular regular expressions and how we can convert them to finite automata. Even number of a's : The regular expression for even number of a's is (b|ab*ab*)*. We can construct a finite automata as shown in Figure 1. The above automata will accept all strings which h
3 min read
Star Height of Regular Expression and Regular Language
The star height relates to the field of theoretical computation (TOC). It is used to indicate the structural complexity of regular expressions and regular languages. In this context, complexity refers to the maximum nesting depth of Kleene stars present in a regular expression. A regular language ma
3 min read
Generating regular expression from Finite Automata
Prerequisite - Introduction of FA, Regular expressions, grammar and language, Designing FA from Regular Expression There are two methods to convert FA to the regular expression: 1. State Elimination Method:Step 1 - If the start state is an accepting state or has transitions in, add a new non-accepti
3 min read
Code Implementation of Deterministic Finite Automata (Set 1)
In this article, we will learn about designing of Deterministic Finite Automata (DFA) and it's code implementation. Problem-1: Construction of a DFA for the set of string over {a, b} such that length of the string |w|=2 i.e, length of the string is exactly 2. Explanation - The desired language will
8 min read
Program for Deterministic Finite Automata (Set 2)
In this article, we will learn about designing of Deterministic Finite Automata (DFA) and it's code implementation. Problem-1: Construction of a DFA for the set of string over {a, b} such that length of the string |w| is divisible by 2 i.e, |w| mod 2 = 0. Explanation - The desired language will be l
7 min read
DFA for Strings not ending with "THE"
Problem - Accept Strings that not ending with substring "THE". Check if a given string is ending with "the" or not. The different forms of "the" which are avoided in the end of the string are: "THE", "ThE", "THe", "tHE", "thE", "The", "tHe" and "the" All those strings that are ending with any of the
12 min read
DFA of a string with at least two 0âs and at least two 1âs
Problem - Draw deterministic finite automata (DFA) of a string with at least two 0âs and at least two 1âs. The first thing that come to mind after reading this question us that we count the number of 1's and 0's. Thereafter if they both are at least 2 the string is accepted else not accepted. But we
3 min read
DFA for accepting the language L = { anbm | n+m=even }
Design a deterministic finite automata(DFA) for accepting the language L =[Tex] {a^n b^{m} | m+n=even} [/Tex] For creating DFA for language, L = { a^n b^m ; n+m=even } use elementary mathematics, which says- even + even = even and odd + odd = even. Examples:Input: a a b b // n = 2, m = 2, 2 + 2 = 4
15+ min read
DFA machines accepting odd number of 0âs or/and even number of 1âs
Prerequisite - Designing finite automata Problem - Construct a DFA machine over input alphabet [Tex]\sum_[/Tex]= {0, 1}, that accepts: Odd number of 0âs or even number of 1âs Odd number of 0âs and even number of 1âs Either odd number of 0âs or even number of 1âs but not the both together Solution -
3 min read
DFA of a string in which 2nd symbol from RHS is 'a'
Draw deterministic finite automata (DFA) of the language containing the set of all strings over {a, b} in which 2nd symbol from RHS is 'a'. The strings in which 2nd last symbol is "a" are: aa, ab, aab, aaa, aabbaa, bbbab etc Input/Output INPUT : baba OUTPUT: NOT ACCEPTED INPUT: aaab OUTPUT: ACCEPTED
10 min read
Union process in DFA
Prerequisite - Designing finite automata To perform the union operation on two deterministic finite automata (DFAs), the following steps can be taken: Create a new DFA with a new set of states, consisting of all the states from both original DFAs.Define the initial state of the new DFA to be the tup
5 min read
Concatenation process in DFA
Prerequisite - Designing finite automata Designing a DFA for the set of string over {a, b} such that string of the language start with "a" and end with "b". There two desired language will be formed: L1 = {a, aab, aabab, .......} L2 = {b, bbab, bbabab, .......} In L1, starting element is "a" and in
2 min read
DFA in LEX code which accepts even number of zeros and even number of ones
Lex is a computer program that generates lexical analyzers, which is commonly used with the YACC parser generator. Lex, originally written by Mike Lesk and Eric Schmidt and described in 1975, is the standard lexical analyzer generator on many Unix systems, and an equivalent tool is specified as part
6 min read
Conversion from NFA to DFA
An NFA can have zero, one or more than one move from a given state on a given input symbol. An NFA can also have NULL moves (moves without input symbol). On the other hand, DFA has one and only one move from a given state on a given input symbol. Steps for converting NFA to DFA:Step 1: Convert the g
5 min read
Minimization of DFA
DFA minimization stands for converting a given DFA to its equivalent DFA with minimum number of states. DFA minimization is also called as Optimization of DFA and uses partitioning algorithm.Minimization of DFA Suppose there is a DFA D < Q, Î, q0, Î, F > which recognizes a language L. Then the
7 min read
Reversing Deterministic Finite Automata
Prerequisite â Designing finite automata Reversal: We define the reversed language [Tex]L^R \text{ of } L [/Tex] to be the language [Tex]L^R = \{ w^R \mid w \in L \} [/Tex], where [Tex]w^R := a_n a_{n-1} \dots a_1 a_0 \text{ for } w = a_0 a_1 \dots a_{n-1} a_n [/Tex] Steps to Reversal: Draw the sta
4 min read
Complementation process in DFA
Prerequisite â Design a Finite automata Suppose we have a DFA that is defined by ( Q, [Tex]\Sigma  [/Tex], [Tex]\delta  [/Tex], q0, F ) and it accepts the language L1. Then, the DFA which accepts the language L2 where L2 = Ì
L1', will be defined as below:Â Â ( Q, [Tex]\Sigma[/Tex], [Tex]\delta[/Tex],
2 min read
Kleene's Theorem in TOC | Part-1
A language is said to be regular if it can be represented by using Finite Automata or if a Regular Expression can be generated for it. This definition leads us to the general definition that; For every Regular Expression corresponding to the language, a Finite Automata can be generated. For certain
4 min read
Mealy and Moore Machines in TOC
Moore and Mealy Machines are Transducers that help in producing outputs based on the input of the current state or previous state. In this article we are going to discuss Moore Machines and Mealy Machines, the difference between these two machinesas well as Conversion from Moore to Mealy and Convers
3 min read
Difference Between Mealy Machine and Moore Machine
In theory of computation and automata, there are two machines: Mealy Machine and Moore Machine which is used to show the model and behavior of circuits and diagrams of a computer. Both of them have transition functions and the nature of taking output on same input is different for both. In this arti
4 min read
CFG
Relationship between grammar and language in Theory of Computation
In the Theory of Computation, grammar and language are fundamental concepts used to define and describe computational problems. A grammar is a set of production rules that generate a language, while a language is a collection of strings that conform to these rules. Understanding their relationship i
4 min read
Simplifying Context Free Grammars
A Context-Free Grammar (CFG) is a formal grammar that consists of a set of production rules used to generate strings in a language. However, many grammars contain redundant rules, unreachable symbols, or unnecessary complexities. Simplifying a CFG helps in reducing its size while preserving the gene
6 min read
Closure Properties of Context Free Languages
Context-Free Languages (CFLs) are an essential class of languages in the field of automata theory and formal languages. They are generated by context-free grammars (CFGs) and are recognized by pushdown automata (PDAs). Understanding the closure properties of CFLs helps in determining which operation
11 min read
Union and Intersection of Regular languages with CFL
Prerequisite - Chomsky Hierarchy, Regular Languages As we all are aware that languages accepted by finite automata are called regular languages and those which are accepted by push down automata are called context free languages But, when it comes to the union or intersection of these two languages
3 min read
Converting Context Free Grammar to Chomsky Normal Form
Chomsky Normal Form (CNF) is a way to simplify context-free grammars (CFGs) so that all production rules follow specific patterns. In CNF, each rule either produces two non-terminal symbols, a single terminal symbol, or, in some cases, the empty string. Converting a CFG to CNF is an important step i
5 min read
Converting Context Free Grammar to Greibach Normal Form
Context-free grammar (CFG) and Greibach Normal Form (GNF) are fundamental concepts in formal language theory, particularly in the field of compiler design and automata theory. This article delves into what CFG and GNF are, provides examples, and outlines the steps to convert a CFG into GNF. What is
6 min read
Pumping Lemma in Theory of Computation
There are two Pumping Lemmas, which are defined for 1. Regular Languages, and 2. Context - Free Languages Pumping Lemma for Regular Languages For any regular language L, there exists an integer n, such that for all x ? L with |x| ? n, there exists u, v, w ? ?*, such that x = uvw, and (1) |uv| ? n (2
4 min read
Check if the language is Context Free or Not
Identifying regular languages is straightforward, but determining if a language is context-free can be tricky. Since the Pumping Lemma requires mathematical proof, it is time-consuming. Instead, observational techniques help quickly determine whether a language is context-free. Pumping Lemma for Con
4 min read
Ambiguity in Context free Grammar and Languages
Context-Free Grammars (CFGs) are essential in formal language theory and play a crucial role in programming language design, compiler construction, and automata theory. One key challenge in CFGs is ambiguity, which can lead to multiple derivations for the same string. Understanding Derivation in Con
3 min read
Operator grammar and precedence parser in TOC
A grammar that is used to define mathematical operators is called an operator grammar or operator precedence grammar. Such grammars have the restriction that no production has either an empty right-hand side (null productions) or two adjacent non-terminals in its right-hand side. Examples - This is
6 min read
Context-sensitive Grammar (CSG) and Language (CSL)
Context-Sensitive Grammar - A Context-sensitive grammar is an Unrestricted grammar in which all the productions are of form - Where α and β are strings of non-terminals and terminals. Context-sensitive grammars are more powerful than context-free grammars because there are some languages that can be
2 min read
PDA (Pushdown Automata)
Introduction of Pushdown Automata
We have already discussed finite automata. But finite automata can be used to accept only regular languages. Pushdown Automata is a finite automata with extra memory called stack which helps Pushdown automata to recognize Context Free Languages. This article describes pushdown automata in detail. Pu
5 min read
Pushdown Automata Acceptance by Final State
We have discussed Pushdown Automata (PDA) and its acceptance by empty stack article. Now, in this article, we will discuss how PDA can accept a CFL based on the final state. Given a PDA P as: P = (Q, Σ, Î, δ, q0, Z, F) The language accepted by P is the set of all strings consuming which PDA can move
4 min read
Construct Pushdown Automata for given languages
Prerequisite - Pushdown Automata, Pushdown Automata Acceptance by Final State A push down automata is similar to deterministic finite automata except that it has a few more properties than a DFA.The data structure used for implementing a PDA is stack. A PDA has an output associated with every input.
4 min read
Construct Pushdown Automata for all length palindrome
A Pushdown Automaton (PDA) is like an epsilon Non deterministic Finite Automata (NFA) with infinite stack. PDA is a way to implement context free languages. Hence, it is important to learn, how to draw PDA. Here, take the example of odd length palindrome: Que-1: Construct a PDA for language L = {wcw
6 min read
Detailed Study of PushDown Automata
According to the Chomsky Hierarchy, the requirement of a certain type of grammar to generate a language is often clubbed with a suitable machine that can be used to accept the same language. When the grammar is simple, the language becomes more complex, hence we require a more powerful machine to un
3 min read
NPDA for accepting the language L = {an bm cn | m,n>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - â Design a non deterministic PDA for accepting the language L = {[Tex]a^n [/Tex][Tex]b^m [/Tex][Tex]c^n [/Tex]| m, n>=1}, i.e., L = { abc, abbc, abbbc, aabbcc, aaabccc, aaaabbbcccc, ...... } In each of the str
2 min read
NPDA for accepting the language L = {an bn cm | m,n>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem â Design a non deterministic PDA for accepting the language L = {[Tex]a^n[/Tex] [Tex]b^n[/Tex] [Tex]c^m[/Tex] | m, n>=1}, i.e., L = { abc, abcc, abccc, aabbc, aaabbbcc, aaaabbbbccccc, ...... } In each of the str
2 min read
NPDA for accepting the language L = {an bn | n>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^n [/Tex][Tex]b^n [/Tex]| n>=1}, i.e., L = {ab, aabb, aaabbb, aaaabbbb, ......} In each of the string, the number of a's are followed by equ
2 min read
NPDA for accepting the language L = {am b(2m) | m>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^m [/Tex][Tex]b^{2m} [/Tex]: m>=1}, i.e., L = {abb, aabbbb, aaabbbbbb, aaaabbbbbbbb, ......} In each of the string, the number of a's are fo
2 min read
NPDA for accepting the language L = {am bn cp dq | m+n=p+q ; m,n,p,q>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^m[/Tex] [Tex]b^n[/Tex] [Tex]c^p[/Tex] [Tex]d^q[/Tex] | m + n = p + q : m, n, p, q>=1}, i.e., L = {abcd, abbcdd, abbccd, abbbccdd, ......} I
2 min read
Construct Pushdown automata for L = {0n1m2m3n | m,n ⥠0}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Pushdown automata (PDA) plays a significant role in compiler design. Therefore there is a need to have a good hands on PDA. Our aim is to construct a PDA for L = {0n1m2m3n | m,n ⥠0} Examples - Input : 00011112222333 Outpu
3 min read
Construct Pushdown automata for L = {0n1m2(n+m) | m,n ⥠0}
Prerequisite - Pushdown automata, NPDA for accepting the language L = {ambnc(m+n) | m,n ⥠1} PDA plays a very important role in task of compiler designing. That is why there is a need to have a good practice on PDA. Our objective is to construct a PDA which accepts a string of the form {(0^n)(1^m)(2
2 min read
NPDA for accepting the language L = {ambnc(m+n) | m,n ⥠1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^m b^n c^{(m+n)} [/Tex]| m,n ⥠1}, i.e., L = {abcc, aabccc, abbbcccc, aaabbccccc, ......} In each of the string, the total sum of the number of
2 min read
NPDA for accepting the language L = {amb(m+n)cn | m,n ⥠1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^m b^{(m+n)} c^n [/Tex]| m,n ⥠1} The strings of given language will be: L = {abbc, abbbcc, abbbcc, aabbbbcc, ......} In each of the string, th
2 min read
NPDA for accepting the language L = {a2mb3m | m ≥ 1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem â Design a non deterministic PDA for accepting the language L = {a2mb3m | m ≥ 1}, i.e., L = {aabbb, aaaabbbbbb, aaaaaabbbbbbbbb, aaaaaaaabbbbbbbbbbbb, ......} In each of the string, for every 2 'a's there is 3 '
2 min read
NPDA for accepting the language L = {amb(2m+1) | m ⥠1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^{m} b^{2m+1} [/Tex]| m ⥠1}, or,L = {[Tex]a^{m} b b^{2m} [/Tex]| m ⥠1}, i.e., L = {abbb, aabbbbb, aaabbbbbbb, aaaabbbbbbbbb, ......} In each
2 min read
NPDA for accepting the language L = {aibjckdl | i==k or j==l,i>=1,j>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^i[/Tex] [Tex]b^j[/Tex] [Tex]c^k[/Tex] [Tex]d^l[/Tex] : i==k or j==l, i>=1, j>=1}, i.e., L = {abcd, aabccd, aaabcccd, abbcdd, aabbccdd, a
3 min read
Construct Pushdown automata for L = {a(2*m)c(4*n)dnbm | m,n ⥠0}
Prerequisite â Pushdown automata, Pushdown automata acceptance by final state PDA plays a very important role in task of compiler designing. That is why there is a need to have a good practice on PDA. Our objective is to construct a PDA for L = {a(2*m)c(4*n)dnbm | m,n ⥠0} Examples - Input: aaccccdb
3 min read
NPDA for L = {0i1j2k | i==j or j==k ; i , j , k >= 1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state The language L = {0i1j2k | i==j or j==k ; i , j , k >= 1} tells that every string of â0â, â1â and â2â have certain number of 0âs, then certain number of 1âs and then certain number of 2âs. The condition is that count of
2 min read
NPDA for accepting the language L = {anb(2n) | n>=1} U {anbn | n>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^n [/Tex][Tex]b^{2n} [/Tex]: n>=1} U {[Tex]a^n [/Tex][Tex]b^{n} [/Tex]: n>=1}, i.e., L = {abb, aabbbb, aaabbbbbb, aaaabbbbbbbb, ......} U
2 min read
NPDA for the language L ={w∈ {a,b}*| w contains equal no. of a's and b's}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L ={w?{a,b}* | w contains equal no. of a's and b's}, i.e., L = {ab, aabb, abba, aababb, bbabaa, baaababb, .......} The number of a's and b's are same in a
3 min read
Turing Machine
Recursive and Recursive Enumerable Languages in TOC
Recursive Enumerable (RE) or Type -0 Language RE languages or type-0 languages are generated by type-0 grammars. An RE language can be accepted or recognized by Turing machine which means it will enter into final state for the strings of language and may or may not enter into rejecting state for the
5 min read
Turing Machine in TOC
Turing Machines (TM) play a crucial role in the Theory of Computation (TOC). They are abstract computational devices used to explore the limits of what can be computed. Turing Machines help prove that certain languages and problems have no algorithmic solution. Their simplicity makes them an effecti
7 min read
Turing Machine for addition
Prerequisite - Turing Machine A number is represented in binary format in different finite automata. For example, 5 is represented as 101. However, in the case of addition using a Turing machine, unary format is followed. In unary format, a number is represented by either all ones or all zeroes. For
3 min read
Turing machine for subtraction | Set 1
Prerequisite - Turing Machine Problem-1: Draw a Turing machine which subtract two numbers. Example: Steps: Step-1. If 0 found convert 0 into X and go right then convert all 0's into 0's and go right.Step-2. Then convert C into C and go right then convert all X into X and go right.Step-3. Then conver
2 min read
Turing machine for multiplication
Prerequisite - Turing Machine Problem: Draw a turing machine which multiply two numbers. Example: Steps: Step-1. First ignore 0's, C and go to right & then if B found convert it into C and go to left. Step-2. Then ignore 0's and go left & then convert C into C and go right. Step-3. Then conv
2 min read
Turing machine for copying data
Prerequisite - Turing Machine Problem - Draw a Turing machine which copy data. Example - Steps: Step-1. First convert all 0's, 1's into 0's, 1's and go right then B into C and go left Step-2. Then convert all 0's, 1's into 0's, 1's and go left then Step-3. If 1 convert it into X and go right convert
2 min read
Construct a Turing Machine for language L = {0n1n2n | nâ¥1}
Prerequisite - Turing Machine The language L = {0n1n2n | nâ¥1} represents a kind of language where we use only 3 character, i.e., 0, 1 and 2. In the beginning language has some number of 0's followed by equal number of 1's and then followed by equal number of 2's. Any such string which falls in this
3 min read
Construct a Turing Machine for language L = {wwr | w ∈ {0, 1}}
The language L = {wwres | w â {0, 1}} represents a kind of language where you use only 2 character, i.e., 0 and 1. The first part of language can be any string of 0 and 1. The second part is the reverse of the first part. Combining both these parts a string will be formed. Any such string that falls
5 min read
Construct a Turing Machine for language L = {ww | w ∈ {0,1}}
Prerequisite - Turing Machine The language L = {ww | w â {0, 1}} tells that every string of 0's and 1's which is followed by itself falls under this language. The logic for solving this problem can be divided into 2 parts: Finding the mid point of the string After we have found the mid point we matc
7 min read
Construct Turing machine for L = {an bm a(n+m) | n,mâ¥1}
L = {an bm a(n+m) | n,mâ¥1} represents a kind of language where we use only 2 character, i.e., a and b. The first part of language can be any number of "a" (at least 1). The second part be any number of "b" (at least 1). The third part of language is a number of "a" whose count is sum of count of a's
3 min read
Construct a Turing machine for L = {aibjck | i*j = k; i, j, k ⥠1}
Prerequisite â Turing Machine In a given language, L = {aibjck | i*j = k; i, j, k ⥠1}, where every string of 'a', 'b' and 'c' has a certain number of a's, then a certain number of b's and then a certain number of c's. The condition is that each of these 3 symbols should occur at least once. 'a' and
2 min read
Turing machine for 1's and 2âs complement
Problem-1:Draw a Turing machine to find 1's complement of a binary number. 1âs complement of a binary number is another binary number obtained by toggling all bits in it, i.e., transforming the 0 bit to 1 and the 1 bit to 0. Example: Approach:Scanning input string from left to rightConverting 1's in
3 min read
Recursive and Recursive Enumerable Languages in TOC
Recursive Enumerable (RE) or Type -0 Language RE languages or type-0 languages are generated by type-0 grammars. An RE language can be accepted or recognized by Turing machine which means it will enter into final state for the strings of language and may or may not enter into rejecting state for the
5 min read
Turing Machine for subtraction | Set 2
Prerequisite â Turing Machine, Turing machine for subtraction | Set 1 A number is represented in binary format in different finite automatas like 5 is represented as (101) but in case of subtraction Turing Machine unary format is followed . In unary format a number is represented by either all ones
2 min read
Halting Problem in Theory of Computation
The halting problem is a fundamental issue in theory and computation. The problem is to determine whether a computer program will halt or run forever. Definition: The Halting Problem asks whether a given program or algorithm will eventually halt (terminate) or continue running indefinitely for a par
4 min read
Turing Machine as Comparator
Prerequisite â Turing MachineProblem : Draw a turing machine which compare two numbers. Using unary format to represent the number. For example, 4 is represented by 4 = 1 1 1 1 or 0 0 0 0 Lets use one's for representation. Example: Approach: Comparing two numbers by comparing number of '1's.Comparin
3 min read
TOC Interview preparation
TOC Quiz and PYQ's in TOC