Solutions of Examples for Practice...Solutions of Examples for Practice Example 2.3.38 Solution :...

12

Transcript of Solutions of Examples for Practice...Solutions of Examples for Practice Example 2.3.38 Solution :...

Solutions of Examples for Practice

Example 2.3.38

Solution : The required DFA can be drawn as follows.

Processing of 1001011

q 0 |� 1001011

1q 1 |� 001011

10q 2 |� 01011

100 q 4 |� 1011

1001q 4 |� 011

10010q 3 |� 11

100101q 2 |� 1

1001011q 0 |� Accept.

Example 2.3.39

Solution :

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM

(2 - 1)

2 Finite Automata

q2q1

q3

q0 q4

0

1

1

0

0 1

0

01

1

q3q0 q1 q2

q4

ab

b a a

Example 2.8.10

Solution :� (p, 0) = {p, q} = [p, q]

� (p, 1) = {p} = [p]

� (q, 0) = {r, s} = [r, s]

� (q, 1) = {t} = [t]

� (r, 0) = {p, r} = [p, r]

� (r, 1) = {t} = [t]

� (s, 0) = �

� (s, 1) = �

� (t, 0) = �

� (t, 1) = �

Now we will apply � transitions on newly generated states [p, q], [r, s], [p, r]

� ([p, q], 0) = {p, q, r, s} = [p, q, r, s] state

� ([p, q], 1) = {p, t} = [p, t] state

� ([r, s], 0) = [p, r]

� ([r, s], 1) = [t]

� ([p, r], 0) = {p, q, r} = [p, q, r] state

� ([p, r], 1) = {p, t} = [p, t]

� ([p, q, r, s], 0) = [p, q, r, s]

� ([p, q, r, s], 1) = [p, t]

� ([p, t], 0) = [p, q]

� ([p, t], 1) = [p]

� ([p, q, r], 0) = {p, q, r, s} = [p, q, r, s]

� ([p, q, r], 1) = {p, t} = [p, t]

As no new state is getting generated, we will stop applying � transitions.

Formal Languages and Automata Theory 2 - 2 Finite Automate

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM

The transition table is as follows -

Example 2.9.9

Solution : The table for first transition diagram will be as shown in the Fig. 2.1.

The cross is put in (A, B) because A is a final state and B is a non final

state. Hence given DFA can not be minimized. Similarly table for second

transition diagram will be

This indicates that states C and D are equivalent. Hence minimized DFA

will be

Thus the language accepted by both the DFA is same.

Formal Languages and Automata Theory 2 - 3 Finite Automate

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM

i/p

State

[p]

[q]

[r]

[s]

0 1

[p,q]

� �r,s

[p,r]

[p]

[t]

[t]

� �

[t] � �

[p,q] [p,q,r,s] [p,t]

[p,q,r,s] [p,q,r,s] [p,t]

[p,t] [p,q] [p]

[p,q,r] [p,q,r,s] [p,t]

[p,r] [p,q,r] [p,t]

[p,r] [t]� �r,s

A

B

Fig. 2.1

C E

0

1

0

1

Fig. 2.2

Example 2.12.9

Solution : Mealy machine :

Moore machine :

���

Formal Languages and Automata Theory 2 - 4 Finite Automate

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM

q /00 q /11 q /22 q /13

q /20

0

02

1

0 1 1

2

1

0

0

2

2

2

Fig. 2.4

1/1q0 q1 q2 q3

2/2 0/1

1/10/0

1/1

2/20/0

2/2

1/1

2/20/0

Fig. 2.3

Solutions of Examples for Practice

Example 3.3.37

Solution : The situation can be

The r.e. = � �� �a a b c a b c b� � � �

Example 3.7.10

Solution : Consider, L = {w � {a, b}|w = wR}

Consider w = abab

wR = baba

Hence L = wwR

The string z can be denoted by

z = uvw. where |z| � n and |uv| � n |v| � 1.

We assume z =

We can split z = uvw as

z =

|u| = n – 1

|v| = 1

i.e. |uv| = |u| + |v|

= n – 1 + 1

= n

Now according to pumping lemma,

when z = uviw �L then language is said to be regular. We will assume that L = wwR is

regular. And we will find uviw.

� z = uviw = ababbaba

Assume i = 0 i.e. there will be

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM

(3 - 1)

3 Regular Languages

ab

n

ab

n

ba

n

ba

n

ba

v

ab

u

ba

w

ba

a a + b + c a + b + c b

z = uv0w = uw

Then the string becomes

z = aabbaba

wwR

i.e. z = aabbaba L …(1)

Now consider i = 2 then

z = uv2w

= abbabbaba

wwR

i.e. z = abbabbaba L …(2)

From equations (1) and (2) we can state that

z = uviw L

Hence our assumption that L = wwR being regular is wrong. Hence we can prove that

z = wwR is not regular.

���

Formal Languages and Automata Theory 3 - 2 Regular Languages

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM

Solution of Example for Practice

Example 5.1.2

Solution : The production rules for valid expressions are

E � E – E

E � E / E

E � (E)

E � LD

L � a | b

D � 0D | 1D | �

Left most derivation for (a11 b0) / (b00 a01)� �

E

E/E

(E)/E

(E–E)/E

(LD–E)/E

(aD–E)/E

(a1D E) / E�

(a11D E) / E�

(a11 E) / E�

(a11 LD) / E�

(a11 bD) / E�

(a11 b0D) / E�

(a11 b0) / E�

(a11 b0) / (E)�

(a11 b0) / (E E)� �

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM(5 - 1)

5 Context Free Grammar and Languages

E

E E

( E ) ( E )

L D L D L D L D

a b1 D 0 D b 0 D a 0 D

1 D 0 D 1 D�

� � �

E E E E

/

– –

Fig. 5.1 Parse tree

(a11 b0) / (LD E)� �

(a11 b0) / (bD E)� �

(a11 b0) / (b0D E)� �

(a11 b0) / (b00D E)� �

(a11 b0) / (b00 E)� �

(a11 b0) / (b00 LD)� �

(a11 b0) / (b00 aD)� �

(a11 b0) / (b00 a0D)� �

(a11 b0) / (b00 a01)� �

Right most derivation

E

E/E

E/(E)

E/(E – E)

E/(E – LD)

E/(E – L0D)

E/(E – L01D)

E/(E – L01)

E/(E – a01)

E / (LD a01)�

E / (L0D a01)�

E / (L00D a01)�

E / (L00 a01)�

E / (b00 a01)�

(E) / (b00 a01)�

(E E) / (b00 a01)� �

(E LD) / (b00 a01)� �

(E L0) / (b00 a01)� �

(E b0) / (b00 a01)� �

(LD b0) / (b00 a01)� �

(L1D b0) / (b00 a01)� �

(L11D b0) / (b00 a01)� �

(L11 b0) / (b00 a01)� �

(a11 b0) / (b00 a01)� �

���

Formal Languages and Automata Theory 5 - 2 Context Free Grammar and Languages

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM

Solution of Example for Practice

Example 7.6.21

Solution : This turing machine is for performing copy operation. We will apply following

logic.

� 1 1 1 � Read 1 convert it to A and move at the end.

� A 1 1 � Move beyond � and convert two �'s to 1

� A 1 1 � 1 1 Move left upto A

� A 1 1 � 1 1 Move right by 1 position

� A 1 1 � 1 1 Convert 1 to A and move upto the end

� A A 1 � 1 1 � Convert two �s to two 1s.

� A A 1 � 1 1 1 1 � Move left to A

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM(7 - 1)

7 Turing Machines and Undecidability

Initially� 1 �1 1 �

Input tape

Fig. 7.1

� A A 1 � 1 1 1 1 � Move right by one position

� A A 1 � 1 1 1 1 � Convert 1 to A

� A A A � 1 1 1 1 � Copy two 1s at the end

� A A A � 1 1 1 1 1 1 � Go back, convert As to �s.

� � � � � 1 1 1 1 1 1 � Halt

���

Formal Languages and Automata Theory 7 - 2 Turing Machines and Undecidability

TECHNICAL PUBLICATIONS - An up thrust for knowledgeTM

q0 q1(1, A, R)

q2( , , R)� �

q3( , 1, R)�

q4( , 1, L)�

(1, 1, R) (1, 1, L)

q5

q7

( , , L)� �

(A, , L)�

(A, , L)�

q6

HALT

(A, A, R) (1, 1, L)

(1, 1, L)

Fig. 7.2