0% found this document useful (0 votes)
17 views38 pages

Formal Language: by Hossam Hawash

Uploaded by

anassyd91
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)
17 views38 pages

Formal Language: by Hossam Hawash

Uploaded by

anassyd91
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/ 38

1

Formal Language
BY HOSSAM HAWASH
Alphabet 2

• Definition − An alphabet is any finite set of symbols.


• Example − ∑ = {a, b, c, d} is an alphabet set where ‘a’, ‘b’, ‘c’, and
‘d’ are symbols.
String 3

• Definition − A string is a finite sequence of symbols taken from ∑.


• Example − ‘cabcad’ is a valid string on the alphabet set ∑ = {a, b, c,
d}
Length of a String 4

• Definition − It is the number of symbols present in a string. (Denoted


by |S|).
• Examples −
• If S = ‘cabcad’, |S|= 6
• If |S|= 0, it is called an empty string (Denoted by λ or ε)
Kleene Star 5

• 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 6

• 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,………..}
Language 7

• Definition − A language is a subset of ∑* for some alphabet ∑. It can


be finite or infinite.
• Example − If the language takes all possible strings of length 2 over
∑ = {a, b}, then L = { ab, aa, ba, bb }
Finite Automaton 8

 Finite Automaton can be classified into two types −


• Deterministic Finite Automaton (DFA)
• Non-deterministic Finite Automaton (NDFA / NFA)
Deterministic Finite Automaton 9

(DFA)
 In DFA, for each input symbol, one can determine the state to which
the machine will move. Hence, it is called Deterministic Automaton.
 As it has a finite number of states, the machine is called
Deterministic Finite Machine or Deterministic Finite Automaton.
Formal Definition of a DFA 10

 A DFA can be represented by a 5-tuple (Q, ∑, δ, q0, F) where −


• Q is a finite set of states.
• ∑ is a finite set of symbols called the alphabet.
• δ is the transition function where δ: Q × ∑ → Q
• 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 a DFA 11

 A DFA is represented by digraphs called state diagram.


• The vertices represent the states.
a
• 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.
DFA with ∑ = {0, 1} accepts all 12

starting with 0.
 solution

0
q0 q1
DFA with ∑ = {0, 1} accepts all 13

starting with 0.
 solution
0,1

0
q0 q1
DFA with ∑ = {0, 1} accepts all 14

starting with 0.
 solution
0,1

0
q0 q1

q2
DFA with ∑ = {0, 1}, L= {x|x is ending 15

with 0}.
 solution

0
q0 q1
DFA with ∑ = {0, 1}, L= {x|x is ending 16

with 0}.
 solution
0

0
q0 q1
DFA with ∑ = {0, 1}, L= {x|x is ending 17

with 0}.
 solution
0

0
q0 q1

1
DFA with ∑ = {0, 1}, L= {x|x is ending 18

with 0}.
 solution
1
0

0
q0 q1

1
DFA with ∑ = {0, 1}, L={x|x is string 19

starts with 1 and ends with 0}


 solution

1 0
q0 q1 q2
DFA with ∑ = {0, 1}, L={x|x is string 20

starts with 1 and ends with 0}


 solution

1 0
q0 q1 q2
DFA with ∑ = {0, 1}, L={x|x is string 21

starts with 1 and ends with 0}


 solution

1 0

1 0
q0 q1 q2
DFA with ∑ = {0, 1}, L={x|x is string 22

starts with 1 and ends with 0}


 solution

1 0

1 0
q0 q1 q2

1
DFA with ∑ = {0, 1}, L={x|x is string 23

starts with 1 and ends with 0}


 solution

1 0

1 0
q0 q1 q2

0
1
q3
DFA with ∑ = {0, 1}, L={ x | x start 24

with 110}
 solution

0, 1

1 1 0
q0 q1 q2 q3
DFA with ∑ = {0, 1}, L={ x | x start 25

with 110}
 solution

0, 1

1 1 0
q0 q1 q2 q3

0
q4

0, 1
DFA with ∑ = {0, 1}, L={ x | x start 26

with 110}
 solution

0, 1

1 1 0
q0 q1 q2 q3

0 0
q4

0, 1
DFA with ∑ = {0, 1}, L={ x | x start 27

with 110}
 solution

0, 1

1 1 0
q0 q1 q2 q3

0 0 1

q4

0, 1
DFA with ∑ = {0, 1}, L={ x | x end 28

with 1011}
 solution

1 0 1 1
q0 q1 q2 q3 q4
DFA with ∑ = {0, 1}, L={ x | x end 29

with 1011}
 solution

0
1 0 1 1
q0 q1 q2 q3 q4
DFA with ∑ = {0, 1}, L={ x | x end 30

with 1011}
 solution

1
0
1 0 1 1
q0 q1 q2 q3 q4
DFA with ∑ = {0, 1}, L={ x | x end 31

with 1011}
 solution

1
0
1 0 1 1
q0 q1 q2 q3 q4

0
DFA with ∑ = {0, 1}, L={ x | x end 32

with 1011}
 solution

1
0 0
1 0 1 1
q0 q1 q2 q3 q4

0
DFA with ∑ = {0, 1}, L={ x | x end 33

with 1011}
 solution
0

1
0 0
1 0 1 1
q0 q1 q2 q3 q4

0
DFA with ∑ = {0, 1}, L={ x | x end 34

with 1011}
 solution
0

1
0 0
1 0 1 1
q0 q1 q2 q3 q4

1
0
35
 Describe the language
accepted by the following
DfA.

 Answer
 L=(ab)*
 L={x|x =(ab)^n n>=0}
36

 Describe the language


accepted by the following
Dfa
 Answer
 L={ (aa)*b+ }
 L= { (aa)+ or b+}
37

 Describe the language


accepted by the following
DfA.
38

Implementing
DFA in C++

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy