1 of 125

Prof. Dixita B. Kagathara

2160704

Theory of Computation

Unit-2

Regular Languages & Finite Automata

dixita.kagathara@darshan.ac.in

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

1

2 of 125

Topics to be covered

  • Regular expressions & Regular languages
  • Finite Automata
  • Union, Intersection and Complement of Regular Languages
  • Non-Deterministic Finite Automata
  • Conversion from NFA to FA
  • ^ - Non-Deterministic Finite Automata
  • Conversion of NFA-^ to FA
  • Kleene’s Theorem Part – I
  • Finite Automata with Output (Moore machine, Mealy machine)
  • Minimization of FA
  • Moore machine & Mealy machine
  • Pumping Lemma – Regular and Non Regular Languages

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

2

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

2

3 of 125

Regular Expression

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

3

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

3

4 of 125

Regular expression

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

4

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

4

5 of 125

Regular expression

L = Zero or More Occurrences of a =

*

a*

a

aaa

aa

aaaa

aaaaa…..

Infinite …..

𝜖

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

5

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

5

6 of 125

Regular expression

L = One or More Occurrences of a =

+

a+

a

aaa

aa

aaaa

aaaaa…..

Infinite …..

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

6

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

6

7 of 125

Precedence and associativity of operators

Operator

Precedence

Associative

Kleene *

1

left

Concatenation

2

left

Union |

3

left

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

7

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

7

8 of 125

Regular expression examples

  •  

 

 

 

 

 

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

8

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

8

9 of 125

Regular expression examples

  1. 0 or more occurrence of either a or b or both

  • 1 or more occurrence of either a or b or both

  • Binary no. ends with 0

  • Binary no. ends with 1

  • Binary no. starts and ends with 1

  • String starts and ends with same character

 

 

 

 

 

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

9

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

9

10 of 125

Regular expression examples

  •  

 

 

 

 

 

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

10

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

10

11 of 125

Regular expression examples

  •  

 

 

 

 

 

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

11

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

11

12 of 125

Regular expression examples

  •  

 

 

 

 

 

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

12

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

12

13 of 125

Regular expression examples

  1. All string begins or ends with 00 or 11

  • Language of all string containing both 11 and 00 as substring

  • String ending with 1 and not contain 00

  • Language of C identifier

 

 

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

13

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

13

14 of 125

Finite Automata

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

14

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

14

15 of 125

Finite Automata

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

15

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

15

16 of 125

Example: Finite Automata

  •  

δ

Input

State

 

 

 

1

0

1

0

0

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

16

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

16

17 of 125

Applications of FA

  • Lexical analysis phase of a compiler.
  • Design of digital circuit.
  • String matching.
  • Communication Protocol for information exchange.

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

17

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

17

18 of 125

FA Examples

  • The string with next to last symbol as 0.

 

 

 

 

0

1

0

1

0

1

0

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

18

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

18

19 of 125

FA Examples

  • The strings ending with 10.

 

 

 

1

0

1

0

0

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

19

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

19

20 of 125

FA Examples

  • The string with number of 0’s and number of 1’s are odd

odd 0�even 1

even 1�even 0

odd 1�even 0

odd 0�odd 1

0

0

0

0

1

1

1

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

20

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

20

21 of 125

FA Examples

  • The string ending in 10 or 11

A

B

C

D

1

1

0

1

0

0

0

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

21

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

21

22 of 125

FA Examples

  • The string corresponding to Regular expression {00}*{11}*

B

C

A

E

1

0

D

1

1

1

0

0

0

0,1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

22

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

22

23 of 125

FA Examples

  • (a+b)*baaa

A

C

E

B

a

D

a

a

a

a

b

b

b

b

b

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

23

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

23

24 of 125

 

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

24

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

24

25 of 125

 

  •  

 

 

 

 

c

b

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

25

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

25

26 of 125

 

  •  

 

 

 

Y

X

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

26

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

26

27 of 125

Acceptance by FA

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

27

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

27

28 of 125

Union, Intersection & Complement of Languages

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

28

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

28

29 of 125

Example

  •  

 

 

 

0

1

1

0,1

0

 

 

 

0

1

1

0

0

1

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

29

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

29

30 of 125

 

  •  

 

 

 

 

 

 

 

 

 

 

 

 

 

0

1

BQ

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

30

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

30

31 of 125

 

 

 

 

 

 

 

 

 

 

 

 

0

1

0

1

0

1

0

 

 

 

 

 

 

 

 

 

 

1

BQ

CQ

AR

CR

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

31

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

31

32 of 125

 

 

 

 

 

 

 

 

 

 

 

 

0

1

 

 

 

 

 

 

0

1

0

1

0

1

0

1

0

1

BQ

CQ

AR

CR

CP

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

32

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

32

33 of 125

Removing Unconnected States

 

 

 

 

 

 

 

 

 

0

1

0

1

0

1

0

1

0

1

0

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

33

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

33

34 of 125

 

 

 

 

 

 

 

0

1

0

1

0

1

0

1

0

1

0

1

 

 

 

As per theorem stated earlier, the states which consists A or B or R will be Accepting states in the resultant FA.

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

34

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

34

35 of 125

 

 

 

 

 

 

 

0

1

0

1

0

1

0

1

0

1

0

1

 

 

 

Therefore, as per theorem stated earlier, the states which consists (A and R) and (B and R) will be Accepting states in the resultant FA.

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

35

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

35

36 of 125

 

 

 

 

 

 

 

0

1

0

1

0

1

0

1

0

1

0

1

 

 

 

Therefore, as per theorem stated earlier, the states which consists A or B but should not contain R with them will be Accepting states in the resultant FA.

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

36

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

36

37 of 125

Exercise

  •  

 

 

 

1

0

0

0,1

1

 

 

 

1

0

0

1

1

0

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

37

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

37

38 of 125

Nondeterministic Finite Automata (NFA)

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

38

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

38

39 of 125

 

  •  

δ

Input

State

 

 

 

1

0

1

 

 

1

1

0

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

39

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

39

40 of 125

 

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

40

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

40

41 of 125

 

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

41

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

41

42 of 125

Acceptance by NFA

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

42

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

42

43 of 125

 

  •  

δ

Input

State

 

 

 

 

1

0, 1

0, 1

0, 1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

43

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

43

44 of 125

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

44

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

44

45 of 125

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

45

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

45

46 of 125

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

46

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

46

47 of 125

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

47

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

47

48 of 125

 

 

 

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

48

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

48

49 of 125

NFA to FA using subset construction method

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

49

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

49

50 of 125

Example 1: Conversion from NFA to FA

1

3

4

2

b

a

a

b

b

a

1

{2,3}

{4}

2

{4}

3

{4}

{3}

4

NFA

Transition Table

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

50

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

50

51 of 125

Example 1: Conversion from NFA to FA

 

 

 

 

 

 

 

 

1

3,4

b

2,3

4

b

a

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

51

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

51

52 of 125

Example 1: Conversion from NFA to FA

 

 

 

 

 

 

1

3

3,4

b

2,3

4

b

b

b

a

a

a

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

52

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

52

53 of 125

Example 2: Conversion from NFA to FA

δ

Input

State

 

 

 

 

1

0, 1

0, 1

0, 1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

53

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

53

54 of 125

Example 2: Conversion from NFA to FA

 

0

 

 

 

 

 

 

 

1

 

0

 

1

 

0

 

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

54

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

54

55 of 125

Example 2: Conversion from NFA to FA

 

0

 

 

1

 

0

 

1

 

0

 

1

 

0

1

 

 

 

 

0

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

55

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

55

56 of 125

Example 2: Conversion from NFA to FA

 

0

 

 

1

 

0

 

1

 

0

 

1

 

0

1

 

 

 

 

0

1

0

1

0

1

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

56

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

56

57 of 125

Example 2: Conversion from NFA to FA

 

0

 

1

 

0

 

1

 

0

 

1

0

1

 

 

 

 

0

1

0

1

0

1

0

1

  • As now no new states are obtained, the process stops and we need to define the accepting states.
  • To define accepting states, the states which contain the accepting states of NFA will be accepting states of final FA.

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

57

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

57

58 of 125

 

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

58

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

58

59 of 125

 

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

59

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

59

60 of 125

 

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

60

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

60

61 of 125

 

 

 

 

 

 

 

 

 

^

^

^

^

^

0

0

0

0

0

1

1

1

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

61

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

61

62 of 125

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

^

^

^

^

^

0

0

0

0

0

1

1

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

62

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

62

63 of 125

 

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

63

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

63

64 of 125

 

 

 

 

 

 

 

 

 

 

 

 

^

^

^

^

^

0

0

0

0

0

1

1

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

64

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

64

65 of 125

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

^

^

^

^

^

0

0

0

0

0

1

1

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

65

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

65

66 of 125

 

 

 

 

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

66

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

66

67 of 125

NFA-^ to FA

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

67

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

67

68 of 125

 

 

NFA

FA

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

68

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

68

69 of 125

 

A

{B}

{A}

B

{D}

{C}

C

{B}

D

{D}

A

B

D

C

^

0

^

0

0

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

69

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

69

70 of 125

Conversion from NFA- ^ to FA

Step 1: To convert NFA - ^ to NFA

 

 

A

D

0

B

 

 

 

C

0

0

0

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

70

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

70

71 of 125

 

A

D

0

B

 

C

0

0

0

 

 

 

 

 

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

71

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

71

72 of 125

Conversion from NFA- ^ to FA

 

 

 

 

 

 

 

 

A

D

0

B

C

0

0

0

0

0

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

72

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

72

73 of 125

Conversion from NFA- ^ to FA

 

 

 

 

 

 

A

D

0

B

C

0

0

0

0

0

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

73

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

73

74 of 125

Conversion from NFA- ^ to FA

 

 

 

 

 

 

 

 

A

D

0

B

C

0

0

0

0

0

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

74

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

74

75 of 125

 

 

 

 

 

 

 

A

D

0

B

C

0

0

0

0

0

1

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

75

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

75

76 of 125

Conversion from NFA- ^ to FA

 

 

 

 

 

 

 

 

A

D

0

B

C

0

0

0

0

0

1

1

0

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

76

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

76

77 of 125

Conversion from NFA- ^ to FA

 

 

 

 

 

 

A

D

0

B

C

0

0

0

0

0

1

1

0

Resulting NFA

Accepting State

 

=

{

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

77

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

77

78 of 125

Conversion from NFA- ^ to FA

Step 2: To convert NFA to FA

 

 

 

 

 

 

 

 

 

 

A

CD

ABCD

0

BD

0

1

0

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

78

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

78

79 of 125

Conversion from NFA- ^ to FA

A

CD

0

D

ABCD

0

0

0

0

1

 

 

 

 

 

 

BD

1

FA

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

79

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

79

80 of 125

Kleene’s Theorem Part-1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

80

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

80

81 of 125

Kleene’s Theorem Part-1

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

81

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

81

82 of 125

Kleene’s Theorem Part-1

  •  

Ø

{^}

a

{a}

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

82

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

82

83 of 125

Kleene’s Theorem Part-1

  •  

 

 

 

 

 

 

 

^

^

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

83

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

83

84 of 125

Kleene’s Theorem Part-1

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

84

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

84

85 of 125

Kleene’s Theorem Part-1

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

85

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

85

86 of 125

Kleene’s Theorem Part-1

  •  

 

 

 

 

 

 

^

^

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

86

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

86

87 of 125

Kleene’s Theorem Part-1

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

87

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

87

88 of 125

Kleene’s Theorem Part-1

  •  

 

 

 

 

^

^

^

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

88

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

88

89 of 125

Kleene’s Theorem Part-1

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

89

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

89

90 of 125

Kleene’s Theorem Part-1

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

90

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

90

91 of 125

Application of Kleene’s Theorem

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

91

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

91

92 of 125

Regular expression to NFA-^

  •  

a

a

^

b

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

92

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

92

93 of 125

Regular expression to NFA-^

  •  

a

a

^

b

^

^

^

^

^

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

93

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

93

94 of 125

Regular expression to NFA-^

  •  

0

0

^

1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

94

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

94

95 of 125

Regular expression to NFA-^

  •  

0

0

^

1

^

^

0

0

^

1

^

^

^

^

^

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

95

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

95

96 of 125

Regular expression to NFA-^

  •  

1

0

^

^

^

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

96

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

96

97 of 125

Regular expression to NFA-^

  •  

1

0

^

^

^

^

0

0

^

1

^

^

^

^

^

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

97

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

97

98 of 125

Exercise (RE to NFA-^)

  1. 00
  2. 00+1
  3. (00+1)*
  4. (0+1)*
  5. (111)*
  6. (10+01)*
  7. (0+1)*(11+00)*11
  8. (10+110)*(0+1)*1
  9. (00+1)*(10)*
  10. (a+b)(a+b)*
  11. (aab)*b*(a+b)*

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

98

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

98

99 of 125

Finite Automata with Output

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

99

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

99

100 of 125

Finite automata with output

  • Finite automata has limited capability of either accepting a string or rejecting a string. Acceptance of string was based on the reachability of a machine from starting state to final state.
  • Finite automata with output do not have a final state.
  • Machine generates output on every input.
  • There are two types of automata with outputs:
  • Moore machine
  • Mealy machine

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

100

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

100

101 of 125

Moore machine & Mealy Machine

FA with Output

Mealy Machine

 

Moore Machine

 

 

 

 

 

X,1

Y,0

b

b

X

Y

b|0

b|0

a

a

a|1

a|1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

101

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

101

102 of 125

Moore Machine

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

102

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

102

103 of 125

Example: Moore Machine

  • Design a moore machine for the 1’s compliment of binary number.

A,0

B,1

0

1

1

0

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

103

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

103

104 of 125

Example: Moore Machine

  • Design a moore machine to count occurrence of “ab” as substring.

 

 

 

a

b

a

b

b

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

104

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

104

105 of 125

Example: Moore Machine

  • Construct a moore machine that takes set of all strings over {0, 1} and produces ‘A’ if i/p ends witg ‘10’ , produces ‘B’ if i/p ends with ’11’ otherwise produces ‘C’.

 

 

 

1

0

0

1

1

0

1

 

0

10🡪A

11🡪B

Otherwise 🡪C

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

105

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

105

106 of 125

Example: Moore Machine

  • Construct a moore machine that takes binary number as an i/p and produces residue modulo ‘3’ as an output.

Input={0,1}

∆={0, 1, 2}

A,0

B,1

1

1

0

1

C,2

0

0

 

0

1

A

A

B

0

B

C

A

1

C

B

C

2

Transition Table

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

106

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

106

107 of 125

Mealy Machine

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

107

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

107

108 of 125

Example: Mealy Machine

  • Design a mealy machine for the 1’s compliment of binary number

A

1/0

0/1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

108

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

108

109 of 125

Example: Mealy Machine

  • Design a mealy machine for regular expression (0+1)*(00+11).

q1

q2

q3

1|x

0|x

1|x

0|x

0|y

1|y

00🡪y

11🡪y

Otherwise 🡪x

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

109

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

109

110 of 125

Moore to Mealy Machine Conversion

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

110

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

110

111 of 125

Conversion of Moore into Mealy Machine

 

 

 

 

Start

a/1

a/1

a/0

b/0

b/1

b/0

 

 

 

 

Start

a

a

a,b

a

b

b

b

0

0

1

1

Moore machine

Mealy machine

a/1,b/1

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

111

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

111

112 of 125

Mealy to Moore Machine Conversion

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

112

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

112

113 of 125

Conversion of Mealy to Moore machine

 

0|0

1|1

 

0|1

1|0

 

0

1

 

0

1

 

1

0

Mealy machine

Moore machine

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

113

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

113

114 of 125

Exercise: Mealy machine to Moore machine

q1

q2

q3

1|x

0|x

1|x

0|x

0|y

1|y

 

b|0

a|0

 

a|1

b|1

GTU- May 2016, 7 Marks

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

114

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

114

115 of 125

Minimization of FA

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

115

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

115

116 of 125

Example: Minimize FA

2

 

 

3

X

X

 

4

 

 

X

 

5

X

X

 

X

 

6

X

X

X

X

X

 

7

X

X

 

X

 

X

 

1

2

3

4

5

6

Final state is {6}

And, Non-Final state is {1,2,3,4,5,7}

(6, 1), (6,2), (6, 3), (6, 4), (6, 5), (6, 7) are distinguish pairs.

Consider pair (1,2)

δ(1,a)=2 δ(1,b)=3

δ(2,a)=4 δ(2,b)=5

Consider pair (1,3)

δ(1,a)=2 δ(1,b)=3

δ(3,a)=6 δ(3,b)=7

pair (2,6) is distinguish, so (1,3) is distinguished pair.

Consider pair (1,4)

δ(1,a)=2 δ(1,b)=3

δ(4,a)=4 δ(4,b)=5

 

 

 

 

 

 

7

a

b

b

b

b

b

b

b

a

a

a

a

a

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

116

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

116

117 of 125

Example: Minimize FA

Consider pair (1,5)

δ(1,a)=2 δ(1,b)=3

δ(5,a)=6 δ(5,b)=7

pair (2,6) is distinguish, so (1,5) is distinguished pair.

Consider pair (1,7)

δ(1,a)=2 δ(1,b)=3

δ(7,a)=6 δ(7,b)=7

pair (2,6) is distinguish, so (1, 7) is distinguished pair.

Consider pair (2,3)

δ(2,a)=4 δ(2,b)=5

δ(3,a)=6 δ(3,b)=7

pair (4,6) is distinguish, so (2, 3) distinguished pair.

Consider pair (2,4)

δ(2,a)=4 δ(2,b)=5

δ(4,a)=4 δ(4,b)=5

2

 

 

3

X

X

 

4

 

 

X

 

5

X

X

 

X

 

6

X

X

X

X

X

 

7

X

X

 

X

 

X

 

1

2

3

4

5

6

 

 

 

 

 

 

7

a

b

b

b

b

b

b

b

a

a

a

a

a

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

117

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

117

118 of 125

Example: Minimize FA

Consider pair (2,5)

δ(2,a)=4 δ(2,b)=5

δ(5,a)=6 δ(5,b)=7

pair (4,6) is distinguish, so (2,5) is distinguished pair.

Consider pair (2,7)

δ(2,a)=4 δ(2,b)=5

δ(7,a)=6 δ(7,b)=7

pair (4,6) is distinguish, so (2,7) is distinguished pair.

Consider pair (3,4)

δ(3,a)=6 δ(3,b)=7

δ(4,a)=4 δ(4,b)=5

pair (6,4) is distinguish, so (3,4) is distinguish pair.

Consider pair (3,5)

δ(3,a)=6 δ(3,b)=7

δ(5,a)=6 δ(5,b)=7

2

 

 

3

X

X

 

4

 

 

X

 

5

X

X

 

X

 

6

X

X

X

X

X

 

7

X

X

 

X

 

X

 

1

2

3

4

5

6

 

 

 

 

 

 

7

a

b

b

b

b

b

b

b

a

a

a

a

a

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

118

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

118

119 of 125

Example: Minimize FA

Consider pair (3,7)

δ(3,a)=6 δ(3,b)=7

δ(7,a)=6 δ(7,b)=7

Consider pair (4,5)

δ(4,a)=4 δ(4,b)=5

δ(5,a)=6 δ(5,b)=7

pair (6,4) is distinguish, so (4,5) is distinguish.

Consider pair (4,7)

δ(4,a)=4 δ(4,b)=5

δ(7,a)=6 δ(7,b)=7

pair (4,6) is distinguish, so (4,7) is distinguish.

Consider pair (5,7)

δ(5,a)=6 δ(5,b)=7

δ(7,a)=6 δ(7,b)=7

2

 

 

3

X

X

 

4

 

 

X

 

5

X

X

 

X

 

6

X

X

X

X

X

 

7

X

X

 

X

 

X

 

1

2

3

4

5

6

 

 

 

 

 

 

7

a

b

b

b

b

b

b

b

a

a

a

a

a

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

119

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

119

120 of 125

Example: Minimize FA

2

 

 

3

X

X

 

4

 

 

X

 

5

X

X

 

X

 

6

X

X

X

X

X

 

7

X

X

 

X

 

X

 

1

2

3

4

5

6

 

 

 

b

a

a

b

b

a

 

1=2

1=4

2=4

1=2=4

3=5

3=7

5=7

3=5=7

 

 

 

 

 

 

7

a

b

b

b

b

b

b

b

a

a

a

a

a

a

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

120

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

120

121 of 125

Pumping lemma

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

121

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

121

122 of 125

Define pumping lemma and its application.

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

122

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

122

123 of 125

Use the pumping lemma to show that following language is not regular: L = {ww|w ϵ {0,1}*}

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

123

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

123

124 of 125

Use the pumping lemma to show that following language is not regular: L = {ww|w ϵ {0,1}*}

  •  

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

124

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

124

125 of 125

End of Unit - 2

Unit – 2 : Regular languages & FA

Darshan Institute of Engineering & Technology

125

Theory of Computation (2160704)

Darshan Institute of Engineering & Technology

125