CS3102 Theory of Computation
Warm up: Whatβs the language of this NFA?
start
final
0, π
CS3102 Theory of Computation Warm up: Whats the language of this - - PowerPoint PPT Presentation
CS3102 Theory of Computation Warm up: Whats the language of this NFA? 0, final start Logistics 2 Last Time Non-determinism 3 Showing Regex FSA Show how to convert any regex into a FSA for the same language Idea: show
start
final
0, π
2
3
4
5
FSA Regex π, literal, union, concat, * How to build a Regex Computability by FSA closed under
Non- determinism Makes that easy
β Matches just the string of length 0 β Notation: π or ββ
β Matches a specific string of length 1 β Example: the regex π will match just the string π
β Matches strings that match at least one of the two parts β Example: the regex π|π will match π and π
β Matches strings that can be dividing into 2 parts to match the things concatenated β Example: the regex π π π will match the strings ππ and ππ
β Matches strings that are 0 or more copies of the thing starred β Example: π π πβ will match π, π, or either followed by any number of πβs
6
β Must have exactly one transition per character per state β Can only be in one state at a time
β Allowed to be in multiple (or zero) states! β Can have multiple or zero transitions for a character β Can take transitions without using a character β Models parallel computing
7
8
Driving to a friendβs house Friend forgets to mention a fork in the directions Which way do you go?
9
πππ 0,1 start πππ¦π’ 0,1 1
β Finite number of states β One start state β βFinalβ states β Transitions: (partial) function mapping state-character (or epsilon) pairs to sets of states
β Start in the initial βstateβ β Enter every state reachable without consuming input (π»-transitions) β Read each character once, in order (no looking back) β Transition to new states once per character (based on current states and character) β Enter every state reachable without consuming input (π»-transitions) β Return True if any state you end is final
10
11
12
0,1 start next 0,1 1
{} start
next Start,
Start, next One, next Start, One, next
13
0,1 start next 0,1 1
{} start
next Start,
Start, next One, next Start, One, next
1 1 1 1
β start state and everything reachable using empty transitions
πΈ = π‘ β 2π βπ β π‘ . π β πΊ}
β All states with a start state in them
π π‘, π
πβπ‘
β Transition to the stateset of everything any current state transitions to
14
15 start
0,1 1
Some 0s No 0s
1 Even 1 1
Odd
new Goal: Return 1 if either machine returns 1 Strategy: Run both machines in parallel (non-deterministically) by transitioning to the start states for both without using input
16 start
0,1 1
Some 0s No 0s
1 Even 1 1
Odd
new π π πβͺ = π 1 βͺ π 2 βͺ πππ₯ , Ξ£, πβͺ, πππ₯, πΊ
1 βͺ πΊ 2
πβͺ(π, π) = π1 π, π if π β π 1 {π2 π, π } if π β π 2 πβͺ πππ₯, π = {π‘π’ππ π’, ππ€ππ} π2 π1 e e
17
18
π2 e π1 e
start
0,1 1
Some 0s No 0s
1 Even 1 1
Odd
Goal: Return 1 if the input can be broken into 2 chunks, π1 returns 1 on the first chunk, π2 on the second Strategy: Every time we enter a final state in π1, non-deterministically run the rest of the string on π2. Return 1 if π2 does.
19
π2 e π1 e
start
0,1 1
Some 0s No 0s
1 Even 1 1
Odd
π π ππ = π 1 βͺ π 2, Ξ£, ππ, π01, πΊ
2
ππ(π, π) = π1 π, π if π β π 1 β πΊ
1
π1 π, π , π0,2 if π β πΊ
1
{π2 π, π } if π β π 2
20
21
π1 e e e
start
0,1 1
Some 0s No 0s
1 Goal: Return 1 if the input can be broken into chunks such that π1 returns 1 for every chunk Strategy: Every time we enter a final state in π1, non- deterministically βrestartβ the machine to run on the rest of the string, make sure we return 1 on π
22
π1 e e e
start
0,1 1
Some 0s No 0s
1 Goal: Return 1 if the input can be broken into chunks such that π1 returns 1 for every chunk Strategy: Every time we enter a final state in π1, non- deterministically βrestartβ the machine to run on the rest of the string, make sure we return 1 on π
empty
π π π
23
24
25
000...0000 111...1111 000...0000 111...1111 Γ50,000 Γ50,000 Γ50,000 Γ50,001 000...0000 111...1111 Γ49,999 Γ50,000