TCS Notes
TCS Notes
TCS Notes
Chapter 1
δ: Transition function that maps (state, symbol) pairs to next states (e.g., δ(S1,
0) = S2)
If the DFA reaches a final state after reading the entire string, it accepts the string
(belongs to the language recognized by the DFA).
If the DFA reaches a non-final state at any point, it rejects the string.
Alphabet: {0, 1}
TCS Notes 1
Transitions: δ(q0, 0) = q0, δ(q0, 1) = q1, δ(q1, 0) = q2
States: q0 (start), q1
Alphabet: {0, 1}
δ: Transition function that maps (state, symbol) pairs to a set of next states
(including possibly empty).
Properties:
An NFA accepts a string if there exists at least one path through its states,
reading the symbols in order, that ends in a final state.
Any language recognized by a DFA can also be recognized by an NFA (but not
vice versa).
Examples:
TCS Notes 2
Recognizing strings with an even number of 0s or ending in "01":
Transitions: δ(q0, 0) = {q0, q1}, δ(q0, 1) = {q0}, δ(q1, 0) = {q0, q1}, δ(q1, 1) =
{q1}
Alphabet: {(, ), }
Transitions: δ(q0, "(") = {q1}, δ(q1, ")") = {q2}, δ(q1, "(") = {q1}, δ(q2, ε) = {q2}
(ε denotes the empty string)
TCS Notes 3
1.10 Mealy and Moore Machines:
These are variations of DFAs that output symbols or take actions during transitions.
Mealy Machines: Outputs depend on the current state and input symbol.
Minimization reduces the complexity of the DFA, making it easier to analyze and
implement.
TCS Notes 4
A concise and powerful notation for describing formal languages recognized by
Finite Automata.
Built using basic symbols like letters, digits, special characters, and operators
like union, concatenation, and repetition.
States that if a language is regular, any sufficiently long string in the language
can be "pumped" (repeated sections) to create new strings still belonging to the
TCS Notes 5
language.
TCS Notes 6
Anchors: Match strings only at the beginning or end (e.g., ^pattern$ ).
This RE defines a flexible format for phone numbers with optional hyphens or
dots and three-digit segments.
Understand derivation trees and how they represent the generation of strings
from a CFG.
TCS Notes 7
Compare CFGs with regular expressions in terms of expressiveness and
recognition power.
Practice constructing CFGs for simple languages based on their structure and
derivation rules.
Analyze the limitations of CFGs and their relationship to other language classes.
MORE NOTES
1. Grammar:
Understanding derivation trees and how they represent the generation of strings
from a CFG.
TCS Notes 8
Discussing differences between CFGs and regular expressions in terms of
expressiveness and recognition power.
2. Derivation-reduction:
Formalizing the definition of a CFG with terminal and non-terminal symbols, start
symbol, and production rules.
4. Ambiguous Grammer:
Identifying situations where a CFG can generate multiple derivation trees for the
same string, leading to ambiguity.
5. Normal Forms:
Introducing Chomsky Normal Form (CNF) and Greibach Normal Form (GNF) as
special types of CFGs with specific restrictions on production rules.
Introducing subclasses of regular grammars where all production rules have non-
terminals either at the leftmost or rightmost position.
TCS Notes 9
Exploring the benefits of left-linear and right-linear grammars for efficient parsing
and analysis of regular languages.
Showing that any regular language recognized by a Finite Automaton (FA) can
also be defined by a regular grammar.
Discussing the equivalence between these two models for recognizing simple
patterns and languages.
Production Rules: These are the core of a CFG, written in the format A ->
α, where A is a non-terminal and α is a string of terminals and/or non-
terminals. They define how non-terminals can be replaced with concrete strings.
To solidify your understanding, let's consider an example CFG for the language of
balanced parentheses:
S -> (S) | () | ε (empty string)
This CFG has one non-terminal (S) and three production rules. These rules tell us:
S can be replaced with either "(S)" (another pair of parentheses), "()", or the
empty string.
By repeatedly applying these rules, starting from S, we can generate strings like
"()", "((()))", "(()())", etc., all of which are balanced parentheses.
TCS Notes 10
Next, we can explore derivation trees, which visually represent the step-by-step
application of production rules. They start from the start symbol and expand non-
terminals until all nodes contain only terminals.
For example, the derivation tree for the string "()" would look like this:
S
/ \
( )
Here, S is replaced with "()" in the first step, resulting in two terminal leaves
representing the balanced parentheses.
Chomsky Normal Form (CNF) and Greibach Normal Form (GNF) for context-
free grammars (CFGs):
CNF:
A special type of CFG where all production rules follow one of these formats:
This restriction simplifies the structure of the CFG and makes it easier to analyze
and manipulate.
Any CFG can be converted to an equivalent CNF CFG using algorithms like
Chomsky's Normalization Algorithm.
GNF:
Another special type of CFG where all production rules follow one of these
formats:
The start symbol (S) can be replaced by the empty string (epsilon) (S -> ε).
This form focuses on rewriting rules from left to right, making it useful for
parsing algorithms and proving pumping lemmas.
Not all CFGs can be converted to GNF, but a large subset can.
TCS Notes 11
Design efficient parsing algorithms.
Examples:
The CFG for balanced parentheses can be converted to both CNF and GNF:
Types of PDAs:
Deterministic PDA (DPDA): Follows a unique transition function for each state
and input symbol combination.
They can also handle languages with unbounded recursion, like the language of
all strings over {a, b} that end in n consecutive b's, where n is an arbitrary
positive integer.
TCS Notes 12
Alphabet: {, }, a, b
Stack: (push/pop)
Example transitions: (q0, {, ) -> q1, push }), (q1, a, ( ) -> q1)
The states of the PDA correspond to the non-terminals in the grammar, and the
stack stores the remaining non-terminals to be expanded and terminals
processed.
This method provides a direct link between these two models of computation.
Components:
Tape: An infinite, two-way tape holding symbols representing the input and
working memory.
Head: Reads and writes symbols on the tape, moving left or right.
States: The current "mode" of the machine, determining its next action.
Operation: The machine starts in a certain state and reads the input on the tape.
Based on the current state and read symbol, it applies the transition function,
potentially changing state, writing a symbol on the tape, and moving the head left
or right. This cycle continues until the machine halts (enters a specific final state).
TCS Notes 13
Universal Computation: Church-Turing Thesis states that any computable
function can be implemented by a Turing Machine. This makes them the
theoretical limit of what's computable.
Applications:
TCS Notes 14