Regular Language computer science, Lecture notes of Computer Science

theory computer science lecture notes

Typology: Lecture notes

2017/2018

Uploaded on 11/18/2018

tuanzati
tuanzati 🇲🇾

3 documents

1 / 162

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
BCS 2143 Theory of
Computer Science
Part I: Automata and Languages
Topic 2: Regular Languages
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Regular Language computer science and more Lecture notes Computer Science in PDF only on Docsity!

BCS 2143 Theory of

Computer Science

Part I: Automata and Languages

Topic 2: Regular Languages

Finite Automata

Consider a board-game

Pieces are set up on a playing board. Dice are thrown, and a number is generated on random. Depending on number, the pieces on the board must be rearranged in a fashion completely specified by the rules. The child has no options about changing the board. Everything is determined by the dice.

Computer

A child has a simple computer (input device, processing unit, memory, output device) and wished to calculate the sum of 3 plus 4. The child writes a program, which is a sequence of instructions that are fed into the machine one at a time. Each instruction is executed as soon as it is read, and then the next instruction is read. If all goes well, the machine outputs the number 7 and

terminates execution.

Computer is also deterministic : the resultant state is completely determined by the prior state and the input instruction.

Game vs. Computer

 Difference:

 (^) The input of Game (the number generated by rolling dice) is depended on whether anyone has won the game yet. But the input of the computer program is the number of instruction which is predetermined before running the program.

Now we will consider the input of both the game and computer as strings of alphabet instead of the number generated randomly by the dice or the command instruction of the program.

State Diagram

CLOSED OPEN

FRONT

NEITHER

FRONT

REAR

BOTH

BOTH

REAR

NEITHER

front

pad

rear

pad

automatic door

State Transition Table

INPUT SIGNAL NEITHER FRONT REAR BOTH

STATE

CLOSED CLOSED OPEN CLOSED CLOSED OPEN CLOSED OPEN OPEN OPEN

Definition

 (^) A finite automaton is a collection of 3 things:

 (^) A finite set of states, one of which is designated as the initial state, called the start state , and some (maybe none) of which are designated as final states.  (^) An alphabet of possible input letters.  (^) A finite set of transitions that tell for each state and for each letter of the input alphabet which state to go to next.

State Diagram

 (^) start state = q 1  (^) final state = q 2  (^) transitions = each arrows  (^) alphabet = each labels  (^) When this automaton receives an input string such as 1101, it processes that string and produce output (Accept or Reject).

q 1

0

1

(^10)

0,

q 2 q 3

Formal Definition

 A finite automaton is a 5-tuple

(Q,,,q 0 ,F) where

 Q is a finite set called the states ,

  is a finite set called the alphabet ,

 : Q x   Q is the transition function ,

 q 0  Q is the start state , and

 F  Q is the set of accept states (final

states)

Example :

Finite Automaton M 1

 (^) M 1 = (Q,,,q 0 ,F) , where  (^) Q = {q 1 , q 2 , q 3 },  (^)  = {0,1},  (^)  is described as  (^) q 1 is the start state , and  (^) F = {q 2 }.

0 1 q 1 q 1 q 2 q 2 q 3 q 2 q 3 q 2 q 2

q 1

0

1

(^10)

0,

q 2 q 3

Example :

Finite Automaton M 1

 (^) A = {w | w contains at least one 1 and an even number of 0s follow that last 1}

L(M 1 ) = A, or equivalently, M1 recognizes A

q 1

0

1

(^10)

0,

q 2 q 3

Example :

Finite Automaton M 2

 (^) M 2 = (Q,,,q 0 ,F) , where  (^) Q =  (^)  =  (^)  is described as  (^) is the start state , and  (^) F = { }.

0 1 q 1 q 2

q 1

(^0 1 )

q 2

0

Empty String 

 (^) If the start state is also a final state, what string does it automatically accept?  (^) L(M 3 ) = { w | w is the empty string  or ends in a 0}

q 1 q 2

0

0

1 1

Example :

Finite Automaton M 4

 (^) M 4 = (Q,,,q 0 ,F) , where  (^) Q =  (^)  =  (^)  is described as

 (^) is the start state , and  (^) F = { }.

a b q 1 q 2 r 1 r 2

a

S

q 1 r 1

q 2 r 2

a

a a

b a

b

b (^) b

L(M 4 ) =