Lecture 1 CSE 322 LPU By 5th SEM .ppt Good

abcxyz19691969 107 views 125 slides Oct 07, 2024
Slide 1
Slide 1 of 125
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114
Slide 115
115
Slide 116
116
Slide 117
117
Slide 118
118
Slide 119
119
Slide 120
120
Slide 121
121
Slide 122
122
Slide 123
123
Slide 124
124
Slide 125
125

About This Presentation

CSE 322 LPU


Slide Content

CSE322
Formal Languages and
Automation Theory
Lecture #1

Definition
An automaton is defined as a system where energy,
materials and information are transformed, transmitted
and used for performing some functions without direct
participation of man.

Formal Definition
• Finite Automaton (FA)
 FqQM ,,,,
0

• Finite Automaton (FA)
 FqQM ,,,,
0

Q


0
q
F
: set of states
: input alphabet
: transition function
: initial state
: set of accepting states

• There are ________ tuples in finite state
machine.
a) 4
b) 5
c) 6
d) unlimited

DESCRIPTION OF A FINITE AUTOMATON

•Transition function maps.
a) Σ * Q -> Σ
b) Q * Q -> Σ
c) Σ * Σ -> Q
d) Q * Σ -> Q

•The transition function which maps Q x ∑*
into Q (i.e. maps a state and a string of
input symbols including the empty string
into a state) is called the indirect
transition function.

Transition System

•110011
•110110

Extended transition function is .
a) Q * Σ* -> Q
b) Q * Σ -> Q
c) Q* * Σ* -> Σ
d) Q * Σ -> Σ

110101

•Check for the 101101
•11111
•000000

•Find input sequence not accepted by M.

0
q
1
q
2
q
3
q
4
qa b b a
5
q
aa bb
ba,
ba,
ba,
Input alphabet

0
q
1
q
2
q
3
q
4
qa b b a
5
q
aa bb
ba,
 
543210
,,,,, qqqqqqQ
ba,
Set of States

1
q
2
q
3
q
4
qa b b a
5
q
aa bb
ba,
ba,
0
q
Initial State

Set of Accepting States
F
0
q
1
q
2
q
3
qa b b a
5
q
aa bb
ba,

4
qF
ba,
4
q
Accepting State

•Which of the following is not a part of 5-
tuple finite automata?
a) Input alphabet
b) Transition function
c) Initial State
d) Output Alphabet

Deterministic
Finite Automata

DFA
•FA and DFA are both abbreviations for finite
automata, but DFA stands for deterministic
finite automaton.
•A Deterministic Finite Automaton (DFA) is a
mathematical model of computation used to
recognize patterns within input strings. It's a
finite state machine where each input symbol
determines a unique transition from one state to
another.

Formal Definition

 FqQM ,,,,
0
 FqQM ,,,,
0

Q


0
q
F
: set of states
: input alphabet
: transition function
: initial state
: set of accepting states

How DFA works
•A DFA processes an input string one symbol
at a time.
•Starting from the start state, it moves to
the next state based on the current state
and the input symbol.
•The process continues until the end of the
input string is reached.
•If the final state is an accept state, the
string is accepted; otherwise, it is
rejected.

Rules of DFA:
•Deterministic Nature: For each state and each symbol in the
input alphabet, there is exactly one transition to a new state.
This ensures that the DFA's behavior is fully determined by
its current state and the current input symbol.
•Single Start State: The DFA must have one and only one
start state.
•Unique Transition: There is exactly one transition for each
symbol in the alphabet from each state. Formally, for any
state q Qq \in Qq Q and any symbol a Σa \in Σa Σ,
∈ ∈ ∈ ∈
there is exactly one state p Qp \in Qp Q such that
∈ ∈
δ(q,a)=pδ(q, a) = pδ(q,a)=p.
•Acceptance: A string is accepted by the DFA if, after
processing all input symbols, the DFA ends in one of the
accepting states.

Example
•Let's consider a DFA that accepts strings
ending with 'ab'.

Example 2
•DFA accepting strings that end with '11‘
•Alphabet: {0, 1}
•States: {q0, q1, q2}
•Start state: q0
•Accept states: {q2}

•Transitions:δ(q0, 0) = q0
•δ(q0, 1) = q1
•δ(q1, 0) = q0
•δ(q1, 1) = q2
•δ(q2, 0) = q0
•δ(q2, 1) = q2

Example 3:
DFA accepting strings that contain the
substring '01‘
•Alphabet: {0, 1}States: {q0, q1, q2}Start
state: q0Accept states:
{q2}Transitions:δ(q0, 0) = q0
•δ(q0, 1) = q0
•δ(q1, 0) = q2
•δ(q1, 1) = q1
•δ(q2, 0) = q2
•δ(q2, 1) = q2

Example 4:
•Construct a DFA that either starts with aa
or with bb from input (a,b).
•Designing DFA Step-by-Step:
•Step-1: Take initial state qo, and smallest
possible string are aa and bb if qo takes ‘a’
as the first input alphabet it goes to
state q1 and if qo takes ‘b’ as the first
input alphabet it goes to state q3.

•Step-2: Now think about state q1, if it takes
input alphabet ‘b’, it breaks our condition of  ‘aa’
but if takes input alphabet ‘a’ it makes an
acceptable string, and now it goes to
state q2 which is set to the final state.

•Step-3: On state q3 if it takes input alphabet ‘a’,
it breaks our condition of  ‘bb’ but if takes input
alphabet ‘b’ it makes an acceptable string, and
now it goes to state q2 which is set to the final
state.

•Step-4: If input alphabet ‘a’ of state q3 breaks
the condition and Input alphabet ‘b’ of
state q1 breaks the condition so they go to some
dead state(D).

•Step-5: Till now, our machine accepts strings that
starts from ‘aa’ or from ‘bb’ but we also have to
take care of all the symbols after the string has
begun from ‘aa’ or ‘bb’ and hence we introduce
ourselves loops in q2(final state) and D(dead
state).

Applications of DFA
•DFAs have various applications in computer
science, including:
•Lexical analysis: Breaking text into tokens
for compilers and interpreters.
•Pattern matching: Finding specific
patterns within text or data.
•Protocol analysis: Validating data packets
in communication protocols.
•Text search algorithms: Implementing
basic search functionalities.

Non-Deterministic
Finite Automata

1
q
2
q
3q
a
a
a
0q
}{aAlphabet =
Nondeterministic Finite Automaton

1
q
2
q
3q
a
a
a
0q
Two choices
}{aAlphabet =

No transition
1
q
2
q
3q
a
a
a
0q
Two choices
No transition
}{aAlphabet =

a a
0q
1
q
2
q
3q
a
a
First Choice
a

a a
0q
1
q
2
q
3q
a
a
a
First Choice

aa
0q
1
q
2
q
3q
a
a
First Choice
a

aa
0q
1
q
2
q
3q
a
a
a
“accept”
First Choice
All input is consumed

a a
0q
1
q
2
q
3q
a
a
Second Choice
a

a a
0q
1
q
2
q
a
a
Second Choice
a
3q

a a
0q
1
q
2
q
a
a
a
3q
Second Choice
No transition:
the automaton hangs

a a
0q
1
q
2
q
a
a
a
3q
Second Choice
“reject”
Input cannot be consumed

An NFA accepts a string:
when there is a computation of the
NFA that accepts the string
all the input is consumed and the automaton
is in an accepting state
There is a computation:

Example
aais accepted by the NFA:
0q
1q
2q
3q
a
a
a
“accept”
0
q
1q
2q
a
a
a
3
q
“reject”
because this
computation
accepts aa

a
0q
1
q
2
q
3q
a
a
Rejection example
a

a
0q
1
q
2
q
3q
a
a
a
First Choice

a
0q
1
q
2
q
3q
a
a
a
First Choice
“reject”

Second Choice
a
0q
1
q
2
q
3q
a
a
a

Second Choice
a
0q
1
q
2
q
a
a
a
3q

Second Choice
a
0q
1
q
2
q
a
a
a
3q“reject”

Which of the following not an
example Bounded
Information?
a) fan switch outputs {on, off}
b) electricity meter reading
c) colour of the traffic light
at the moment
d) none of the mentioned

An NFA rejects a string:
when there is no computation of the
NFA that accepts the string.
• All the input is consumed and the
automaton is in a non final state
• The input cannot be consumed
OR
For each computation:

Example
ais rejected by the NFA:
0
q
1
q
2
q
a
a
a
3
q
“reject”
0
q
1
q
2
q
a
a
a
3q
“reject”
All possible computations lead to rejection

Rejection example
a a
0q
1
q
2
q
3q
a
a
a
a

a a
0q
1
q
2
q
3q
a
a
a
First Choice
a

aa
0q
1
q
2
q
3q
a
a
First Choice
a
a
No transition:
the automaton hangs

aa
0q
1
q
2
q
3q
a
a
a
“reject”
First Choice
a
Input cannot be consumed

a a
0q
1
q
2
q
3q
a
a
Second Choice
a
a

a a
0q
1
q
2
q
a
a
Second Choice
a
3q
a

a a
0q
1
q
2
q
a
a
a
3q
Second Choice
No transition:
the automaton hangs
a

a a
0q
1
q
2
q
a
a
a
3q
Second Choice
“reject”
a
Input cannot be consumed

aaais rejected by the NFA:
0q
1q
2q
3q
a
a
a
“reject”
0
q
1q
2q
a
a
a
3
q
“reject”
All possible computations lead to rejection

1
q
2
q
3q
a
a
a
0q
Language accepted: }{aaL

Lambda Transitions
1
q
3
qa
0
q 
2
qa

aa
1
q
3
qa
0
q 
2
qa

aa
1
q
3
qa
0
q 
2
qa

aa
1
q
3
qa
0
q 
2
qa
(read head does not move)

aa
1
q
3
qa
0
q 
2
qa

aa
1
q
3
qa
0
q 
2
qa
“accept”
String is acceptedaa
all input is consumed

aa
1
q
3
qa
0
q 
2
qa
Rejection Example
a

aa
1
q
3
qa
0
q 
2
qa
a

aa
1
q
3
qa
0
q 
2
qa
(read head doesn’t move)
a

aa
1
q
3
qa
0
q 
2
qa
a
No transition:
the automaton hangs

aa
1
q
3
qa
0
q 
2
qa
“reject”
String is rejectedaaa
a
Input cannot be consumed

Language accepted: }{aaL
1
q
3
qa
0
q 
2
qa

Another NFA Example
0q 1q
2qa b 

3
q

ab
0q 1q
2qa b 

3
q

0q 2qa b 

3
q
ab
1
q

ab
0q 1q a b 

3
q
2
q

ab
0q 1q a b 

3
q
2
q
“accept”

0q
a b 

ab
Another String
ab
1
q
2
q
3
q

0q
a b 

abab
1
q
2
q
3
q

0q
a b 

abab
1
q
2
q
3
q

0q
a b 

abab
1
q
2
q
3
q

0q
a b 

abab
1
q
2
q
3
q

0q
a b 

abab
1
q
2
q
3
q

0q
a b 

abab
1
q
2
q
3
q

abab
0q
a b 

1
q
2
q
3
q
“accept”

 




ab
ababababababL ...,,,
Language accepted
0q 1q
2qa b 

3
q

Another NFA Example
0
q 1
q
2
q
0
1
1,0

{ }
{}*10=
...,101010,1010,10,λ=)(ML
0
q 1
q
2
q
0
1
1,0

Language accepted
(redundant
state)

Remarks:
•The symbol never appears on the
input tape

0
q
2
M
0
q
1
M
{}=)M(L
1 }λ{=)M(L
2
•Simple automata:

0
q
2q
1
q
a
a
a
0
q
1
q
a
}{=)(
1
aML
2
M
1
M
}{=)(
2
aML
NFA FA
•NFAs are interesting because we can
express languages easier than FAs

Formal Definition of NFAs

 FqQM ,,,,
0
:Q
:
:
0q
:F
Set of states, i.e. 
210
,,qqq
:Input aplhabet, i.e.ba,
Transition function
Initial state
Accepting states

•Which of the following options is correct?
Statement 1: Initial State of NFA is Initial State of DFA.
Statement 2: The final state of DFA will be every combination of final state
of NFA.
a) Statement 1 is true and Statement 2 is true
b) Statement 1 is true and Statement 2 is false
c) Statement 1 can be true and Statement 2 is true
d) Statement 1 is false and Statement 2 is also false


101,qq
0
1
1,0

Transition Function
0
q
1
q
2
q

0
q
0
1
1,0

},{)0,(
201
qqq
1
q

0
q
0
1
1,0

1
q
2
q
},{),(
200
qqq

0
q
0
1
1,0

1
q
2
q
)1,(
2
q

Extended Transition Function

*
0
q

5
q
4
q
3
q
2
q
1
q
a
aa
b 

10,* qaq

 
540 ,,* qqaaq 
0
q

5
q
4
q
3
q
2
q
1
q
a
aa
b 

  
0320 ,,,* qqqabq 
0
q

5
q
4
q
3
q
2
q
1
q
a
aa
b 

Formally
wqq
ij
,* : there is a walk from to
with label
i
q
j
q
w
i
q j
q
w
kw 
21
1
2
k
i
q j
q

•Which of the following is correct proposition?
Statement 1: Non determinism is a generalization of Determinism.
Statement 2: Every DFA is automatically an NFA
a) Statement 1 is correct because Statement 2 is correct
b) Statement 2 is correct because Statement 2 is correct
c) Statement 2 is false and Statement 1 is false
d) Statement 1 is false because Statement 2 is false

The Language of an NFA

0
q

5
q
4
q
3
q
2
q
1
q
a
aa
b 
 
540
,,* qqaaq  )(MLaa

50
,qqF
F

0
q

5
q
4
q
3
q
2
q
1
q
a
aa
b 
  
0320
,,,* qqqabq  MLab

50
,qqF
F

0
q

5
q
4
q
3
q
2
q
1
q
a
aa
b 

50
,qqF
 
540
,,* qqabaaq  )(MLaaba
F

0
q

5
q
4
q
3
q
2
q
1
q
a
aa
b 

50
,qqF
 
10
,* qabaq  MLaba
F

0
q

5
q
4
q
3
q
2
q
1
q
a
aa
b 
 }{*aaabML 

•NFA, in its name has ’non-deterministic’
because of :
a) The result is undetermined
b) The choice of path is non-deterministic
c) The state to be transited next is non-
deterministic
d) All of the mentioned

Diffrence B/w DFA NFA
DFA NFA
DFA stands for Deterministic Finite
Automata.
NFA stands for Nondeterministic
Finite Automata.
For each symbolic representation of
the alphabet, there is only one state
transition in DFA.
No need to specify how does the NFA
react according to some symbol.
DFA cannot use Empty String
transition.
NFA can use Empty String transition.
DFA can be understood as one machine.NFA can be understood as multiple
little machines computing at the same
time.
In DFA, the next possible state is
distinctly set.
In NFA, each pair of state and input
symbol can have many possible next
states.
DFA is more difficult to construct.NFA is easier to construct.

PROPERTIES OF TRANSITION FUNCTIONS
Tags