Download - Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Transcript
Page 1: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Nondeterministic Finite Automata and Regular Expressions

CS 2800: Discrete Structures, Spring 2015

Sid Chaudhuri

Page 2: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Recap: Deterministic Finite Automaton● A DFA is a 5-tuple M = (Q, Σ, δ, q

0, F)

– Q is a finite set of states– Σ is a finite input alphabet (e.g. {0, 1})– δ is a transition function δ : Q × Σ → Q

– q0 ∈ Q is the start/initial state

– F ⊆ Q is the set of final/accepting states

Yes No1

100

Page 3: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

csunplugged.com, clubpenguin.wikia.com

Page 4: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

csunplugged.com, clubpenguin.wikia.com

P = NP!!!

Page 5: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

csunplugged.com, clubpenguin.wikia.com

P = NP!!!

Page 6: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

csunplugged.com, clubpenguin.wikia.com

P = NP!!!

A NON-deterministic finite automaton lets you try all possible choices in

parallel. If ANY choice leads you to the treasure, the pirate can't harm you!

Page 7: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

A non-deterministic finite automaton

q0

1 0,10,1 q

1 0,1q2

Page 8: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

A non-deterministic finite automaton

q0

1 0,10,1 q

1 0,1q2

Different transitionsfrom q

0 on input 1

Page 9: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

A non-deterministic finite automaton

q0

1 0,10,1 q

1 0,1q2

An NFA accepts a string x if it can getto an accepting state on input x

Different transitionsfrom q

0 on input 1

Page 10: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

A non-deterministic finite automaton

q0

1 0,10,1 q

1 0,1q2

What language does this automaton accept?

Page 11: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

A non-deterministic finite automaton

q0

1 0,10,1 q

1 0,1q2

Answer: All strings ending with 1

Page 12: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Another NFA

q0

1 0,10,1 q

2 0,1q3

What language does this automaton accept?

q1

0,1

Page 13: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Another NFA

q0

1 0,10,1 q

2 0,1q3

Answer: All strings with 1 in the penultimate place

q1

0,1

Page 14: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton● An NFA is a 5-tuple M = (Q, Σ, δ, q

0, F)

Page 15: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton● An NFA is a 5-tuple M = (Q, Σ, δ, q

0, F)

– Q is a finite set of states

q0

q1 q

2q

3

Page 16: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton● An NFA is a 5-tuple M = (Q, Σ, δ, q

0, F)

– Q is a finite set of states– Σ is a finite input alphabet (e.g. {0, 1})

q0

q1 q

2q

3

Page 17: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

0,1

Non-deterministic Finite Automaton● An NFA is a 5-tuple M = (Q, Σ, δ, q

0, F)

– Q is a finite set of states– Σ is a finite input alphabet (e.g. {0, 1})

– δ is a transition function δ : Q × Σ → 2Q

q0

q1

1 0,10,1 q2 0,1q

3

Page 18: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

0,1

Non-deterministic Finite Automaton● An NFA is a 5-tuple M = (Q, Σ, δ, q

0, F)

– Q is a finite set of states– Σ is a finite input alphabet (e.g. {0, 1})

– δ is a transition function δ : Q × Σ → 2Q

q0

q1

1 0,10,1 q2 0,1q

3

Only changefrom DFAs

Page 19: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

0,1

Non-deterministic Finite Automaton● An NFA is a 5-tuple M = (Q, Σ, δ, q

0, F)

– Q is a finite set of states– Σ is a finite input alphabet (e.g. {0, 1})

– δ is a transition function δ : Q × Σ → 2Q

– q0 ∈ Q is the start/initial state

q0

q1

1 0,10,1 q2 0,1q

3

Only changefrom DFAs

Page 20: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

0,1

Non-deterministic Finite Automaton● An NFA is a 5-tuple M = (Q, Σ, δ, q

0, F)

– Q is a finite set of states– Σ is a finite input alphabet (e.g. {0, 1})

– δ is a transition function δ : Q × Σ → 2Q

– q0 ∈ Q is the start/initial state

– F ⊆ Q is the set of final/accepting states

q0

q1

1 0,10,1 q2 0,1q

3

Only changefrom DFAs

Page 21: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● An NFA accepts a string x if it can get to an accepting state on input x

Page 22: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● An NFA accepts a string x if it can get to an accepting state on input x– Think of it as trying many options in parallel, and

hoping one path gets lucky

Page 23: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● An NFA accepts a string x if it can get to an accepting state on input x– Think of it as trying many options in parallel, and

hoping one path gets lucky

● Transition f (state, symbol) ↦ ∅ is possible

Page 24: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● An NFA accepts a string x if it can get to an accepting state on input x– Think of it as trying many options in parallel, and

hoping one path gets lucky

● Transition f (state, symbol) ↦ ∅ is possible– … the NFA treats this as a rejecting path (the string

may still reach an accepting state by another path)

Page 25: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● An NFA accepts a string x if it can get to an accepting state on input x– Think of it as trying many options in parallel, and

hoping one path gets lucky

● Transition f (state, symbol) ↦ ∅ is possible– … the NFA treats this as a rejecting path (the string

may still reach an accepting state by another path)– A convenient shortcut for our “hell/black-hole” state

Page 26: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● An NFA accepts a string x if it can get to an accepting state on input x– Think of it as trying many options in parallel, and

hoping one path gets lucky

● Transition f (state, symbol) ↦ ∅ is possible– … the NFA treats this as a rejecting path (the string

may still reach an accepting state by another path)– A convenient shortcut for our “hell/black-hole” state– Class convention: Draw all possible transitions for DFA.

Not required for NFA (missing transitions lead to hell).

Page 27: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● Every DFA is an NFA

Page 28: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● Every DFA is an NFA– If we're strict with our notation, we need to replace the

transitionf (state

1, symbol) ↦ state

2 with

f (state1, symbol) ↦ {state

2}

Page 29: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● Every DFA is an NFA– If we're strict with our notation, we need to replace the

transitionf (state

1, symbol) ↦ state

2 with

f (state1, symbol) ↦ {state

2}

● Every NFA can be simulated by a DFA

Page 30: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● Every DFA is an NFA– If we're strict with our notation, we need to replace the

transitionf (state

1, symbol) ↦ state

2 with

f (state1, symbol) ↦ {state

2}

● Every NFA can be simulated by a DFA– … i.e. they accept exactly the same language

Page 31: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Non-deterministic Finite Automaton

● Every DFA is an NFA– If we're strict with our notation, we need to replace the

transitionf (state

1, symbol) ↦ state

2 with

f (state1, symbol) ↦ {state

2}

● Every NFA can be simulated by a DFA– … i.e. they accept exactly the same language– Exponential blowup: if the NFA has n states, the DFA

can require up to 2n states

Page 32: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Thought for the Day #1

Find an NFA with n states that can't be simulated by a DFA with less than 2n states

Page 33: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

Page 34: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

p

q

ra

a

NFA(fragment)

Page 35: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

p

q

ra

a

{p} {q, r}a

DFA (fragment)NFA(fragment)

Page 36: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

p

q

ra

a

{p} {q, r}a

NFA(fragment)

DFA (fragment)

(This is merely illustrative – formal construction on following slides)

“Subset construction”Main idea: ONE state of DFA tracks current states of ALL evolving paths of NFA

Page 37: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

NFA Equivalent DFA

Specification

States

Alphabet

Transition Function

Initial State

Accepting States

Page 38: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

NFA Equivalent DFA

Specification (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'

0, F')

States

Alphabet

Transition Function

Initial State

Accepting States

Page 39: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

NFA Equivalent DFA

Specification (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'

0, F')

States Q 2Q

Alphabet

Transition Function

Initial State

Accepting States

Page 40: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

NFA Equivalent DFA

Specification (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'

0, F')

States Q 2Q

Alphabet Σ Σ

Transition Function

Initial State

Accepting States

Page 41: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

NFA Equivalent DFA

Specification (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'

0, F')

States Q 2Q

Alphabet Σ Σ

Transition Function δ δ'(S, a) = ∪s ∈ S δ(s, a)

Initial State

Accepting States

Page 42: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

NFA Equivalent DFA

Specification (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'

0, F')

States Q 2Q

Alphabet Σ Σ

Transition Function δ δ'(S, a) = ∪s ∈ S δ(s, a)

Initial State q0

q'0 = {q

0}

Accepting States

Page 43: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Every NFA can be simulated by a DFA

NFA Equivalent DFA

Specification (Q, Σ, δ, q0, F) (2Q, Σ, δ', q'

0, F')

States Q 2Q

Alphabet Σ Σ

Transition Function δ δ'(S, a) = ∪s ∈ S δ(s, a)

Initial State q0

q'0 = {q

0}

Accepting States F F' = {S ∈ 2Q | S ∩ F ≠ ∅}

Page 44: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Why NFAs?

Page 45: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Why NFAs?

● They can be way more compact than DFAs

Page 46: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Why NFAs?

● They can be way more compact than DFAs

0,1

q0

q1

1

0,1

q3

q20,1

NFA

Page 47: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Why NFAs?

● They can be way more compact than DFAs

q000

q001

q010

q011

q100

q101

q110

q111

0 1 0

00

00

0

0

1

1

1

1

1

1

1

0,1

q0

q1

1

0,1

q3

q20,1

NFA Equivalent minimal DFA

Page 48: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Why NFAs?

● They can be way more compact than DFAs

● It's easier to directly convert regular expressions (“wildcard search” on steroids) to NFAs

q000

q001

q010

q011

q100

q101

q110

q111

0 1 0

00

00

0

0

1

1

1

1

1

1

1

0,1

q0

q1

1

0,1

q3

q20,1

NFA Equivalent minimal DFA

Page 49: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

XKCD

Page 50: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Playing with regexes

● http://regex101.com/● http://rubular.com/● http://www.google.com/search?q=online+regex+tester

Page 51: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Regular expressions (“regex”-es) are defined by structural induction

(start with simple base expressions, construct more complicated ones recursively)

Page 52: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Empty set

L(∅) = ∅

Page 53: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Empty string

L(ε) = {ε}

Page 54: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Literal character

L(x) = {x}

e.g. L(1) = {1}, L(2) = {2}, L(a) = {a}

Page 55: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Concatenation

L(AB) = {ab | a ∈ L(A), b ∈ L(B)}

e.g. L(12) = {12}, L(aabb) = {aabb}

Page 56: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Concatenation

L(AB) = {ab | a ∈ L(A), b ∈ L(B)}

e.g. L(12) = {12}, L(aabb) = {aabb},L(aε) = ?

Page 57: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Concatenation

L(AB) = {ab | a ∈ L(A), b ∈ L(B)}

e.g. L(12) = {12}, L(aabb) = {aabb},L(aε) = {a}

Page 58: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Concatenation

L(AB) = {ab | a ∈ L(A), b ∈ L(B)}

e.g. L(12) = {12}, L(aabb) = {aabb},L(aε) = {a}, L(a∅) = ?

Page 59: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Concatenation

L(AB) = {ab | a ∈ L(A), b ∈ L(B)}

e.g. L(12) = {12}, L(aabb) = {aabb},L(aε) = {a}, L(a∅) = ∅

Page 60: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Alternation

L(A|B) = L(A) ∪ L(B)

e.g. L(1|2) = {1, 2}, L(aa|bb) = {aa, bb}

Page 61: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Alternation

L(A|B) = L(A) ∪ L(B)

e.g. L(1|2) = {1, 2}, L(aa|bb) = {aa, bb},L(a|ε) = ?

Page 62: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Alternation

L(A|B) = L(A) ∪ L(B)

e.g. L(1|2) = {1, 2}, L(aa|bb) = {aa, bb},L(a|ε) = {a, ε}

Page 63: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Alternation

L(A|B) = L(A) ∪ L(B)

e.g. L(1|2) = {1, 2}, L(aa|bb) = {aa, bb},L(a|ε) = {a, ε}, L(a|∅) = ?

Page 64: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Alternation

L(A|B) = L(A) ∪ L(B)

e.g. L(1|2) = {1, 2}, L(aa|bb) = {aa, bb},L(a|ε) = {a, ε}, L(a|∅) = {a}

Page 65: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...}

Page 66: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...},L((ab)*) = ?

Page 67: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...},L((ab)*) = {ε, ab, abab, ababab, ...}

Page 68: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...},L((ab)*) = {ε, ab, abab, ababab, ...},

L((a|b)*) = ?

Page 69: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...},L((ab)*) = {ε, ab, abab, ababab, ...},

L((a|b)*) = {ε, a, b, aa, ab, ba, bb, aaa, aab, aba, ...}

Page 70: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...},L((ab)*) = {ε, ab, abab, ababab, ...},

L((a|b)*) = {ε, a, b, aa, ab, ba, bb, aaa, aab, aba, ...},L(ε*) = ?

Page 71: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...},L((ab)*) = {ε, ab, abab, ababab, ...},

L((a|b)*) = {ε, a, b, aa, ab, ba, bb, aaa, aab, aba, ...},L(ε*) = {ε}

Page 72: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...},L((ab)*) = {ε, ab, abab, ababab, ...},

L((a|b)*) = {ε, a, b, aa, ab, ba, bb, aaa, aab, aba, ...},L(ε*) = {ε}, L(∅*) = ?

Page 73: Nondeterministic Finite Automata and Regular Expressions€¦ · They can be way more compact than DFAs It's easier to directly convert regular expressions (“wildcard search”

Kleene star

L(A*) ={ε} ∪ { x

1x

2...x

n | n ∈ N, x

i ∈ L(A) }

e.g. L(a*) = {ε, a, aa, aaa, aaaa, ...},L((ab)*) = {ε, ab, abab, ababab, ...},

L((a|b)*) = {ε, a, b, aa, ab, ba, bb, aaa, aab, aba, ...},L(ε*) = {ε}, L(∅*) = {ε}