Professional Documents
Culture Documents
COMPUTABILITY
(BCS 214)
This piece of work is dedicated, first and foremost, to God Almighty for keeping me
alive and to the ones I love; my mum Mary Lamunu, my brothers; Bonny, Erick,
Walter, Justine and Vincent, my Uncle Philip Otim and finally to my beloved fiancée
Molly Shiella.
ii
Preface
iii
Organization and Features
iv
Methods of Presentation
This tutorial has a modular construction. Chapters 2 through 9 are the core of the
book, chapter 1 may be assigned as preliminary reading or may be covered in the
introductory lecture(s). The order of presentation in a classroom depends on and
needs to follow the table of contents in sequence since the proceeding chapters are
built on the preceding chapters.
Acknowledgements
Special thanks go to Dr. Okello Onen; Dean Faculty of Science – Gulu University
and Mr. Nimrod Mafabi; Head of Department- Computer Science for their support.
My gratitude to all my friends and colleagues, particularly those at the Department of
Computer Science; especially Mr. Tabo Geoffrey Olok, Miss Pauline Olango, Mr.
Billy Kalema and others; who were so generous with their encouragement, advice
and support.
Special thanks also go to my beloved fiancée Molly Shiella for her endless support
and encouragement; and for always being there whenever I need help both spiritually
and socially and to my uncle Mr. Philip Otim for seeing me through with my
education.
TABLE OF CONTENTS
v
Dedication...............................................................................................................ii
Preface....................................................................................................................iii
Organization and Features...........................................................................iv
Methods of Presentation.................................................................................v
Acknowledgements...........................................................................................v
CHAPTER ONE......................................................................1
1.1.0 BASIC DEFINITIONS.....................................................................................1
1.1.1 Automata:.....................................................................................................1
1.1.2 Alphabet:......................................................................................................1
1.1.3 Algorithm:....................................................................................................2
1.2.0 ALGEBRAIC PRELIMINARIES....................................................................2
1.2.1 Definitions:..................................................................................................2
1.3.0 MAPPING..........................................................................................................3
CHAPTER TWO.....................................................................5
2.1.0 DETERMINISTIC SEMI-AUTOMATA (DSA)..............................................5
2.1.1 Definition:.....................................................................................................5
2.2.0 NON-DETERMINISTIC SEMI-AUTOMATA (NDSA).................................7
2.2.1 Definition:.....................................................................................................7
CHAPTER THREE.................................................................8
3.1.0 DETERMINISTIC FINITE AUTOMATA (DFA)...........................................8
3.1.1 Definition:.....................................................................................................8
3.1.2 Examples:....................................................................................................8
3.2.0 NON-DETERMINISTIC FINITE AUTOMATA (NDFA)............................11
3.2.1 Definition:...................................................................................................11
3.2.2 Examples:..................................................................................................11
CHAPTER FOUR.................................................................13
4.0 REGULAR EXPRESSIONS............................................................................13
4.1 Definition one:..............................................................................................13
4.2 Definition two: ...........................................................................................13
4.3 Properties of Operations on REs:...........................................................14
CHAPTER FIVE...................................................................15
5.0 TRANSITION GRAPHS...................................................................................15
5.1.1 Definition:...................................................................................................15
5.1.2 More examples:........................................................................................16
5.2.0 SETS OF WORDS CORRESPONDING TO TRANSITION GRAPHS: 18
5.2.1 Examples:..................................................................................................18
5.2.2 Assignment:..............................................................................................24
CHAPTER SIX......................................................................28
6.0 GRAMMARS......................................................................................................28
6.1 Definition:......................................................................................................28
6.2 Classification of Grammars......................................................................28
6.2.1. Type 0 or Right Linear Grammar:...................................................28
6.2.2. Type 1 or Context Sensitive Grammar:.........................................29
6.2.3. Type 2 or Context Free Grammar:..................................................29
6.2.4. Type 3 or Regular Grammar:...........................................................29
6.3 Definitions.....................................................................................................30
6.4 Deriving Grammar from a Given Language:........................................31
CHAPTER SEVEN...............................................................33
7.0 PUSH-DOWN AUTOMATA AND CONTEXT-FREE GRAMMAR............33
7.1 Definition:......................................................................................................33
vi
7.2 Examples:......................................................................................................33
CHAPTER EIGHT................................................................38
8.0 MARKOV ALGORITHMS (MAs)....................................................................38
8.1 Introduction:.................................................................................................38
8.2 Definition:......................................................................................................38
8.3 Examples.......................................................................................................39
CHAPTER NINE...................................................................44
9.0 TURING MACHINE...........................................................................................44
9.1 Introduction:.................................................................................................44
9.2 Physical Interpretation:.............................................................................44
9.3 Description of the TM through Quintuples:.........................................44
9.4 Definition (other):........................................................................................45
BIBLIOGRAPHY..................................................................................................46
APPENDIX: SAMPLE QUESTIONS.............................................................47
NOTES.....................................................................................................................53
vii
CHAPTER ONE
1.1.1 Automata:
1.1.2 Alphabet:
The set of all words over an alphabet I is denoted by I* which is an infinite set.
Subsets of I* are referred to as Languages over the alphabet I.
E.g. the following sets are languages over the alphabet I 2 = {x1, x2}:
1
Languages L1, L2 are finite while L3 & L4 are infinite.
1.1.3 Algorithm:
1.2.1 Definitions:
Let R be a relation between A and B i.e. R is a set of pairs (a, b). Then we
write R or aRb.
The inverse relation R-1 is defined by
Consider a binary relation on a set S. A binary relation R over the set S is said
to be:
2
1. Reflexive: If for each s S, sRs i.e. {(s, s): s S};
2. Symmetric: If for s and t in S, sRt => tRs (R = R-1);
3. Transitive: If for s, t and u in S, sRt and tRu => sRu
4. A binary relation which is reflexive, symmetric and transitive is called
an equivalence relation.
Example:
If S = {1, 2, 3, 4}
Then;
R1= {(1, 1), (2, 2), (3, 3), (4, 4)} is a Reflexive relation.
NB: If one of the members of R doesn’t exist, then the relation is NOT
reflexive.
R2 = {(1, 2), (2, 1), (2, 3), (3, 2)} is a Symmetric relation.
And
R3 = {(1, 2), (2, 3), (1, 3)} is a Transitive relation
1.3.0 MAPPING
The identity relation IA over a set A is the set of all pairs (a, a); a A.
E.g.
If A= {a, b, c} and B= {d, e, f},
Then
U = {(a, d), (b, e), (c, d)} is a mapping.
Note: Elements of the second set can be repeated but those of the first one
cannot.
3
And
U = {(a, b), (b, c), (c, a)} is a permutation; i.e. elements are formed from one
set.
IA = {(a, a), (b, b), (c, c)} is an identity relation.
Exercises:
4
CHAPTER TWO
2.1.1 Definition:
Example;
A = ({1, 2, 3, 4, 5, 6}, {δ 0, δ1}, {mδ0 = (1, 3), (2, 1), (3, 2), (4, 1), (5, 3), (6, 5);
mδ1 = (1, 4), (2, 5), (3, 3), (4, 3), (5, 3), (6,3)}) is a semi-automaton with 6
states and 2 inputs.
A semi-automaton can also be described by means of a table called a Next
State Table (NST) or Transition Table (TT). For the above example, the TT
will have the following form:
States
mδi 1 2 3 4 5 6
Inputs δ0 3 1 2 1 3 5
δ1 4 5 3 3 3 3
5
A directed graph for the above example:
δ0 δ1
1 δ0 2 δ0 3
δ0, δ1
δ0 δ1 δ1 δ1
4 5 δ0 6
δ1
Exercise:
0 1
p r q
q s p
1. Represent the above automaton as a directed
r p s
graph.
s q r
2. Show the mappings of the above automaton in
the form.
(k, x) = k where k {p, q, r, s} and x {0, 1}
6
2.2.1 Definition:
Example:
A = ({1, 2, 3, 4, 5}, {0, 1}, {A0 = {(1, 2), (2, 1), (3, 2), (3, 3), (4, 3)}; A1 = {(1, 4),
(3, 4), (4, 2), (4, 3), (4, 5)}})
Transition table:
Ai 1 2 3 4 5
0 2 1 2,3 3
1 4 4 3,5
Directed graph:
0 0
0
1 0 2 3
1 1
1
0, 1
5 4
1
Exercise:
CHAPTER THREE
7
3.1.0 DETERMINISTIC FINITE AUTOMATA (DFA)
3.1.1 Definition:
3.1.2 Examples:
A = (S, Σ, m, S0, F)
Where Σ = {0, 1}, S = {S0, S1, S2, S3}, F= {S0} and m is defined as follows:
δ(S0, 0)=S2
δ(S1,0)=S3
δ(S2,0)=S0
δ(S3,0)=S1
δ(S0,1)=S1
δ(S1,1)=S0
δ(S2,1)=S3
δ(S3,1)=S2
Directed graph:
8
NB: By convention, a double ring is used to denote or indicate a final state in
FA.
S0 S1
1
0 0 0 0
1
S2
S3
1
1 1 0 1 0 1
S0 → S1 → S 0 → S2 → S 3 → S1 → S 0
Therefore x will be accepted by automaton A.
NB: A string is accepted if it ends in a state which is a member of the final
state F.
A set of words accepted by an automaton A is called a regular set.
A partition Σ* into two disjoint sets i.e.
U = {set of words accepted by A}
Σ*-U = {set of words rejected by A}.
Exercise:
(s0, 0) = s2
(s1, 0) = s3
(s2, 0) = s0
(s3, 0) = s1
(s0, 1) = s1
(s1, 1) = s0
(s2, 1) = s3
(s3, 1) = s2
9
Where 0, 1 are elements of the automaton alphabet and s 0, s1, s2 and
s3 are the states of the automaton, s0 being the initial and final state.
i) 110101
ii) 111010
iii) 101010
iv) 011011
10
3.2.0 NON-DETERMINISTIC FINITE AUTOMATA (NDFA)
3.2.1 Definition:
3.2.2 Examples:
A = ({S0, S1, S2, S3, S4}, {0, 1}, m, S0, {S2, S4}) and m is defined as:
δ(S0, 0) = {S0, S3}
δ(S1, 0) = { Ø } i.e. Undefined
δ(S2, 0) = S2
δ(S3, 0) = S4
δ(S4, 0) = S4
δ(S0, 1) = {S0, S1}
δ(S1, 1) = S2
δ(S2, 1) = S2
δ(S3, 1) = Ø
δ(S4, 1)= S4
Solution:
Directed Graph:
0, 1
0, 1
S0 S3 S4
0 0
1
S1
S2
0, 1
11
Let x = 01101 be input into A;
Lower route:
0 1 1 0 1
S0 → S0 → S1 → S2 → S2→ S2; Hence x is accepted along this route
0 1 1 0 1
S0 → S0 → S1 → S0 → S1 →!!! Not accepted!
Upper route:
0 1
S0 → S3 →!!!! Rejected!
Exercise:
(s0, 0) = {Ø}
(s1, 0) = s3
(s2, 0) = {s0, s3}
(s3, 0) = s1
(s0, 1) = s1
(s1, 1) = {Ø}
(s2, 1) = s3
(s3, 1) = {s2, s1}
i) 110101
ii) 111010
iii) 101010
iv) 011011
12
CHAPTER FOUR
A SET UNION by
R+S = {x: x R or x S}
A SET CONCATENATION by
R.S = RS = {xy: x R, y S}
A CLOSURE OPERATOR by
R* = Λ + {x: x is obtained by concatenating a finite number of words of R}
= Λ + R + R2 + ……. + Ri + …… (i.e. R0 = Λ)
Where Ri = (……((RR)R….)R i times, i.e.
R* =
Example
Let Σ = {a, b}
R = {aa, ab} = {a2, ab}
S = {aba, ab, ba}
Then
R+S = {a2, ab, aba, ba}
RS = {a2aba, a2ab, a2ba, ababa, abab,abba}
R* = Λ + {a2, ab, a2a2, a2ab, abab, …….}
= (a2)m.(ab)n; m, n 0
Order of precedence in decreasing is *, ., +.
RS and SR give different results because the operation is order sensitive.
13
4. If P and Q are regular sets over Σ, then so are P+Q, PQ and P*;
5. Nothing else is a regular set.
Thus, a set of Σ* is regular if and only if it falls in any of the above, or can be
obtained from them by a finite number of applications of Union, Concatenation
and Closure.
1. R+R = R, R+Ø = R
2. R+S = S+R
3. (R+S)+T = R+(S+T)
4. (RS)T = R(ST) = RST
5. R.Λ = Λ.R = R
6. (R+S)T = RT+ST
7. T(R+S) = TR+TS
8. R*.R* = R*
9. (R*)* = R*
10. RR* = R*R = R*
11. R* = Λ+RR*
For any function F(R1, R2, ….., Rn),
12. F(R1, R2, ….., Rn)+( R1, R2, ….., Rn)* = ( R1, R2, ….., Rn)* i.e. F(R1, R2,
….., Rn) ( R1, R2, ….., Rn)*
13. (R*+S*)* = (R*S*)*
14. (RS)*R = R(SR)*
15. (R*S)*R* = (R+S)*
16. (R*S)* = (R+S)S*+ Λ
17. (SR*)* = S(R+S)*+ Λ
Exercise:
0
0
0 0
1 2 3 4
+
+
1
1
14
CHAPTER FIVE
5.1.1 Definition:
Examples:
1.
2.
3.
4.
Can accept 1, 11, 111, but not an empty word; γ creates a loop.
T (G) = 11*
5.
15
T (G) = Λ
6.
7.
8.
1.
Accepts 1000, 1001, 0000, 0001, 1*000, 1*001, 0*000, 0*001, 0*000*, 0*001*,
1*000*, 1*001*, etc
2.
T (G) = 0 + 11*
0 can be accepted and a series of 1s.
Therefore;
T (G1) = 0
T (G2) = 11*
16
We have to minimise on the number of gammas (γ) on the transition graph; so
we have:
i.e.
Create an arrow from final state of one node to initial node of the second one.
Therefore;
Exercise:
i) (a + b)* bab
ii) [10 + (0 + 11)0*1]*1
iii) (0 + 1)* 00 (0 + 1)*
17
5.2.0 SETS OF WORDS CORRESPONDING TO TRANSITION GRAPHS:
Tx: - represents all words which correspond to paths leaving from the vertices
in Ax to the final vertex in the transition graph G.
Ax: - represents the set of all vertices in G which can be reached from the
initial vertex following a path corresponding to the word x Σ* and including
any γ arrows.
To obtain a regular expression corresponding to a given transition graph, we
construct a table of derivatives which consists of four columns; i.e.
i) Inputs: - These are words x Σ* ordered by length and for words of
the same length ordered by their numerical magnitude.
ii) Vertices of G: - The corresponding subsets Ax are marked.
iii) Equal to: - If Axy = Ax, then we mark x in the row of xy.
iv) Includes Λ: - A ‘yes’ appears in this column if and only if the
corresponding Ax includes a final vertex.
Tx = 0Tx0 + 1Tx1 + αx
Where
αx = Λ, x Tx
, x Tx
In the expression Tx, any terminal derivative on the R.H.S of the equation is
replaced by the “Equal to” non-terminal appearing in the 3rd column of the
table and in this way a system of equations in which the non-terminals appear
as unknowns is obtained.
5.2.1 Examples:
Obtain a regular expression for the strings recognised by the transition graphs
below:
18
Example 5.2.1.1
2
0
1
1
1 5 +
-
0
1
0
3 4 1
1
T0 = 0T00 + 1T10 + α0
Table of derivatives:
Input Vertices of G Equal to Includes Λ
1 2 3 4 5
Non-terminals
Λ √ - - - - - -
0 - - √ - - - -
1 - √ - √ √ - Yes
Terminals
00 - - √ - - 0 -
01 √ - - - - Λ -
10 √ - - - - Λ -
11 - - √ - - 0 -
Now:
Tx = 0Tx0 + 1Tx1 + αx
From table;
T00 = T0, T01 = T Λ = T, T10 = T, T11 = T0
When x = Λ;
T Λ = 0T Λ0 + 1T Λ1 + α Λ
When x = 0;
T0 = 0T00 + 1T01 + α0
T0 = 0T0 + 1T
(2)
When x = 1;
T1 = 0T10 + 1T11 + α1
19
=> T1 = 0T + 1T0 + Λ
(3)
Possible strings:
1, (10)*1, (00*1)*1, (110*1)*1
Transition graph:
1 0
0
1
1
- +
1
1
0
Example 5.2.1.2
20
1
3
γ
0
γ 2
0
1 γ 4
Table of derivatives:
Input Vertices of G Equal to Includes Λ
1 2 3 4
Λ √ √ √ - - Yes
0 √ √ √ √ - Yes
1 - - √ - - -
00 √ √ √ √ 0 Yes
01 - - √ - 1 -
10 - √ √ - - -
11 - - √ - 1 -
Add more inputs; since 10 is not equivalent to any non-terminal
100 √ √ √ √ 0 Yes
101 - - √ - 1 -
Tx = 0Tx0 + 1Tx1 + αx
T00 = T100 = T0, T01 = T11 = T101 = T1
(4) in (3);
T1 = 0(0T0 + 1T1) + 1T1
= 00T0 + (01 + 1)T1
T1 = (01 + 1)*00T0 (5)
21
(5) in (2);
T0 = 0T0 + 1[(01 + 1)*00T0] + Λ
= 0T0 + 1(01 + 1)*00T0 + Λ
= [0 + 1(01 + 1)*00]T0 + Λ
= [0 + 1(01 + 1)*00]* Λ
= [0 + 1(01 + 1)*00]*
T0 = [0 + 1(01 + 1)*00]* (6)
Example 5.2.1.3
3
γ
0
γ 2
0
1 γ 4
1
Table of derivatives:
Input Vertices of G Equal to Includes Λ
1 2 3 4
Λ √ √ √ - - Yes
0 √ √ √ √ - Yes
1 - - √ - - -
00 √ √ √ √ 0 Yes
01 √ √ √ √ 0 Yes
10 - √ √ - - -
11 - - √ - 1 -
100 √ √ √ √ 0 Yes
101 - - √ - 1 -
22
From table: T101 = T11 = T1, T100 = T01 = T00 = T0
When x = Λ,
T Λ = 0T Λ0 + 1T Λ1 + α Λ
T = 0T0 + 1T1 + Λ
(1)
When x = 0,
T0 = 0T00 + 1T01 + α0
T0 = 0T0 + 1T0 + Λ
= (0 + 1)T0 + Λ
= (0 + 1)* Λ
T0 = (0 + 1)* (2)
When x = 1,
T1 = 0T10 + 1T11 + α1
T1 = 0T10 + 1T1 (3)
When x = 10,
T10 = 0T100 + 1T101 + α10
T10 = 0T0 + 1T1 (4)
Substituting (4) into (3);
T1 = 0(0T0 + 1T1) + 1T1
= 00T0 + (01 + 1) T1
= (01 + 1)*00T0 (5)
(2) into (5);
T1 = (01 + 1)*00(0 + 1)*
(6)
(2) and (6) into (1);
T = 0(0 + 1)* + 1[(01 + 1)*00(0 + 1)*] + Λ
Example 5.21..4
0 0
γ 0
0
1 2 3 4
1 1
Table of Derivatives:
Inputs Vertices Equal to Includes Λ
1 2 3 4
Λ √ √ √ - - Yes
0 - √ √ √ - Yes
1 - √ - - - -
00 - √ √ √ 0 Yes
01 - √ - √ - Yes
10 - √ √ - - -
11 - √ - - 1 -
010 - √ √ √ 0 Yes
011 - √ - √ 01 Yes
23
100 - √ √ √ 0 Yes
101 - √ - - 1 -
NB: Add more inputs since 01 and 10 are any of the Non-terminals. Hence
they also become non-terminals themselves.
Tx = 0Tx0 + 1Tx1 + αx
When x = Λ; T = 0T0 + 1T1 + Λ
(1)
(5)
5.2.2 Assignment:
24
Δ 0 1
P r q
q s p
r p s
s q r
i)
0
1 0 2
1 1
3
0, 1
ii)
25
1
1
0
1 2 1 3 1 4
0
0 0
Exercise:
1 2 3
+ 1
0 0
26
b). Using the table of derivatives obtained in (a) above,
obtain the regular expression generated by the transition graph
G. simplify your expression to the smallest possible form.
2 0
-
1
1
1 - 5 +
- -
1
0 3 1
- 1 -
-
4
27
CHAPTER SIX
6.0 GRAMMARS
6.1 Definition:
A grammar for a language L uses two distinct sets of symbols, that is, the set
of Non terminals N and the set of terminal symbols Σ.
28
Σ is the alphabet over which the language is defined, N are symbols used in
the generation of words in L.
Example:
G = ({A, S}, {0, 1}, P, S) where P consists of:
S 0A1
0A 00A1
A Λ
Some derivatives: S 0A1 00A11 0011 (00Λ11)
Or S 0A1 01 (0Λ1)
S 00A11 000A111
000111
Example:
29
V Z0/0
Where Σ = {0, 1} and N = {U, V, Z}.
1
0
Z A
0
0
S
Z A0
A A0
A Z1
A 0
Z A0 00
Z A0 A00 000
Z A0 Z10 A010 A0010 00010
6.3 Definitions
30
Syntax refers to the set of rules for determining whether or not a sentence
generated by G is in L (G).
Example:
2) Consider
(i) S aSb
S b
(ii) S Ab
A aAb
A Λ
Possible strings:
b, abb, aabbb, aaabbbb, ………………
S aSb aaSbb aabbb
L (G) = {anbn+1; n 0}
For S Ab
A aAb
A Λ
31
S Ab b
S Ab aAbb abb
S Ab aAbb aaAbbb aabbb are the possible strings.
Here we have two grammars which generate the same language. Hence the
two grammars are equivalent.
Solution:
Possible strings:
n = 1, a2b2 = aabb
n = 2, (a2b2)2 = aabbaabb
aabb, aabbaabb, aabbaabbaabb, ……………
Hence;
S aabbA
A aabbA
A Λ
Solution:
n = 0, anbn+1 = b
n = 1, anbn+1 = abb
n = 2, anbn+1 = aabbb
n = 3, anbn+1 = aaabbbb
b, abb, aabbb, aaabbbb, ……
Hence,
S Ab
A aAb
A
Exercise:
32
ii) Syntax
iii) Derivation
iv) Sentence
v) Sentential form
A A0 | 1 | B1
B C1 | 1
C 0 | A1 | B0
CHAPTER SEVEN
7.1 Definition:
33
F K is the set of final states.
δ is a mapping from K {Σ Λ} Г to finite subsets of K Г*, i.e.
δ (q0, a, z) = {(p1, γ1), (p2, γ2), ….., (pm, γm)} where q0 and pi K, a Σ, and γi
Г*
7.2 Examples:
START
a
INPUT=?
Λ
Λ
b
PUSH DOWN
S Yes
STACK EMPTY? REJECT
No
b POP UP
a
INPUT=?
Λ
No
STACK EMPTY?
Yes
ACCEPT
PDA = ({q0, q1, q2}, {a, b}, {z, a}, δ, q0, z, {q0}) where
δ(q0, a, z) = (q1, a, z)
34
δ(q1, a, a) = (q1, aa)
δ(q1, b, a) = (q2, a)
δ(q2, b, a) = (q2, Λ)
δ(q2, Λ, z) = (q0, Λ) Acceptance.
START
a
INPUT=?
Λ
PUSH DOWN b
S Yes
STACK EMPTY? REJECT
No
b POP UP
INPUT=?
a
INPUT=?
Λ
Λ
a, b No
STACK EMPTY?
Yes
ACCEPT
35
Example:
PDA = ({q0, q1, q2, q3}, {0, 1}, {0, z}, δ, q0, z, {q3})
Where
1. δ(q0, 0, z) = (q0, 0z)
2. δ(q0, 1, z) = (q2, Λ)
3. δ(q0, 0, 0) = (q0, 00)
4. δ(q0, 1, 0) = (q1, Λ)
5. δ(q1, 1, 0) = (q1, Λ)
6. δ(q1, 1, z) = (q2, Λ)
7. δ(q2, Λ, z) = (q3, Λ) Acceptance state.
Exercise:
A A0 | B1 | 1
B C1 | 1
C A0 | B0 | 0
Where = {0, 1} and N = {A, B, C}
3. Design a Push-Down Automaton to recognize the strings of the
language generated by the grammar G with the following set of
productions:
S aAb
A aAb
36
Ab
S aAb
A aAb
Ab
37
CHAPTER EIGHT
8.1 Introduction:
38
8.2 Definition:
NOTE:
A M.A is applicable to a string if and only if there’s at least one occurrence of
an antecedent in S.
8.3 Examples
1. Duplication of strings:
P1: x x x (x V)
39
P2: xy y x (x, y V)
P3: Λ
P4: Λ
P5: Λ
NOTE:
, are referred to as markers from the auxiliary alphabet (V’)
The last production P5 introduces a marker (symbol from an auxiliary
alphabet) which is used to mark the sub-string to be moved; production P 4
moves the marker to leave the final string. The first production duplicates a
marked character but introduces a second marker to mark the duplicate
character for subsequent movement to the end of the original string.
Let S = abc
P5 (S’) P1 P1 P1 P2
abc Λabc αabc aβaαbc aβabβbαc aβabβbcβcα
βaβbcβcα
P2 P2 P3 P3 P3 P4
abβacβbβcα abcβaβbβcα abcaβbβcα abcabβcα abcabcα
abcabc.
40
abc abc bac bca bca bca cba
cba
P5 P2 P5 P1
cba cba cba cba.
NOTE: (i) Stop normally
(ii) No production which can be applied; are the 2 ways of stopping.
P3 P3 P3
ABRACADABRA ABRACADABRA ABRACADABRA
P3 P4
41
ABRACADABRA …. ABRACADABRA ABRACADABRA.
Solution:
Algorithm:
i) Introduce a marker:
ii) Search for the substring: x x
iii) Remove the substring: ara
iv) Remove marker:
42
v) Terminate
Hence, we combine the above and write in order of priority:
P1: ara
P2: x x
P3:
P4:
NOTE:
ara can be changed with A where A is any substring.
E.g.
P4 P1 P2 P2 P1 P3
araratara araratara ratara ratara … ratara rat rat.
Exercise:
43
CHAPTER NINE
9.1 Introduction:
44
At a particular time t, what symbol is to be printed and whether the tape head
is to move to the right or left depends on the combination of the internal state
of the Turing Machine and the symbol in the square being read at that time.
This combination also determines the next internal state.
Example 1:
A TM to ‘empty’ a string i.e. convert a string to null:
1: q0 S1 Λ q0 R
2: q0 Λ Λ qH R
Example 2:
A TM to convert n to n+1, where n is written in decimal notation:
1: q0 S1 S1 q0 R
2: q0 Λ Λ q1 L
3: q1 0 1 qH R
4: q1 1 2 qH R
5: q1 2 3 qH R
45
6: q1 3 4 qH R
7: q1 4 5 qH R
8: q1 5 6 qH R
9: q1 6 7 qH R
10: q1 7 8 qH R
11: q1 8 9 qH R
12: q1 9 0 q1 L
13: q1 Λ 1 qH R
Exercise:
BIBLIOGRAPHY
46
APPENDIX: SAMPLE QUESTIONS
(b)
i) Define a deterministic semi-automaton, explaining fully the
parameters used in your definition and show how it differs from a
Non-deterministic semi-automaton.
ii) Using an appropriate example, show the possible
representations of a non-deterministic semi-automaton using a
transition table and a state graph.
47
δ(θ0, 0) = θ2
δ(θ1, 0) = θ3
δ(θ2, 0) = θ0
δ(θ3, 0) = θ1
δ(θ0, 1) = θ1
δ(θ1, 1) = θ0
δ(θ2, 1) = θ3
δ(θ3, 1) = θ2
i) 110011
ii) 111000
iii) 101010
iv) 001110
δ(S0, 0) = S2
δ(S1, 0) = S3
δ(S2, 0) = S0
δ(S3, 0) = S1
δ(S0, 1) = S1
δ(S1, 1) = S0
δ(S2, 1) = S3
δ(S3, 1) = S2
48
Which of the following strings are regular with regard to automaton A?
i) 110101
ii) 111010
iii) 101010
iv) 011011
i) a mapping
ii) a permutation
iii) an identity relation
i) (a + b)*aa(a + b)*
iii) (a +b)*bab
Inputs
δ 0 1
States
a c b
b d a
c a 49 d
d b c
a). Represent the above automaton as a directed graph.
X X0 | Y1 | 1
Y Z1 | 1
Z X0 | Y0 | 0
Where Σ = {0, 1} and N = {X, Y, Z}.
(b) Design a push down automaton to recognize the strings of the
language generated by the grammar G with the following set of
productions:
S ----- aAb
A ---- aAb
A ---- b
50
1
3
γ
0
γ 2
0
1 γ 4
(ii) What are the two ways in which a Markov Algorithm can be
terminated?
15. (a) Obtain a regular expression for the strings recognised by the
transition graphs below by generating a table of Derivatives to indicate
the vertices of G that can be reached from the initial vertex by following
51
a path corresponding to strings x , where = {0, 1}. Your
table should also indicate for all terminal strings, the equivalent lower
values of x and whether or not the string leads to a final state.
(b) Using the table of derivatives obtained in (a) above, obtain the
regular expression generated by the transition graph G.
1.
3
γ
0
γ 2
0
1 γ 4
2.
3
γ
0
γ 2
0
1 γ 4
1
52
16. Draw transition graphs to represent the following strings/expressions:
i) (a + b)*bab
ii) [10 + (11)0*1]*1
iii) (0 + 1)*00(0 + 1)*
17. (a) Define a Turing machine in form of quintuples clearly explaining the
symbols used in your definition.
(b) Apply the Turing machine quintuples given below to the decimal
number 9595 and explain the purpose of the TM.
1: q0 S1 S1 q0 R
2: q0 Λ Λ q1 L
3: q1 0 1 qH R
4: q1 1 2 qH R
5: q1 2 3 qH R
………………………
12: q1 9 0 q1 L
13: q1 Λ 1 qH R
NOTES
………………………………………………………………......................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
………………………………………………………………......................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
………………………………………………………………......................................
............................................................................................................................
53
............................................................................................................................
............................................................................................................................
………………………………………………………………......................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
………………………………………………………………......................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
………………………………………………………………......................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
………………………………………………………………......................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
………………………………………………………………......................................
............................................................................................................................
............................................................................................................................
............................................................................................................................
………………………………………………………………......................................
............................................................................................................................
54