Two Way Deterministic Finite Automata

Two Way Deterministic Finite Automata
Jagvir Singh
and
Pavan Kumar Akulakrishna
Indian Institute of Science
November 29, 2013
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
1 / 14
Overview
Introduction.
Formal Construction.
Example.
Configuration and Acceptance.
2DFA vs DFA.
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
2 / 14
2-way Deterministic Finite Automata
1
2
Generalised version of DFA.
Process the input in either direction.
Have read only head which can move in both direction over the input
string.
Revisit the characters again and again.
3
Like a Turing Machine but.
Have read only head.
Have finite memory like DFA.
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
3 / 14
2-way Deterministic Finite Automata
4
5
2DFA has finite set of states Q like DFA.
Input string
Input string is stored on finite tape.
One character per cell.
Input string is stored in between two extra symbol called left
endmarker(`) and right endmarker(a).
6
At any time instance the machine is in state p and scan some symbol
ai ∈ Σ or an endmarkers {`, a}, based on p and current symbol it
will move its head one cell in direction d ∈ {L, R} and enter in new
state q .
7
Machine head never go outside the endmarkers.
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
4 / 14
2-way Deterministic Finite Automata
8
Accept and reject states.
2DFA needs only single accept and single reject state.
It will accept the input string by entering in a special accept state t.
It will reject the input string by entering in a special reject state r .
Accept and reject states are like sink state.
9
The machine action on a present state and head symbol is depend on
transition function δ.
10
Transition function take present state and head symbol as input
argument and return next state and direction of movement of head.
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
5 / 14
Formal definition of 2DFA
2DFA is represented by octuple.
M = {Q, Σ, δ, s, t, r , `, a}
where
Q is a finite set of states.
Σ is a finite set of input symbol.
δ : Q × (Σ ∪ {`, a}) = Q × {L, R} is a transition function.
s ∈ Q is a start state.
t ∈ Q is a accept state.
r ∈ Q is a reject state.
` is left endmarker.
a is right endmarker.
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
6 / 14
Some properties of transition function
1
Input is endmarker.
δ(p, `) = (q, R)
δ(p, a) = (q, L)
2
Accept and reject states are t, r respectively and current input symbol
is a ∈ Σ ∪ {`}.
δ(t, a) = (t, R) and δ(t, a) = (t, L)
δ(r , a) = (r , R) and δ(r , a) = (r , L)
3
In general
δ(p, a) = (q, d) where p, q ∈ Q and d ∈ {L, R}
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
7 / 14
Example (Constructing a normal DFA)
Construct the DFA to accept the language
L = {x ∈ Σ∗ |#a(x) are multiple of 3, #b(x) are multiple of 2}
Construct a normal DFA
1 DFA M accepting L = {x ∈ Σ∗ |#a(x) are multiple of 3}
1
1
M1 = {Q1 , Σ, δ1 , s1 , F1 }
2 DFA M accepting L = {x ∈ Σ∗ |#b(x) are multiple of 2}
2
2
M2 = {Q2 , Σ, δ2 , s2 , F2 }
3 DFA M accepting L such that M = M × M
1
2
M = {Q, Σ, δ, s, F }
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
8 / 14
Example(Constructing a 2DFA )
Construct a 2DFA accepting the set
L = {x ∈ Σ∗ |#a(x) are multiple of 3, #b(x) are multiple of 2}
1
Machine start scanning from the left endmarker.
2
Scan input string from left to right consider only a and ignore b.
if #a(x) are not multiple of 3 then rejects x and enters in state r .
3
if #a(x) are multiple of 3 then start scanning from right consider only
b and ignore a.
if #b(x) are not multiple of 2 then enters in t otherwise enters in
state r .
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
9 / 14
Example (Formal construction of 2DFA)
M = {Q, Σ, δ, s, t, r , `, a}
where Σ = {a, b}, Q = {q0 , q1 , q2 , p0 , p1 , t, r } and the transition function
δ is given by following table.
states
q0
q1
q2
p0
p1
t
r
`
(q0 , R)
(t, R)
(r , R)
(t, R)
(r , R)
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
a
(q1 , R)
(q2 , R)
(q0 , R)
(p0 , L)
(p1 , L)
(t, R)
(r , R)
2DFA
b
(q0 , R)
(q1 , R)
(q2 , R)
(p1 , L)
(p0 , L)
(t, R)
(r , R)
a
(p0 , L)
(r , L)
(r , L)
(t, L)
(r , L)
November 29, 2013
10 / 14
Configuration and Acceptance
Let we have input string x ∈ Σ∗ such that x = a1 a2 · · · an−1 an ,|x| = n
and let a0 =`, an+1 =a then machine head will scan ` x a .
1
Configuration for the input x is pair (p, j) such that p ∈ Q and
0 ≤ j ≤ n + 1.
2
In pair (p, j) p is current state and j is current position of head.
3
Initial configuration of machine is (s, 0) this mean initially machine is
in state s and scanning left endmarker.
4
The relation −
→ describes one step of the machine on input x.
1
x
1
δ(p, aj ) = (q, L) ⇒ (p, j) −
→ (q, j − 1)
x
1
δ(p, aj ) = (q, R) ⇒ (p, j) −
→ (q, j + 1)
x
0
(p, j) −
→ (p, j)
x
n
1
n+1
x
x
x
(p, i) −
→ (q, j) and (q, j) −
→ (u, k) then (p, i) −−→ (u, k)
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
11 / 14
5
∗
def
n
(p, j) −
→ (q, k) ⇐⇒ ∃n ≥ 0 such that (p, j) −
→ (q, k)
x
6
7
x
∗
Machine accept input string x if (s, 0) −
→ (t, k) for some k.
x
∗
Machine reject input string x if (s, 0) −
→ (r , k) for some k.
x
8
9
It is possible that machine neither accept nor reject input string x
then machine go in loop.
∗
Language accepted by machine M is L(M) = {x ∈ Σ∗ |(s, 0) −
→ (t, k)}
x
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
12 / 14
2DFA vs DFA
Jagvir Singh and Pavan Kumar Akulakrishna (IISC)
2DFA
November 29, 2013
13 / 14