dragon book exercise answers ch03 3.6 3.6

3
12/21/13 dragon-book-exercise-answers/ch03/3.6/3.6.md at master · fool2fish/dragon-book-exercise-answers · GitHub https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.6/3.6.md 1/3 fool2fish 8 months ago update 3.6.1 1 Contributor Sign up Sign in 105 57 Star Fork fool2fish / Dragon-book-exercise-answers LIC master branch: Dragon-book-exercise-answers / ch03 / 3.6 / 3.6.md File 188 lines (158 sloc) 3.094 KB 3.4 Figure 3-19 exercises to calculate the failure function KMP algorithm. Illustrated in the case of a known failure function, and how according to the known keywords b_1b_2 ... b_n construct a DFA n +1 states with the DFA can identify the language. * B_1b_2 ... b_n. Closer prove construct the DFA's time complexity is O (n). For illustration, a string abbaabb 3.4.3-3 example, failure function is: n: 1, 2, 3, 4, 5, 6, 7 f (n): 0, 0, 0, 1, 1, 2, 3 DFA was constructed as follows: The DFA constructed pseudo-code: for (i = 0; i <n; i + +) { move [s [i], c] = { if (c == b_1b_2 ... b_n [i]) { goto s [i +1] } Else { goto s [f (i)] } } } Obviously, in a known f (n) of the case, the time complexity of the algorithm is O (n) Open Edit Raw Blame History Delete 3.6 Exercise 3.6.1! Answer Explore Features Enterprise Blog Search or type a command This repository

Upload: yasir-alam

Post on 23-Oct-2015

1.448 views

Category:

Documents


9 download

DESCRIPTION

Compiler Design by Aho,Ulman,Lam and Sethi

TRANSCRIPT

Page 1: Dragon Book Exercise Answers Ch03 3.6 3.6

12/21/13 dragon-book-exercise-answers/ch03/3.6/3.6.md at master · fool2fish/dragon-book-exercise-answers · GitHub

https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.6/3.6.md 1/3

fool2fish 8 months ago update 3.6.1

1 Contributor

Sign up Sign in

105 57 Star Forkfool2fish / Dragon-book-exercise-answersPUBLIC

masterbranch: Dragon-book-exercise-answers / ch03 / 3.6 / 3.6.md

File 188 lines (158 sloc) 3.094 KB

3.4 Figure 3-19 exercises to calculate the failure function KMP algorithm. Illustrated in the case of a known failure function, and how

according to the known keywords b_1b_2 ... b_n construct a DFA n +1 states with the DFA can identify the language. * B_1b_2 ...

b_n. Closer prove construct the DFA's time complexity is O (n).

For illustration, a string abbaabb 3.4.3-3 example, failure function is:

n: 1, 2, 3, 4, 5, 6, 7

f (n): 0, 0, 0, 1, 1, 2, 3

DFA was constructed as follows:

The DFA constructed pseudo-code:

for (i = 0; i <n; i + +) {

move [s [i], c] = {

if (c == b_1b_2 ... b_n [i]) {

goto s [i +1]

} Else {

goto s [f (i)]

}

}

}

Obviously, in a known f (n) of the case, the time complexity of the algorithm is O (n)

Open Edit Raw Blame History Delete

3.6 Exercise

3.6.1!

Answer

Explore Features Enterprise BlogSearch or type a commandThis repository

Page 2: Dragon Book Exercise Answers Ch03 3.6 3.6

12/21/13 dragon-book-exercise-answers/ch03/3.6/3.6.md at master · fool2fish/dragon-book-exercise-answers · GitHub

https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.6/3.6.md 2/3

3.3.5 for the exercise of each language to design a DFA or NFA.

NFA shown in Figure 3-29 to identify all labeled aabb path. The NFA accepts aabb it?

(0)-a-> (1)-a-> (2)-b-> (2)-b-> ((3))

(0)-a-> (0)-a-> (0)-b-> (0)-b-> (0)

(0)-a-> (0)-a-> (1)-b-> (1)-b-> (1)

(0)-a-> (1)-a-> (1)-b-> (1)-b-> (1)

(0)-a-> (1)-a-> (2)-b-> (2)-b-> (2)

(0)-a-> (1)-a-> (2)-b-> (2)-ε-> (0)-b-> (0)

(0)-a-> (1)-a-> (2)-ε-> (0)-b-> (0)-b-> (0)

The NFA apparently accepted aabb

For the NFA Figure 3-30, repeat the exercise 3.6.3

In practice is given below of the NFA conversion table:

1. Exercise 3.6.3

2. Exercise 3.6.4

3. Figure 3-26

Table 1

Status a b ε

0 {0,1} {0} ∅

1 {1,2} {1} ∅

2 {2} {2,3} {0}

3 ∅ ∅ ∅

Table 2

Status a b ε

0 {1} ∅ {3}

1 ∅ {2} {0}

2 ∅ {3} {1}

3 {0} ∅ {2}

3.6.2

3.6.3

Answer

3.6.4

3.6.5

Answer

Page 3: Dragon Book Exercise Answers Ch03 3.6 3.6

12/21/13 dragon-book-exercise-answers/ch03/3.6/3.6.md at master · fool2fish/dragon-book-exercise-answers · GitHub

https://github.com/fool2fish/dragon-book-exercise-answers/blob/master/ch03/3.6/3.6.md 3/3

Table 3

Status a b ε

0 ∅ ∅ {1,2}

1 {2} ∅ ∅

2 {2} ∅ ∅

3 ∅ {4} ∅

4 ∅ {4} ∅

Status API Training Shop Blog About© 2013 GitHub , Inc.. Terms Privacy Security Contact