NonDeterministic Finite Automata Fall 2005 Costas Busch RPI
Non-Deterministic Finite Automata Fall 2005 Costas Busch - RPI 1
Nondeterministic Finite Automaton (NFA) Alphabet = Fall 2005 Costas Busch - RPI 2
Alphabet = Two choices Fall 2005 Costas Busch - RPI 3
Alphabet = Two choices No transition Fall 2005 Costas Busch - RPI 4
First Choice Fall 2005 Costas Busch - RPI 5
First Choice Fall 2005 Costas Busch - RPI 6
First Choice Fall 2005 Costas Busch - RPI 7
First Choice All input is consumed “accept” Fall 2005 Costas Busch - RPI 8
Second Choice Fall 2005 Costas Busch - RPI 9
Second Choice Fall 2005 Costas Busch - RPI 10
Second Choice No transition: the automaton hangs Fall 2005 Costas Busch - RPI 11
Second Choice Input cannot be consumed “reject” Fall 2005 Costas Busch - RPI 12
An NFA accepts a string: if there is a computation of the NFA that accepts the string i. e. , all the input is consumed and the automaton is in an accepting state Fall 2005 Costas Busch - RPI 13
Example is accepted by the NFA: “accept” because this computation accepts Fall 2005 “reject” Costas Busch - RPI 14
Rejection example Fall 2005 Costas Busch - RPI 15
First Choice Fall 2005 Costas Busch - RPI 16
First Choice “reject” Fall 2005 Costas Busch - RPI 17
Second Choice Fall 2005 Costas Busch - RPI 18
Second Choice Fall 2005 Costas Busch - RPI 19
Second Choice “reject” Fall 2005 Costas Busch - RPI 20
An NFA rejects a string: if there is no computation of the NFA that accepts the string. For each computation: • All the input is consumed and the automaton is in a non final state OR • The input cannot be consumed Fall 2005 Costas Busch - RPI 21
Example is rejected by the NFA: “reject” All possible computations lead to rejection Fall 2005 Costas Busch - RPI 22
Rejection example Fall 2005 Costas Busch - RPI 23
First Choice Fall 2005 Costas Busch - RPI 24
First Choice No transition: the automaton hangs Fall 2005 Costas Busch - RPI 25
First Choice Input cannot be consumed “reject” Fall 2005 Costas Busch - RPI 26
Second Choice Fall 2005 Costas Busch - RPI 27
Second Choice Fall 2005 Costas Busch - RPI 28
Second Choice No transition: the automaton hangs Fall 2005 Costas Busch - RPI 29
Second Choice Input cannot be consumed “reject” Fall 2005 Costas Busch - RPI 30
is rejected by the NFA: “reject” All possible computations lead to rejection Fall 2005 Costas Busch - RPI 31
Language accepted: Fall 2005 Costas Busch - RPI 32
Lambda Transitions Fall 2005 Costas Busch - RPI 33
Fall 2005 Costas Busch - RPI 34
Fall 2005 Costas Busch - RPI 35
(read head does not move) Fall 2005 Costas Busch - RPI 36
Fall 2005 Costas Busch - RPI 37
all input is consumed “accept” String Fall 2005 is accepted Costas Busch - RPI 38
Rejection Example Fall 2005 Costas Busch - RPI 39
Fall 2005 Costas Busch - RPI 40
(read head doesn’t move) Fall 2005 Costas Busch - RPI 41
No transition: the automaton hangs Fall 2005 Costas Busch - RPI 42
Input cannot be consumed “reject” String Fall 2005 is rejected Costas Busch - RPI 43
Language accepted: Fall 2005 Costas Busch - RPI 44
Another NFA Example Fall 2005 Costas Busch - RPI 45
Fall 2005 Costas Busch - RPI 46
Fall 2005 Costas Busch - RPI 47
Fall 2005 Costas Busch - RPI 48
“accept” Fall 2005 Costas Busch - RPI 49
Another String Fall 2005 Costas Busch - RPI 50
Fall 2005 Costas Busch - RPI 51
Fall 2005 Costas Busch - RPI 52
Fall 2005 Costas Busch - RPI 53
Fall 2005 Costas Busch - RPI 54
Fall 2005 Costas Busch - RPI 55
Fall 2005 Costas Busch - RPI 56
“accept” Fall 2005 Costas Busch - RPI 57
Language accepted Fall 2005 Costas Busch - RPI 58
Another NFA Example Fall 2005 Costas Busch - RPI 59
Language accepted (redundant state) Fall 2005 Costas Busch - RPI 60
Remarks: • The symbol never appears on the input tape • Simple automata: Fall 2005 Costas Busch - RPI 61
• NFAs are interesting because we can express languages easier than DFAs NFA Fall 2005 DFA Costas Busch - RPI 62
Formal Definition of NFAs Set of states, i. e. Input aplhabet, i. e. Transition function Initial state Accepting states Fall 2005 Costas Busch - RPI 63
Transition Function Is the result of following exactly one transition Fall 2005 Costas Busch - RPI 64
Fall 2005 Costas Busch - RPI 65
Fall 2005 Costas Busch - RPI 66
Fall 2005 Costas Busch - RPI 67
Extended Transition Function Fall 2005 Costas Busch - RPI 68
Fall 2005 Costas Busch - RPI 69
Fall 2005 Costas Busch - RPI 70
Formally : there is a walk from with label Fall 2005 Costas Busch - RPI to 71
The Language of an NFA Fall 2005 Costas Busch - RPI 72
Fall 2005 Costas Busch - RPI 73
Fall 2005 Costas Busch - RPI 74
Fall 2005 Costas Busch - RPI 75
Fall 2005 Costas Busch - RPI 76
Formally The language accepted by NFA is: where (accepting state) and there is some Fall 2005 Costas Busch - RPI 77
Fall 2005 Costas Busch - RPI 78
NFAs accept the Regular Languages Fall 2005 Costas Busch - RPI 79
Equivalence of Machines Definition: Machine is equivalent to machine if Fall 2005 Costas Busch - RPI 80
Example of equivalent machines NFA DFA Fall 2005 Costas Busch - RPI 81
We will prove: Languages accepted by NFAs Regular Languages NFAs and DFAs have the same computation power Fall 2005 Costas Busch - RPI Languages accepted by DFAs 82
We will show: Languages accepted by NFAs Regular Languages Fall 2005 Costas Busch - RPI 83
Proof-Step 1 Languages accepted by NFAs Regular Languages Proof: Every DFA is trivially an NFA Any language accepted by a DFA is also accepted by an NFA Fall 2005 Costas Busch - RPI 84
Proof-Step 2 Languages accepted by NFAs Regular Languages Proof: Any NFA can be converted to an equivalent DFA Fall 2005 Any language accepted by an NFA is also accepted by a DFA Costas Busch - RPI 85
Convert NFA to DFA NFA DFA Fall 2005 Costas Busch - RPI 86
Convert NFA to DFA NFA DFA Fall 2005 Costas Busch - RPI 87
Convert NFA to DFA NFA DFA Fall 2005 Costas Busch - RPI 88
Convert NFA to DFA NFA DFA Fall 2005 Costas Busch - RPI 89
Convert NFA to DFA NFA DFA Fall 2005 Costas Busch - RPI 90
Convert NFA to DFA NFA DFA Fall 2005 Costas Busch - RPI 91
Convert NFA to DFA NFA DFA Fall 2005 Costas Busch - RPI 92
NFA to DFA: Remarks We are given an NFA We want to convert it to an equivalent DFA With Fall 2005 Costas Busch - RPI 93
If the NFA has states the DFA has states in the powerset Fall 2005 Costas Busch - RPI 94
Procedure NFA to DFA 1. Initial state of NFA: Initial state of DFA: Fall 2005 Costas Busch - RPI 95
Example NFA DFA Fall 2005 Costas Busch - RPI 96
Procedure NFA to DFA 2. For every DFA’s state Compute in the NFA Add transition to DFA Fall 2005 Costas Busch - RPI 97
Exampe NFA DFA Fall 2005 Costas Busch - RPI 98
Procedure NFA to DFA Repeat Step 2 for all letters in alphabet, until no more transitions can be added. Fall 2005 Costas Busch - RPI 99
Example NFA DFA Fall 2005 Costas Busch - RPI 100
Procedure NFA to DFA 3. For any DFA state If some is accepting state in NFA Then, is accepting state in DFA Fall 2005 Costas Busch - RPI 101
Example NFA DFA Fall 2005 Costas Busch - RPI 102
Theorem Take NFA Apply conversion procedure to obtain DFA Then Fall 2005 and are equivalent : Costas Busch - RPI 103
Proof AND Fall 2005 Costas Busch - RPI 104
First we show: Take arbitrary: We will prove: Fall 2005 Costas Busch - RPI 105
NFA Fall 2005 Costas Busch - RPI 106
denotes Fall 2005 Costas Busch - RPI 107
We will show that if NFA then DFA Fall 2005 Costas Busch - RPI 108
More generally, we will show that if in : (arbitrary string) NFA then DFA Fall 2005 Costas Busch - RPI 109
Proof by induction on Induction Basis: NFA DFA Is true by construction of Fall 2005 Costas Busch - RPI 110
Induction hypothesis: NFA DFA Fall 2005 Costas Busch - RPI 111
Induction Step: NFA DFA Fall 2005 Costas Busch - RPI 112
Induction Step: NFA DFA Fall 2005 Costas Busch - RPI 113
Therefore if NFA then DFA Fall 2005 Costas Busch - RPI 114
We have shown: We also need to show: (proof is similar and omitted) Fall 2005 Costas Busch - RPI 115
- Slides: 115