0% found this document useful (0 votes)
4 views31 pages

01 TOC

The document provides an overview of key concepts in the Theory of Computation, including sets, functions, sequences, alphabets, strings, and regular languages. It explains finite automata, grammar, and regular expressions, detailing their definitions, components, and examples. Additionally, it discusses properties of regular expressions and poses questions for understanding these concepts.

Uploaded by

sinhaaaryankumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views31 pages

01 TOC

The document provides an overview of key concepts in the Theory of Computation, including sets, functions, sequences, alphabets, strings, and regular languages. It explains finite automata, grammar, and regular expressions, detailing their definitions, components, and examples. Additionally, it discusses properties of regular expressions and poses questions for understanding these concepts.

Uploaded by

sinhaaaryankumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Theory of Computation

Introduction

SETS:
• A set is a group of objects represented as a unit.
• Sets may contain any type of object including numbers, symbols and
even other sets.
• The objects in a set are called its element or members.

Example: S={7,21,57}
Functions And Relations
• A function is an object that sets up an input-output relationship.
• A function takes an input and produces an output.
• In every function the same input produces the same output.
e.g.: f(a)=b
• The set of possible inputs to the function is called its domain.
• The outputs of a function come from a set called its range.
The notation for saying that f is a function with domain D and range R is
f:DR

In case of addition function for integers, the domain is the set of pairs of
integers Z×Z and the range is Z so, we write

add: Z×ZZ
Sequences and Tuples
• A sequence of object is a list of objects in some order.

Example:
(7,21,57) is a sequence

(7,7,21,57) is not a sequence but a set

• Finite sequences are known as tupules.


Alphabet
• An alphabet is a finite, nonempty set of symbols.
• It is denoted by Σ.
• Symbols may be more than one English letter long.
• Example: while is a single symbol in Pascal {a,b}

STRING
• A string is a finite sequence of symbols from Σ, e.g. aaaba.
• The length of a string s, denoted by |s| is the number of symbols in it,
eg. length of aaaba is 5.
• The empty string is the string of length zero, usually written as λ or ε
(epsilon)
• Σ ∗ denotes the set of all sequences of string that are composed of
zero or more symbols of Σ.
• Σ + denotes the set of all sequences of string that are composed of
one or more symbols of Σ.
• That is Σ ∗ = Σ + U Σ 0
A language is a subset of Σ ∗ .
REGULAR LANGUAGES
• We use several different computational models, depending on the
features we want to focus on.
• The simple model called the finite state machine or finite automaton
• Finite automata are good models for computers with an extremely
limited amount of memory.
Grammar :
• It is a finite set of formal rules for generating syntactically correct sentences or
meaningful correct sentences.

Constitute Of Grammar :
• Grammar is basically composed of two basic elements –

Terminal Symbols –
• Terminal symbols are those which are the components of the sentences generated using
a grammar and are represented using small case letter like a, b, c etc.

Non-Terminal Symbols –
• Non-Terminal Symbols are those symbols which take part in the generation of the
sentence but are not the component of the sentence.
• Non-Terminal Symbols are also called Auxiliary Symbols and Variables. These symbols are
represented using a capital letter like A, B, C, etc.
Grammar

A grammar G is a quadruple G=(V,T,S,P)


where
• V is a finite set of (meta) symbols or variables.
• T is a set of terminal symbols
• S is a distinguished element of V called the start symbol.
• P is a finite set of productions (or rules)
• A production has the form X->Y
where
• X ∈ (V U T)+ and Y ∈ (V U T)*
X is not the empty string while Y can be an empty string.
Finite Automata

0 1
𝑀1 0,1
1
𝑞1 𝑞2 𝑞3
0
Input: finite string
Output: Accept or Reject
States: 𝑞1 𝑞2 𝑞3 Computation process: Begin at start state,
1
read input symbols, follow corresponding transitions,
Transitions: Accept if end with accept state, Reject if not.
Start state: Examples: 01011 → Accept
00101 → Reject
Accept states:
𝑀1 accepts exactly those strings in 𝐴 where
𝐴 = 𝑤 𝑤 contains substrings 11}.

Say that 𝐴 is the language of 𝑀1 and that 𝑀1 recognizes 𝐴 and that 𝐴 = 𝐿(𝑀1).
Formal Definition

Defn: A finite automaton 𝑀 is a 5-tuple (𝑄, Σ, 𝛿, 𝑞0, 𝐹)


𝑄: finite set of states
Σ: finite set of alphabet symbols
𝛿: transition function 𝛿: 𝑄 × Σ → 𝑄
a 𝑟
𝛿 (𝑞, 𝑎) = 𝑟 means 𝑞
𝑞0: start state
𝐹: set of accept states/final states
𝛿= 0 1
Example: 𝑞1 𝑞1 𝑞2
𝑀1 = (𝑄, Σ, 𝛿, 𝑞1, 𝐹)
0 𝑞2 𝑞1 𝑞3
𝑀1 1 𝑄 = {𝑞1, 𝑞2, 𝑞3}
0,1
𝑞1 𝑞2 1 𝑞3 Σ = {0, 1}
0 𝑞3 𝑞3 𝑞3
𝐹 = {𝑞3}
Examples of finite AUTOMATA
State diagram of a finite automaton M

Or, state diagram of the two-state finite automaton M.


In formal description M=({q1,q2},{0,1}, 𝛿, q1,{q2}).

0 1
The transition function 𝛿 is q1 q1 q2
q2 q1 q2

The state diagram of M and the formal description of M contain the same
information, only in different forms.
Binary number ends with 1
Σ={0,1}
set builder notation
0,1,00,01,10,11,………………

L={1,01,11,……}
={x1|x ∈{0,1}*}
Five-state machine M1
Three-state machine M2
Finite Automata – Computation

Strings and languages


- A string is a finite sequence of symbols in Σ
- A language is a set of strings (finite or infinite)
- The empty string ε is the string of length 0 Recognizing languages
- The empty language ø is the set with no strings - 𝐿(𝑀) = {𝑤| 𝑀 accepts 𝑤}
- 𝐿(𝑀) is the language of 𝑀
- 𝑀 recognizes 𝐿(𝑀)
Defn: 𝑀 accepts string 𝑤 = 𝑤1𝑤2 … 𝑤𝑛 each 𝑤𝑖 𝜖 Σ
if there is a sequence of states 𝑟0, 𝑟1, 𝑟2, , … , 𝑟𝑛 𝜖 𝑄
where:
- 𝑟0 = 𝑞0 Defn: A language is regular if some
- 𝑟𝑖 = 𝛿(𝑟𝑖−1 , 𝑤𝑖 ) for 1 ≤ 𝑖 ≤ 𝑛 finite automaton recognizes it.
- 𝑟𝑛 𝜖 𝐹
Regular Expression
• It represents a regular language.
• It has 4 operators
• OR (+)
• Concatenation (.)
• Kleene star [closure](*)
• Kleene plus [positive closure] (+)
OR Concatenation Kleene star Kleene plus

A+B AB 𝐴∗ 𝐴+
Either A or B A.B 𝐴0 𝐴1 𝐴2 …… 𝐴1 𝐴2 𝐴3 ………..
A followed by B λ/ε A AA ... A AA AAA ……
AB ×
Empty string/
BA ×
zero symbols/
zero length
𝐴∗ = 𝐴+U 𝐴0

a+b L={a,b} Φ and ε


• Φ : empty expression ε : non-empty expression
: empty string
• L={} L={ε}
a+ε L={a, ε}
• Phi means no string accepted i.e. no final state.
a+ Φ=a
a+ ε≠a
• Epsilon means there is a string of length 0 &
a+a=a
it is accepted i.e. there is a final state.
Exercise
1. a+φ a
2. a. φ φ

3. a+ ε a+ ε

4. a. ε a
5. ε. ε ε

6. ε+ε ε

7. φ + ε ε

8. φ . ε φ

9. a.(b+c) ab+ac

10. a+(b.c) a+bc


Regular Expression
R. ε = ε.R = R
Identity R+φ= φ+R= R

A+B=B+A
Commutative A.B≠B.A

A+(B+C)=(A+B)+C
Associative A.(B.C)=(A.B).C

. over +

+ over .

Dominator R.φ= φ R+ Σ ∗ = Σ∗
Regular Expression
1. 𝑎0 = ε 11. φ∗ = ε+φ+φφ+ ⋯= ε

2. φ0 = ε 12. φ+ = φ

3. 𝑎1 = 𝑎 13. ε∗ = ε

4. φ1 = φ 14. ε+ = ε

5. ε0 = ε 15. 𝑎∗ = ε + 𝑎 + 𝑎𝑎 + 𝑎𝑎𝑎 + ⋯

6. ε1 = ε 16. 𝑎+ = 𝑎 + 𝑎𝑎 + 𝑎𝑎𝑎 + ⋯

7. 𝑎2 = 𝑎𝑎
8. 𝑏 3 = 𝑏𝑏𝑏
9. φ3 = Φφφ=φ
10. ε3 = εεε=ε
Regular Expression

Language representation by Language


the Expression (set)
L(a) ={a}
L(ε) ={ε}
L(a+b) ={a,b}
L(φ) ={}=φ

1. L={} over Σ={a,b} φ


2. L={ε} over Σ={a,b} ε
3. L={a,b,aa} over Σ={a,b} 𝑎 + 𝑏 + 𝑎𝑎 = a ε + a + b
4. L={ε,a,aa} over Σ={a,b}
ε + a(ε +a)
Regular Expression

Σ ∗ = (𝑎 + 𝑏)∗ = ε + 𝑎 + 𝑏 + 𝑎𝑎 + 𝑎𝑏 + 𝑏𝑎 + 𝑏𝑏+…………….
L={w|w 𝜖 {𝑎 + 𝑏}∗ } =set of all strings

𝑅 = (𝑎 + 𝑏)∗

L={w|w 𝜖 {𝑎 + 𝑏}∗ , |w|>0} set of all strings having more than zero length

𝑅 = (𝑎 + 𝑏)+
Question
• Which of the following does not satisfy commutative property in
regular expression?

1. OR
2. Concatenation
3. Both OR and Concatenation
4. None of these
Question
Which of the following is ODD?
1. 𝑎(𝑎 + 𝑏)∗
2. 𝑎𝑎∗ (𝑎 + 𝑏)∗
3. 𝑎∗ (𝑎∗ 𝑏∗ )∗
4. (𝑎𝑏∗ )+
Regular Expression
(𝑎 + 𝑏)∗ =

1. 𝑎∗
2. 𝑏∗ 10.(𝑎+ 𝑏+ )∗
3. 𝑎∗ 𝑏 ∗ 11.(𝑎+ 𝑏+ )+
4. 𝑏∗ 𝑎∗ 12.(𝑎∗ b)∗ 𝑎∗
5. (𝑎∗ 𝑏∗ )∗ 13.(𝑏∗ a)∗ 𝑏∗
6. (𝑏∗ 𝑎∗ )∗ 14.𝑏∗ (𝑎𝑏∗ )∗
7. 𝑏∗ + 𝑎 ∗ 15.𝑎∗ (𝑏𝑎∗ )∗
8. 𝑎∗ + 𝑏∗ 16.(𝑎∗ +𝑏)+
9. (𝑎∗ 𝑏∗ )+ 17.(𝑎 + 𝑏)+ +ε
Regular Expression
(𝑎 + 𝑏)∗ =

1. 𝑎∗
2. 𝑏∗ 10.(𝑎+ 𝑏+ )∗
3. 𝑎∗ 𝑏 ∗ 11.(𝑎+ 𝑏+ )+
4. 𝑏∗ 𝑎∗ 12.(𝑎∗ b)∗ 𝑎∗
5. (𝑎∗ 𝑏∗ )∗ 13.(𝑏∗ a)∗ 𝑏∗
6. (𝑏∗ 𝑎∗ )∗ 14.𝑏∗ (𝑎𝑏∗ )∗
7. 𝑏∗ + 𝑎 ∗ 15.𝑎∗ (𝑏𝑎∗ )∗
8. 𝑎∗ + 𝑏∗ 16.(𝑎∗ +𝑏)+
9. (𝑎∗ 𝑏∗ )+ 17.(𝑎 + 𝑏)+ +ε
Questions
Which one of the following regular expression represents the language:
set of all binary strings having two consecutive 0’s and two consecutive
1’s?
a) (0 + 1)∗ 0011(0 + 1)∗ +(0 + 1)∗ 1100(0 + 1)∗

b) (0 + 1)∗ (00(0 + 1)∗ 11 + 11(0 + 1)∗ 00)(0 + 1)∗

c) 0 + 1 ∗ 00(0 + 1)∗ + 0 + 1 ∗ 11(0 + 1)∗

d) 00(0 + 1)∗ 11 + 11(0 + 1)∗ 00


Questions
L={w|w 𝜖{𝑎, 𝑏}∗ , 𝑤 = 𝑒𝑣𝑒𝑛}

a) (𝑎 + 𝑏)2
b) [(𝑎 + 𝑏)2 ]∗
c) [(𝑎 + 𝑏)∗ ]2
d) None of the above
Finite Automata

• NFA
• DFA

DFA  NFA  Regular Expression

DFA ( Deterministic FA)


NFA (Non- Deterministic FA)

You might also like