Theory of Computation
Theory of Computation
Papia Akter
Lecturer, Dept. of CSE
Prime University
Purpose and motivation
This course is on the Theory of Computation, which tries to answer the following
questions:
• What are the mathematical properties of computer hardware and software?
• What is a computation and what is an algorithm? Can we give rigorous
mathematical definitions of these notions?
• What are the limitations of computers? Can “everything” be computed? (As we
will see, the answer to this question is “no”.)
So, the main purpose of the Theory of Computation is to Develop formal
mathematical models of computation that reflect real-world computers.
Nowadays, the Theory of Computation can be divided into the following three areas:
Complexity Theory, Computability Theory, and Automata Theory.
Complexity theory
The main question asked in this area is “What makes some problems computationally
hard and other problems easy?”
Informally, a problem is called “easy”, if it is efficiently solvable. Examples of “easy”
problems are (i) sorting a sequence of, say, 1,000,000 numbers, (ii) searching for a name in
a telephone directory, and (iii) computing the fastest way to drive from Ottawa to Miami.
On the other hand, a problem is called “hard”, if it cannot be solved efficiently, or if we
don’t know whether it can be solved efficiently. Examples of “hard” problems are (i) time
table scheduling for all courses at Carleton, (ii) factoring a 300-digit integer into its prime
factors, and (iii) computing a layout for chips in VLSI.
Central Question in Complexity Theory: Classify problems according to their degree of
“difficulty”. Give a rigorous proof that problems that seem to be “hard” are really “hard”.
Computability Theory
In the 1930’s, G¨odel, Turing, and Church discovered that some of the fundamental
mathematical problems cannot be solved by a “computer”. (This may sound strange,
because computers were invented only in the 1940’s). An example of such a problem is
“Is an arbitrary mathematical statement true or false?” To attack such a problem, we
need formal definitions of the notions of
• computer,
• algorithm, and
• computation.
The theoretical models that were proposed in order to understand solvable and
unsolvable problems led to the development of real computers.
Central Question in Automata Theory: Do these models have the same power, or can
one model solve more problems than the other?
Theory of Automata
Theory of automata is a theoretical branch of computer science and mathematical. It is
the study of abstract machines and the computation problems that can be solved using
these machines. The abstract machine is called the automata. The main motivation
behind developing the automata theory was to develop methods to describe and
analyse the dynamic behavior of discrete systems.
This automaton consists of states and transitions. The State is represented by circles,
and the Transitions is represented by arrows.
Automata is the kind of machine which takes some string as input and this input goes
through a finite number of states and may enter in the final state.
Basic Terminologies
There are the basic terminologies that are important and frequently used in automata:
Symbols:
Symbols are an entity or individual objects, which can be any letter, alphabet or any
picture.
Example:
1, a, b, #
Alphabets:
Alphabets are a finite set of symbols. It is denoted by ∑.
Examples:
1.∑ = {a, b}
2.∑ = {A, B, C, D}
3.∑ = {0, 1, 2}
4.∑ = {0, 1, ....., 5]
5.∑ = {#, β, Δ}
String:
It is a finite collection of symbols from the alphabet. The string is denoted by w.
Example 1:
If ∑ = {a, b}, various string that can be generated from ∑ are {ab, aa, aaa, bb, bbb, ba,
aba.....}.
A string with zero occurrences of symbols is known as an empty string. It is represented
by ε.
Length of string
The number of symbols present in the string is known as the Length of the string. The
length of the string is denoted by |w|.
For the string S = 'adadda', the length of the string is |w| = 6.
For the string S = '010', the length of string is |w| = 3
Language:
A language is a collection of appropriate string. A language which is formed over Σ can
be Finite or Infinite.
Example: 1
L1 = {Set of string of length 2} = {aa, bb, ba, bb} Finite Language
Example: 2
L2 = {Set of all strings starts with 'a'} = {a, aa, aaa, abb, abbb, ababb} Infinite Language
Kleene Closure/Star
•Definition − The Kleene star, ∑*, is a unary operator on a set of symbols or strings, ∑, that
gives the infinite set of all possible strings of all possible lengths over ∑ including λ.
•Representation − ∑* = ∑0 ∑1 ∑2 ……. where ∑p is the set of all possible strings of
length p.
•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 − ∑+ = ∑1 ∑2 ∑3 …….
•∑+ = ∑* − { λ }
•Example − If ∑ = { a, b } , ∑+ = { a, b, aa, ab, ba, bb,………..}
Finite Automata
•Finite automata are used to recognize patterns.
•It takes the string of symbol as input and changes its state accordingly. When the desired
symbol is found, then the transition occurs.
•At the time of transition, the automata can either move to the next state or stay in the
same state.
•Finite automata have two states, Accept state or Reject state. When the input string is
processed successfully, and the automata reached its final state, then it will accept.
Formal Definition of FA
A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F), where:
• Q: finite set of states
• ∑: finite set of the input symbol
• q0: initial state
• F: final state
• δ: Transition function
The finite automata can be represented using a transition graph. In the above diagram, the
machine initially is in start state q0 then on receiving input 1 the machine changes its state to
q1. From q0 on receiving 0, the machine changes its state to q2, which is the dead state. From
q1 on receiving input 0, 1 the machine changes its state to q1, which is the final state. The
possible input strings that can be generated are 10, 11, 110, 101, 111......., that means all string
starts with 1.
Transition Table
The transition table is basically a tabular representation of the transition function. It
takes two arguments (a state and a symbol) and returns a state (the "next state").
A transition table is represented by the following things:
• Columns correspond to input symbols.
• Rows correspond to states.
• Entries correspond to the next state.
• The start state is denoted by an arrow with no source.
• The accept state is denoted by a star.
Example 1:
Solution:
Transition table of given DFA is as follows:
Solution:
Transition table of given NFA is as follows:
Example 1:
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}
3. q0 = {q0}
4. F = {q2}
5. Transition Table:
→q0 q0 q1
q1 q2 q1
*q2 q2 q2
Solution:
Transition Diagram:
Give a Formal Definition of DFA from the following language.
Solution:
∑ = {0, 1}
L= {0, 00, 01, 000, 001, 010, 011.
0
A B 0,1
C 0,1
Formal Definition of DFA:
A DFA is a collection of 5-tuples same as we described in the definition of FA.
Q = finite set of states
= {q0, q1, q2}
∑ = finite set of the input symbol
= {0, 1}
q0 = initial state
= {q0}
F = final state
= {q1}
δ = Transition function
Transition function can be defined as:
δ: Q x ∑→Q
Transition Table:
→q0 q0 q2
*q1 q1 q1
q2 q2 q2
Example 2: DFA with ∑ = {0, 1} accepts all ending with 0.
Solution:
∑ = {0, 1}
L={0,00,10,100,110,….}
Transition Table:
→q0 q1 q0
*q1 q1 q0
Some Examples of DFA
Example 1:
Design a DFA with ∑ = {0, 1}, accepts those string which starts with 1.
Solution:
∑ = {0, 1}, 1
L={1,10,11,111,….}
A B 0,1
C 0,1
Example 2:
Design a DFA, which accepts set of all strings over ∑ = {0, 1}, where each string starts with
‘00’
0 0
Solution: A B C 0,1
∑ = {0, 1},
1 1
L= {00,000,001,0000,0001,…}
D 0,1
Example 3:
Design a DFA with ∑ = {0, 1} accepts those set of strings which starts with ‘001’
Solution:
0 0 1 0,1
∑ = {0, 1} A B C D
L = {001,0010,0011,00100, 00101,…} 1
1
0
E 0,1
Example 4:
Design a DFA with ∑ = {0, 1} accepts those set of strings which starts with ‘110’
Solution:
∑ = {0, 1} 1 1 0 0,1
L = {001,0010,0011,00100, 00101,…}
A B C D
0
0
1
E 0,1