12
Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu [email protected] Department of Computer Science & Engineering Fall 2009

Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu [email protected] Department of Computer Science & Engineering Fall 2009

Embed Size (px)

Citation preview

Page 1: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

Examples for Finite Automata

CSC3130 Tutorial One

Xiao Linfu

[email protected]

Department of Computer Science & Engineering

Fall 2009

Page 2: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

Outline

• DFA example

• NFA example

• NFA to DFA conversion

• Regular Expressions

Page 3: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

DFA

• For every string x, there is a unique path from initial state and associated with x.

• x is accepted if and only if this path ends at a accept state.

x

Page 4: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

NFA

• For any string x, there may exist none or more than one path from initial state and associated with x.

• x is accepted if there is some path that ends at a accept state.

Page 5: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

Strings With Common Prefix

• Construct a DFA that accepts a language L over = {0, 1} such that L is the set of all strings starting with “101”.

q2

0q0start q1

1q3

1

1 0

dead statedead state

0,1

absorbing state

absorbing state

q4

0

0,1

Page 6: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

Strings With Common Suffix

• Construct a DFA that accepts a language L over = {0, 1} such that L is the set of all strings ending with “101”.

q11

q100

q1011

1

0

0

1

0q0

start

Page 7: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

NFA for Common Suffix

• We can have a simpler representation for common suffix language using NFA:

• Use subset construction to convert it to a DFA.

start q2

0q3

1q1

1q0

1,0

q0q11

q0q20

q0q1q31

10

0

1

0q0

startcompare with previous DFA

compare with previous DFA

Page 8: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

NFA Example

• Construct NFAs for the following languages over the alphabet {a, b, …, z}:– All strings that contain eat or sea or easy

start q2

aq3

tq1

e

q4

all

q0

all

q6

eq5

as

s y

Page 9: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

NFA Example

• Construct NFA for the language over the alphabet {a, b, …, z} such that every string doesn’t contain “fool”.

start q0 q1

‘f’q2

‘o’

‘o’q2 q3

‘l’

not ‘f’ ‘f’‘f’

‘f’

not ‘f’,‘o’not ‘f’,‘l’

not ‘f’,‘o’

dead statedead state

Page 10: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

Regular Expressions

- Alphabet X = {a, b, c, d}1) (a + b)*

all strings containing only a and b

2) c(a + b + c)*c2

all strings containing only a, b, and c that begin with c and end with cc

3) all strings containing only one b

(a+c+d)*b(a+c+d)*

Page 11: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

Regular Expressions

- Alphabet X = {0, 1}1) (0 + 1)*

the set of all binary strings

2) 031*04

all strings consisting of three 0’s, followed by any number of 1’s, followed by four 0’s

3) 0*1001*

all strings starting with any number of 0’s, followed by 100, followed by and number of 1’s

Page 12: Examples for Finite Automata CSC3130 Tutorial One Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009

Thank you!