0% found this document useful (0 votes)
10 views87 pages

Chapter 1

The document provides an overview of Automata and Complexity Theory, covering fundamental concepts such as formal languages, alphabets, strings, grammars, and automata. It explains the principles of complexity theory, including computability and the operations on languages. Additionally, it details the structure and function of deterministic finite automata (DFA) and their role in recognizing languages.

Uploaded by

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

Chapter 1

The document provides an overview of Automata and Complexity Theory, covering fundamental concepts such as formal languages, alphabets, strings, grammars, and automata. It explains the principles of complexity theory, including computability and the operations on languages. Additionally, it details the structure and function of deterministic finite automata (DFA) and their role in recognizing languages.

Uploaded by

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

DEBRE MARKOS UNIVERSITY

BURIE CAMPUS
DEPARTMENT COMPUTER
SCIENCES

Automata and Complexity Theory

1
outlines
 Introduction
 Alphabet
 Strings
 Languages
 Grammars
 Automata

2
CHAPTER ONE

INTRODUCTION
 Formal language is an abstract of the general
characteristic of programming language.
 It is developed with strict rules.
 It is the set of all strings permitted by the rules of
formation.
 It consists of a set of symbols and some rules of
formation by which these symbols can be
combined into entities called sentences.
3
Introduction to Complexity Theory
 Complexity theory is concerned with questions such as whether a
problem can be solved within certain limited computing resources,
typically space or time.
 Computability theory asks questions such as: do there exist problems
unsolvable by any
effective procedure.
 Whereas computability theory is concerned with unsolvable
problems and the boundary between solvable and unsolvable
problems, complexity theory analyses the set of solvable problems.
Alphabet
 It is finite set of symbols and denoted by 
Example
1 = {a, b, c, d, …, z}: the set of letters in
English
2 = {0, 1, …, 9}: the set of (base 10) digits
3 = {a, b, …, z, #}: the set of letters plus the
special symbol #
4 = {(, )}: the set of open and closed brackets

5
Strings
it is finite set of symbols over 

 a, b
We will use small alphabets:

a
Strings
ab u ab
abba v bbbaaa
baba w abba
aaabbbaabab
6
String Operations

w a1a2  an abba
v b1b2 bm bbbaaa

Concatenation

wv a1a2  anb1b2 bm abbabbbaaa

7
w a1a2  an ababaaabbb

Reverse

R
w an  a2 a1 bbbaaababa

8
String Length
w a1a2  an
Length: w n

Examples: abba 4
aa 2
a 1
9
Recursive Definition of Length
For any letter: a 1

For any stringwa : wa w  1

Example: abba  abb  1


 ab  1  1
 a 1 1 1
1  1  1  1
4 10
Length of Concatenation

uv  u  v

Example: u aab, u 3
v abaab, v 5

uv  aababaab 8
uv  u  v 3  5 8
11
Empty String
A string with no letters:

Observations:  0

w w w

abba abba abba


12
Substring
Substring of string:
a subsequence of consecutive
characters

String Substring
abbab ab
abbab abba
abbab b
abbab bbab
13
Prefix and Suffix
abbab
Prefixes Suffixes
 abbab w uv
a bbab
prefix
ab bab
suffix
abb ab
abba b
abbab 
14
Another Operation
n
w ww
 
w
n
2
Example: abba  abbaabba

0
Definition: w 
0
abba  
15
The * Operation
 * : the set of all possible strings from
alphabet

 a, b
*  , a, b, aa, ab, ba, bb, aaa, aab,

16
The + Operation
 : the set of all possible strings from

alphabet except

 a, b
*  , a, b, aa, ab, ba, bb, aaa, aab,


  *  

 a, b, aa, ab, ba, bb, aaa, aab,
17
Language
*
A language is any subset of

Example:  a, b
*  , a, b, aa, ab, ba, bb, aaa,

Languages: 

a, aa, aab


{ , abba, baba, aa, ab, aaaaaa} 18
Another Example

n n
An infinite language L {a b : n 0}


ab L abb  L
aabb
aaaaabbbbb
19
Operations on Languages
The usual set operations

a, ab, aaaa bb, ab {a, ab, bb, aaaa}


a, ab, aaaa bb, ab {ab}
a, ab, aaaa  bb, ab a, aaaa
Complement: L  *  L

20
Reverse

R R
Definition: L {w : w  L}

Examples:ab, aab, baba R


ba, baa, abab

n n
L {a b : n 0}

R n n
L {b a : n 0}
21
Concatenation

Definition: L1L2  xy : x  L1, y  L2 

Example:a, ab, bab, aa

ab, aaa, abb, abaa, bab, baaa


22
Another Operation
Definition: n
L LL L
n
3
a, b a, ba, ba, b 
aaa, aab, aba, abb, baa, bab, bba, bbb
0
Special case: L 

a, bba, aaa0 


23
Star-Closure (Kleene *)

0 1 2
Definition: L* L  L  L 

Example:
 , 
a, bb, 
 
a, bb*  
 aa , abb, bba , bbbb, 
aaa, aabb, abba, abbbb,
24
Positive Closure

 1 2
Definition: L L  L 
L *   

a, bb, 
  
a, bb aa, abb, bba, bbbb, 
aaa, aabb, abba, abbbb,
 
25
Examples of language generated by
RE
a | b = {a,b}
2- (a|b)a = {aa,ba}
3- (ab) | ε ={ab, ε}
4- ((a|b)a)* = {ε, aa,ba,aaaa,baba,....}
5- (a | c)*b(a|c)* ={b, abc, abaca, baaaac,
ccbaca, cccccb} (construct its DFA)

26
Grammar
Grammar is a mechanism to describe the languages.
A grammar (G) is defined as a quadruple
G = (V, T, S, P)
where
V = Finite set of objects called VARIABLES
T = Finite set of objects called TERMINAL SYMBOLS
S ∈ V = Start variables
P = Finite set of Productions.
A production rule P is of the form X Y

27
Con--
Given a grammar G defined by the
production rules
S ->AB
A ->Aa
B ->Bb
A-> a
B ->b
Show that the word w = a2b4 is L(G)

28
Automata
 An abstract machine which can be used to implement
regular expressions .
 Has a finite number of states, and a finite amount of
memory (i.e., the current state).
 Can be represented by directed graphs or transition
tables
 type of automata
 Deterministic finite automata (DFA)
 Non deterministic finite automata(NDFA)

29
Deterministic Finite Automata
A deterministic finite automaton (DFA) is
a 5-tuple (Q, , , q0, F) where
Q is a finite set of states
 is an input alphabet
: Q ×  → Q is a transition function
q0  Q is the initial state
F  Q is a set of accepting states (or final
states).
In diagrams, the accepting states will be
denoted by double loops
30
Language of a DFA
The language of a DFA (Q, , , q0, F) is the
set of
all strings over  that, starting from q0 and

following the transitions as the string is


read left
to right, will reach some accepting state.
A deterministic finite automaton is a special case of an
NFA
 No state has an ε-transition
 For each state Q and input symbol a there is at most one
edge labeled a leaving S
31
Transition Graph
Abba -Finite Accepter a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

initial final
state state
transition
state “accept”
32
Initial Configuration
Input String
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

33
Reading the Input

a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

34
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

35
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

36
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

37
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

Output: “accept”
38
Rejection

a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

39
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

40
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

41
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

42
a b a

a, b
Output:
q5 “reject”
a, b
b a a b
q0 a q1 b q2 b q3 a q4

43
Another Example

a a b

a a, b

b a, b
q0 q1 q2

44
a a b

a a, b

b a, b
q0 q1 q2

45
a a b

a a, b

b a, b
q0 q1 q2

46
a a b

a a, b

b a, b
q0 q1 q2

47
a a b

a a, b
Output: “accept”

b a, b
q0 q1 q2

48
Rejection

b a b

a a, b

b a, b
q0 q1 q2

49
b a b

a a, b

b a, b
q0 q1 q2

50
b a b

a a, b

b a, b
q0 q1 q2

51
b a b

a a, b

b a, b
q0 q1 q2

52
b a b

a a, b

b a, b
q0 q1 q2

Output: “reject”
53
Input Aplhabet 

 a, b

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

54
Set of States Q
Q q0 , q1, q2 , q3 , q4 , q5 

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

55
Initial State q0

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

56
Set of Final States F

F q4 

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

57
Transition Function 

 : Q   Q

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

58
 q0 , a  q1

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

59
 q0 , b  q5

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

60
 q2 , b  q3

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

61
Transition Function 
 a b
q0 q1 q5
q1 q5 q2
q2 q2 q3
q3 q4 q5 a, b
q4 q5 q5
q5 q5 q5 q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
62
Extended Transition Function  *

 * : Q *  Q

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

63
 * q0 , ab  q2

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

64
 * q0 , abba  q4

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

65
 * q0 , abbbaa  q5

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

66
Observation: There is a walk fromq0 to q5
with label abbbaa

 * q0 , abbbaa  q5


a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

67
Recursive Definition

 * q,   q
 * q, wa   ( * (q, w), a )
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
68
 * q0 , ab 
  * (q0 , a),b  
   * q0 ,  , a , b  
  q0 , a , b  
 q1, b  
q2 a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
69
Languages Accepted by DFAs
Take DFA M

Definition:
The languageLM  contains
M
all input strings accepted by

LM  M
= { strings that drive to a final
state}

70
Example
LM  abba M

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

accept
71
Another Example
LM   , ab, abba M

a, b

q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4

accept accept accept


72
Formally

For a DFA M Q, ,  , q0 , F 

M
Language accepted by :

LM  w  * :  * q0 , w F 

alphabet transition initial final


function state states
73
Observation
M
Language accepted by :

LM  w  * :  * q0 , w F 

Language rejected byM :

LM  w  * :  * q0 , w F 

74
More Examples

n
LM  {a b : n 0}

a a, b

b a, b
q0 q1 q2

accept trap state

75
LM= { all substrings with prefix ab }
a, b

q0 a q1 b q2

b a accept

q3 a, b
76
Example’s on DFA

77
Transition table

78
79
Con…

80
questions
1.Construct a DFA that accepts the
language
L = {010, (  = {0, 1}
1} )

81
Con--
2.Construct a DFA over alphabet {0, 1} that accepts all strings that
end in 101.
3. Construct a DFA which accepts set of all strings over {a,b} that
starts with a string abb
4.Construct a DFA which accepts set of all strings over {0,1}.
5. Construct a DFA which accepts a set of all strings over {a,b} of the
form a3bwa3 where w is any string.

82
Non-Deterministic Finite Automata
(NFA)
 Non determinism means a choice of moves for an
automaton. Rather than prescribing a, unique
move in each satiation.
 it allows a set of possible moves.

83
Con..
 In non deterministic finite accepter the range of
transition function is the power set of 2 the
power of Q,
 so that its value is not a single element of Q, but
a subset of it.
 This subset defines the set of all possible states
that can be reached by the transition.
 For examples:

84
Non-Deterministic Finite Automata
Definition
An NFA M consists of five tuples: ( Σ,S, T, S0, F)
A set of input symbols Σ, the input alphabet
a finite set of states S,
a transition function T: S × (Σ U { ε}) -> S (next state),
a start state S0 from S, and
a set of accepting/final states F from S.

85
NFA…
It is a finite automata which has choice of
edges
The same symbol can label edges from one state to
several different states.

An edge may be labeled by ε, the empty


string
We can have transitions without any input character
consumption.

86
Transition Graph
The transition graph for an NFA recognizing the
language of regular expression (a|b)*abb
all strings of a's and b's ending in the
particular string abb
a

start a b b
0 1 2 3

b S={0,1,2,3}
Σ={a,b}
S0=0
F={3}
87

You might also like