0% found this document useful (0 votes)
8 views

CS-352 - Spring 2024 - Lec5

Uploaded by

jouf00008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

CS-352 - Spring 2024 - Lec5

Uploaded by

jouf00008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Faculty of Information Technology

Spring 2024

Compiler Design
CS-352
Lecture (5)

1
Outline

• Conversion of an NFA to DFA


• Minimization of DFA

2
Outline

• Conversion of an NFA to DFA


• Minimization of DFA

3
Conversion of an NFA to DFA

4
Conversion of an NFA to DFA
(Cont.)
• Example 1: NFA without λ Transition

5
Conversion of an NFA to DFA
(Cont.)
• Example 1: NFA without λ Transition

Step 1 - Construct a transition table showing all reachable states for


every state for every input signal.

6
Conversion of an NFA to DFA
(Cont.)
• Example 1: NFA without λ Transition

Transition Table of NFA


q δ(q, 0) δ(q, 1)

0 {0, 1} 0

1 Ø 2

2 Ø Ø

7
Conversion of an NFA to DFA
(Cont.)
• Example 1: NFA without λ Transition

Transition from state q with input a Transition from state q with input b

Starts here q δ(q, 0) δ(q, 1)

0 {0, 1} 0

1 Ø 2

2 Ø Ø

Transition Table of NFA

8
Conversion of an NFA to DFA
(Cont.)
• Example 1: NFA without λ Transition

Transition Table of NFA

q δ(q, 0) δ(q, 1)
0 {0, 1} 0
1 Ø 2
2 Ø Ø

Step 2 - The set of states resulting from every transition function


constitutes a new state. Calculate all reachable states for every such
state for every input signal.

9
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
Starts with q δ(q, 0) δ(q, 1)
Initial state
0 {0, 1} 0

Transition Table of NFA

q δ(q, 0) δ(q, 1)
0 {0, 1} 0
1 Ø 2
2 Ø Ø

10
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

0 {0, 1} 0

{0, 1}

Transition Table of NFA

q δ(q, 0) δ(q, 1)
0 {0, 1} 0
1 Ø 2
2 Ø Ø

11
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

0 {0, 1} 0

{0, 1} {0, 1} {0, 2}

{0, 2}

Transition Table of NFA

q δ(q, 0) δ(q, 1)
0 {0, 1} 0
1 Ø 2
2 Ø Ø

12
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

0 {0, 1} 0
Stops here as there are no
more reachable states {0, 1} {0, 1} {0, 2}

{0, 2} {0, 1} 0

Transition Table of NFA

q δ(q, 0) δ(q, 1)
0 {0, 1} 0
1 Ø 2
2 Ø Ø

13
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

0 {0, 1} 0

{0, 1} {0, 1} {0, 2}

{0, 2} {0, 1} 0

Resulting DFA after applying Subset


Construction to NFA

14
Conversion of an NFA to DFA
(Cont.)
• Example 2: NFA without λ Transition

15
Conversion of an NFA to DFA
(Cont.)
• Example 1: NFA without λ Transition

Transition Table of NFA


q δ(q, 0) δ(q, 1)

q0 {q0, q1} q1

q1 Ø {q0, q1}

16
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
Starts with q δ(q, 0) δ(q, 1)
Initial state
q0 {q0, q1} q1

{q0, q1}

q1

Transition Table of NFA

q δ(q, 0) δ(q, 1)
q0 {q0, q1} q1
q1 Ø {q0, q1}

17
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

q0 {q0, q1} q1

{q0, q1} {q0, q1} {q0, q1}

q1

Transition Table of NFA

q δ(q, 0) δ(q, 1)
q0 {q0, q1} q1
q1 Ø {q0, q1}

18
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

q0 {q0, q1} q1

{q0, q1} {q0, q1} {q0, q1}

q1 Ø {q0, q1}

Ø
Transition Table of NFA

q δ(q, 0) δ(q, 1)
q0 {q0, q1} q1
q1 Ø {q0, q1}

19
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

q0 {q0, q1} q1

{q0, q1} {q0, q1} {q0, q1}

q1 Ø {q0, q1}

Ø Ø Ø
Transition Table of NFA

q δ(q, 0) δ(q, 1)
q0 {q0, q1} q1
q1 Ø {q0, q1}

20
Conversion of an NFA to DFA
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

q0 {q0, q1} q1

{q0, q1} {q0, q1} {q0, q1}


Stops here as there are no
more reachable states q1 Ø {q0, q1}

Ø Ø Ø

Resulting DFA after applying Subset


Construction to NFA

21
Outline

• Conversion of an NFA to DFA


• Minimization of DFA

22
Minimization of DFA – Example 1
Subset Construction Table

q δ(q, 0) δ(q, 1)

0 {0, 1} 0

{0, 1} {0, 1} {0, 2}

{0, 2} {0, 1} 0

23
Minimization of DFA – Example 1
(Cont.)
Subset Construction Table
q δ(q, 0) δ(q, 1)

0 {0, 1} 0

{0, 1} {0, 1} {0, 2}

{0, 2} {0, 1} 0

Can be merged, But 02 is a Final state where 0


0, 02
Have the Same Transitions  is not

Therefore, Can not minimized DFA

24
Minimization of DFA – Example 2

Alphabet
NFA State DFA State
a b
{0, 1, 2, 4, 7} A B C

{1, 2, 3, 4, 6, 7, 8} B B D
Subset Construction Table
{1, 2, 4, 5, 6, 7} C B C

{1, 2, 4, 5, 6, 7, 9} D B E

{1, 2, 4, 5, 6, 7, 10} E B C
25
Minimization of DFA – Example 2
(Cont.)
Subset Construction Table
q δ(q, a) δ(q, b)
A B C
B B D
C B C
D B E
E B C

Can be merged, But E is a Final state where A


A, C, E
Have the Same Transitions  and C are not

26
Minimization of DFA – Example 2
(Cont.)
Subset Construction Table
q δ(q, a) δ(q, b)
A B C
B B D
C B C Merge A and C
D B E
E B C

q δ(q, a) δ(q, b)
A B CA
B B D
C B C
D B E
E B CA

27
Minimization of DFA – Example 2
(Cont.)
q δ(q, a) δ(q, b)
A B A
Subset Construction Table B B D
D B E
E B A

Minimizing DFA

28

You might also like