Atomat 1
Atomat 1
Chapter One
Introduction
Theory of computation: is the branch of computer science how effectively deal with the
problem using algorithm.
Writing affective algorithm that run on computing machine Computational problem considers
What can/can’t computed
Speed of computation
Amount of memory used for computation
Three ranch of theory of computation
Automata theory
Complexity theory
Computability theory
Automata theory: deals with definition and properties of mathematical model of computation
Automaton is a machine that operates singularly on input and follows a defined pattern or
configuration to produce the desired output.
Mathematical preliminaries and notations
• Set: is a collection of elements, without any structure other than membership. If m is an element
of the set S, we write m ε S. A set is specified by enclosing some description of its elements in
curly braces. E.g. S={a,b,c}
Universal set U of all possible elements is, if U is specified, then S={ x: x ε U, x ɆS} The set with
no element is called the empty set or null set. It is denoted by Ø.
Operation on sets
Let A and B be two sets and
A c B iff, for all x ε A, x ε B
A=B iff, Ac B and B c A
A c B iff, Ac B but A ≠B
A u B={x: x ε A or x ε B}
A ∩ B={x: x ε A and x ɆB}
A X B={ (x, y), x ε A and y ε B}
Formal Language
• A formal language is an abstraction of the general characteristics of programming languages.
• A formal language consists of a set of symbols and some rules of formation by which these
symbols can be combined into entities called sentences.
Formal Language Natural language
• Developed with strict rules. • Rules come after the language
• Predefined syntax and semantics. • Evolve and develop
• Precise • Highly flexible
•Unambiguous • Quite powerful
Disadvantage: • No special learning effort needed
•Unfamiliar notation Disadvantage:
•Initial learning effort • Vague
E.g. C++, Pascal… • Imprecise and ambiguous
• User and context dependent
E.g. Amharic, English…
Kleene Star
Definition: The set Σ* is the infinite set of all possible strings of all possible lengths over Σ
including λ.
Representation: Σ* = Σ0 U Σ1 U Σ2U…….
Example: If Σ = {a, b}, Σ*= {λ, a, b, aa, ab, ba, bb,………..}
Kleene Closure / Plus
Definition: The set Σ+ is the infinite set of all possible strings of all possible lengths over
Σ excluding λ.
Representation: Σ+ = Σ0 U Σ1 U Σ2 U……. Σ+ = Σ* - { λ }
Example: If Σ = { a, b } , Σ+ ={ a, b, aa, ab, ba, bb,………..}
Transpose Operation
• For any string x ε Σ* and a ε Σ, (xa)T = a(x)T.
• A palindrome of even length can be obtained by the concatenation of a string and its transpose.
E.g. Let Σ={0,1}
Y= (01001)T
(xa)T=(0100 1)T
=1(0100)T
=10(010)T
=100(01)T
=10010
Language
• Definition : A language is a subset of Σ*for some alphabet Σ. It can be finite or infinite.
• Language is a set of string generated by a grammar
• Example: If the language takes all possible strings of length 2 over Σ = {a, b}, then L = {ab, bb,
ba, bb}
Grammars
• Grammars denote syntactical rules for conversation in natural languages. Linguistics have
attempted to define grammars since the inception of natural languages like English, Amharic.
• Strings may be derived from other strings using the productions in a grammar.
• Set of rule used to describe the string of a language
• The set of all strings that can be derived from a grammar is said to be the language generated
from that grammar.
A grammar G is defined as a quadruple (represent in four tuples)
G = (V, T, S, P),
Where V is a finite set of objects called variables,
T is a finite set of objects called terminal symbols,
S ∈ V is a special symbol called the start variable,
P is a finite set of productions.
The production rules are the heart of a grammar; they specify how the grammar transforms one
string into another, and through this they define a language associated with the grammar.
Consider the grammar :-
Grammar G (({S, A}, {a, b}, S, {S → aAb, aA → aaAb, A → ε})
Here,
S and A are Non-terminal symbols.
a and b are Terminal symbols. ε is an empty string.
S is the Start symbol, S ∈ N
Production P : S → aAb, aA → aaAb, A → ε
Strings may be derived from other strings using the productions in a grammar.
Some of the strings that can be derived are –
S ⇒ aAb using production S → aAb
⇒ aaAbb using production aA → aAb
⇒ aaaAbbb using production aA → aaAb
⇒ aaabbb using production A → ε
aaabbb is the string that generated from the above grammar.
We can also drive another string
S ⇒ aAb using production S → aA
⇒ aaAbb using production aA → aaAb
⇒ aabb using production A → ε
The string “aabbb” generated from the grammar
Normally, a given language has many grammars that generate it. Even though these grammars are
different, they are equivalent in some sense. We say that two grammars G1 and G2 are equivalent
if they generate the same language, that is, if L (G1) = L (G2)
E.g.
G1 (({S,}, {a, b}, S, S → aSb}) and
G2 (({S, A}, {a, b}, S, {S → aSb, s → ε, S → aAb, s → ε})
G1 and G2 are equivalent hence they can generate the same language
Exercise
Alphabet Σ = {a, b}: construct a grammar for a language
(a) All strings in the language L: {anbm |n>0, m ≥ 0}
(b) All strings in the language L: {anbm |m>0, n ≥ 0}
(c) All strings in the language Contains at least two a’s
•Find the result of δ (a, 0101) c is Ꜫ final sate hence the string “0101”
Solution: accepted by DFA
δ ( a, 0101) Note
= δ (δ (a, 0), 101) The language accepted by a DFA M = (Q, Σ,
=δ (a, 101) δ, q0,F) is the set of all strings on Σ accepted
=δ (δ (a, 1), 01) by M. In M iff δ(q0,w) =qo for some state qo
=δ (b, 01) in F.
=δ (δ (b, 0), 1) Let M = (Q, Σ, δ, q0, F) be a DFA. Then the
=δ(c, 1) language accepted by M is the set: L (M) =
=c {w | w is in Σ* and δ (q0, w) is in F}
q0 is the initial state from where any input is processed (q0∈ Q).
F is a set of final state/states of Q (F ⊆ Q).
Graphical Representation of an NDFA: (same as DFA)
An NDFA is represented by digraphs called state diagram.
The vertices represent the states.
The arcs labeled with an input alphabet show the transitions.
The initial state is denoted by an empty single incoming arc.
The final state is indicated by double circles.
Example
• Let a non-deterministic finite automaton be
NFA M = (Q,Σ,δ, q0,F)
• Q = {a, b, c} Σ = {0, 1} q0 = {a} F={c}
A string is accepted by an NFA if there is some sequence of possible moves that will put the
machine in a final state at the end of the string. i.e. the language consists of all strings w for which
there is a walk labelled w from the initial vertex of the transition graph to some final vertex.
A string is rejected (that is, not accepted) only if there is no possible sequence of moves by which
a final state can be reached.
The transition function δ as shown below:
• Let X = (Qx, Σ, δx, q0, Fx) be an NDFA which accepts the language L(X). We have to design an
equivalent DFA Y = (Qy, Σ, δy, q0, Fy) such that L(Y) = L(X).
The following procedure converts the NDFA to its equivalent DFA:
Algorithm:
Input: An NDFA
Output: An equivalent DFA
• Step 1 Create state table from the given NDFA.
• Step 2 Create a blank state table under possible input alphabets for the equivalent DFA.
• Step 3 Mark the start state of the DFA by q0 (Same as the NDFA).
• Step 4 Find out the combination of States {Q0, Q1... Qn} for each possible input alphabet.
• Step 5 Each time we generate a new DFA state under the input alphabet columns, we have to
apply step 4 again, otherwise go to step 6.
• Step 6 The states which contain any of the final states of the NDFA are the final states of the
equivalent DFA.
Example 1
• Let us consider the NDFA shown in the figure below.
Exercise
1. Find a deterministic finite accepter that recognizes the set of all strings on Σ= {a, b} starting
with the prefix ab.
2. Construct grammar for L (M) = {x | x is a string of a’s and b’s and |x| >= 2}
3. Construct NFA all the strings with exactly two a’s and more than two b’s.
4. .Construct an equivalent DFA for a given NDFA