Docsity

Regular Language computer science, Lecture notes of Computer Science

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 ) =