Outline
•Chapter 1: Introduction
1.1.Alphabets and strings
1.2. Languages and Grammars
1.3. Automata
1.3.1. Finite automata [ Deterministic and
Non-deterministic ]
3.
Introduction
• Automata andComplexity Theory is all about
understanding the fundamental capabilities and
limitations of computers.
• It helps us figure out what problems computers can solve, and
• How efficiently they can solve them.
• Think of it like this:
• Automata Theory is about building abstract machines that
can perform computations, while
• Complexity Theory is about measuring how much "work" those
computations require.
4.
Cont …
•Foundations ofAutomata Theory - Alphabets,
Strings, Languages, and Grammars.
•We're going to start at the very beginning,
with the most fundamental components of
computation.
•These might seem simple at first glance, but
they are the bedrock upon which all more
complex ideas in automata theory are built.
Alphabet Σ(Sigma)
•An alphabet,denoted by Σ (Sigma), is a finite,
non-empty set of symbols.
•These symbols are the atomic units we use to
construct information.
•Think of them as the letters in a natural
language.
7.
Example
Binary Alphabet
• Themost common alphabet
in computer science is the
binary alphabet:
• Σ = {0, 1}
• This is the language of
computers – everything
ultimately boils down to
sequences of 0s and 1s.
English Alphabet
• Σ = {a, b, c, ..., z}
• We could even consider an
alphabet of just specific
letters, like:
• Σ = {a, b, c}
8.
Cont …
Set ofDigits
• Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8,
9}
• This alphabet is used to
form numbers.
Special Characters
• Σ = {+, -, *, /, =}
• An alphabet for basic
arithmetic operations.
• The alphabet
• must be finite.
• We can't have an infinite number of distinct symbols.
• And it must be non-empty;
• we need at least one symbol to do anything!
9.
String (or Word)
•A string (or sometimes called a word) over an alphabet Σ is a
finite sequence of symbols from Σ.
• Binary Alphabet Σ= {0, 1}:
• 0101
• 111000
• 0
• 1
• The empty string is also a valid
string.
• It's a string with zero symbols.
• It's crucial for many theoretical
constructions.
• Alphabet Σ= {a, b, c}:
• abca
• ccba
• B
• Empty String
10.
Properties of Strings
•Length of a String
• It is often useful to classify strings by their length,
that is, the number of positions for symbols in the
string.
• For instance: 01101 has length 5.
• It is common to say that the length of a string is
“the number of symbols” in the string.
• The standard notation for the length of a string w is
|w|.
• For example: |011|=3 and |ε|=0
11.
Cont …
• Concatenation:
•If x and y are strings, then xy is their concatenation.
This means joining x and y end-to-end.
• If x = ab and y = ca, then xy = abca.
• If x = 01 and y = 11, then xy = 0111.
• Note that string concatenation is not
commutative: xy ≠ yx in general.
• The empty string ε (epsilon) acts as an identity for
concatenation: we = ew = w for any string w.
12.
Cont …
•Powers ofa String:
•w^k means string w concatenated with itself
k times.
• If w = ab, then w^2 = abab, w^3 = ababab.
• w^0 = ε (epsilon) (any string raised to the power
of 0 is the empty string).
13.
Cont …
• ImportantNotation:
• Σ* (Sigma Star): This denotes the set of all
possible strings over an alphabet Σ, including the
empty string ε(epsilon).
• This set is infinite if Σ is not empty.
• If Σ = {0, 1}, then Σ * = {ε, 0, 1, 00, 01, 10, 11, 000, ...}
• + (Sigma Plus): This denotes the set of all
possible non-empty strings over an alphabet Σ.
• Σ+ = Σ* - {ε}
Language
• Now thatwe have words, how do we define
meaningful collections of these words?
• That brings us to languages.
• A language L over an alphabet Σ is any subset of Σ*.
• In other words, a language is a collection of strings,
where each string is composed of symbols from Σ.
• A language is a set of strings formed from an
alphabet. Formally, a language is any subset of Σ*.
16.
Cont …
•A languagemay be:
•Finite: Only a finite number of strings (e.g.,
L = {a, aa, aaa})
•Infinite: Unlimited strings (e.g., L = {aⁿ | n ≥
0})
•Empty: ∅
•Universal: All possible strings over Σ (i.e.,
Σ*)
17.
Cont …
• Examples:
•L1 = {aⁿ | n ≥ 0} = {ε, a, aa, aaa, ...}
• L2 = {w {0,1}* | w contains an even number of 0s}
∈
• L3 = {w | w is a palindrome over Σ = {a, b}} (e.g., ε, "a", "aba",
"abba")
• Operations on Languages
• Union (L L ): L = {a, aa}, L = {b, bb} L L = {a, aa, b, bb}
₁ ∪ ₂ ₁ ₂ → ₁ ∪ ₂
• Concatenation (L ·L ): L = {a, ab}, L = {b, ba} L ·L = {ab, aba,
₁ ₂ ₁ ₂ → ₁ ₂
abb, abba}
• Kleene Star (L*): L = {a, b} L* = {
→ ε, a, b, aa, ab, ba, bb, aaa, ...}
18.
Grammar
•While a languageis a set of strings, a grammar
provides:
• A formal mechanism or
• a set of rules for generating precisely those
strings that belong to a particular language.
•Think of it as the blueprint or recipe for
creating valid "sentences" in a language.
Automata
• Finite automataare 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
processing the input, it is accepted;
• otherwise, it is rejected.
21.
Cont …
•An automaton:is a mathematical model of
computation that:
•Reads an input string (one symbol at a time).
•Changes its state based on transitions.
•Accepts or rejects the input based on final
states.
22.
Cont …
• Finiteautomata come in:
• deterministic (DFA) and
• non-deterministic (NFA),
• both of which can recognize
the same set of regular
languages.
• They are widely used in text
processing, compilers, and
network protocols.
23.
Features of FiniteAutomata
• Input: Set of symbols or characters provided to the
machine.
• Output: Accept or reject based on the input pattern.
• States of Automata: The conditions or
configurations of the machine.
• State Relation: The transitions between states.
• Output Relation: Based on the final state, the
output decision is made.
24.
Formal Definition ofFinite Automata
• A finite automaton can be defined as a tuple: { Q, Σ, q,
F, δ }, where:
• Q: Finite set of states
• Σ: Set of input symbols
• q: Initial state
• F: Set of final states
• δ: Transition function
25.
Types of FiniteAutomata
• There are two types of finite automata:
1. Deterministic Fintie Automata (DFA)
2. Non-Deterministic Finite Automata (NFA)
Deterministic Finite Automata(DFA)
•A DFA is represented as {Q, Σ, q, F, δ}.
•In DFA, for each input symbol, the machine
transitions to one and only one state.
•DFA does not allow any null transitions,
meaning every state must have a transition
defined for every input symbol.
28.
Cont …
•DFA consistsof 5 tuples {Q, Σ, q, F, δ}.
• Q : set of all states.
• Σ : set of input symbols. ( Symbols which machine
takes as input )
• q : Initial state. ( Starting state of a machine )
• F : set of final state.
• δ : Transition Function, defined as δ : Q X Σ --> Q.
29.
Example:
• Construct aDFA that accepts
all strings ending with 'a’.
• Given:
• Σ = {a, b},
• Q = {q0, q1},
• F = {q1}
• In this example, if the string ends
in 'a', the machine reaches state
q1, which is an accepting state.
StateSymbol
a b
q0 q1 q0
q1 q1 q0
30.
Cont …
Input
String
Path
Final
State
Accept/Reject
"a" qq
₀ → ₁ q₁ ✅ Accept
"ba" q q
₀ → ₁ q₁ ✅ Accept
"bb" q q
₀ → ₀ q₀ ❌ Reject
"abaa"
q q
₀ → ₁ →
q q
₀ → ₁ →
q₁
q₁ ✅ Accept
• Key Takeaways
1. DFA must remember the last
symbol seen.
a. If it's 'a', go to q₁.
b. If it's 'b', stay in q₀.
2. Only q₁ is accepting because it
means the string ends with 'a'.
3. Every input symbol updates
the state based on the last
character.
31.
Non-Deterministic Finite Automata(NFA)
• NFA is similar to DFA but includes the following
features:
• It can transition to multiple states for the same
input.
• It allows null ( ) moves, where the machine can
ϵ
change states without consuming any input.
32.
Example:
• Construct anNFA that
accepts strings ending in 'a'.
• Given:
• Σ = {a, b},
• Q = {q0, q1},
• F = {q1}
• In an NFA, if any transition
leads to an accepting state,
the string is accepted.
StateSymbol
a b
q0 {q0,q1} q0
q1 φ φ
33.
Comparison of DFAand NFA
• Although NFAs appear more flexible, they do not
have more computational power than DFAs. Every
NFA can be converted to an equivalent DFA,
although the resulting DFA may have more states.
• DFA: Single transition for each input symbol, no null
moves.
• NFA: Multiple transitions and null moves allowed.
• Power: Both DFA and NFA recognize the same set of
regular languages.
34.
Conclusion
• Finite automata,whether deterministic or non-
deterministic, are powerful tools in pattern recognition and
regular language processing.
• They form the backbone of many computational processes,
especially in text analysis and compiler design.
• While DFAs are simpler and more commonly used, NFAs
offer a more flexible yet equivalent way to define regular
languages.
• Understanding the nuances of both helps in optimizing
various algorithms in computer science.
35.
Excersice
•Construct a DFA
acceptingstrings over
{x, y} with at least
one 'x’.
•Given:
• Alphabet: {x, y}
• Condition: Must contain
at least one 'x'.
•Design an NFA that
accepts strings over {0,
1} with an even number
of '0's or an odd
number of '1’s.
•Given:
• Alphabet: {0, 1}
• Condition: Even '0's or
odd '1's.