# CS 44 – Aug. 29 Regular operations –Union construction Section 1.2 - Nondeterminism –2 kinds of FAs –How to trace input –NFA design makes “union” operation.

## Presentation on theme: "CS 44 – Aug. 29 Regular operations –Union construction Section 1.2 - Nondeterminism –2 kinds of FAs –How to trace input –NFA design makes “union” operation."— Presentation transcript:

CS 44 – Aug. 29 Regular operations –Union construction Section 1.2 - Nondeterminism –2 kinds of FAs –How to trace input –NFA design makes “union” operation easier –Equivalence of NFAs and DFAs

Wolf, Goat, Cabbage A man would like to cross a river with his wolf, goat and head of cabbage. Can only ferry 1 of 3 items at a time. Plus: –Leaving wolf & goat alone: wolf will eat goat. –Leaving goat & cabbage alone: goat will eat cabbage. Yes, we can solve this problem using an FA! –Think about possible states and transitions.

Operations on sets We can create new regular sets from existing ones, rather than starting from scratch. Binary operations –Union –Intersection Unary operations –Complement –Star: This is the concatenation of 0 or more elements. For example, if A = {0, 11}, then A* is { ε, 0, 11, 00, 1111, 011, 110, …} “Closure property”: you always get a regular set when you use the above operations.

Union Book shows construction (see handout) We want to union two languages A 1 and A 2 : M 1 accepts A 1 and M 2 accepts A 2. The combined machine is called M. M pretends it’s running M 1 and M 2 at same time! δ((r 1,r 2 ),a) = (δ 1 (r 1,a),δ 2 (r 2,a)) # states increases because it’s the Cartesian product of M 1 and M 2 ’s states. Next section will show easier way to do union.

Union Book shows construction (see handout) We want to union two languages A 1 and A 2 : M 1 accepts A 1 and M 2 accepts A 2. The combined machine is called M. M pretends it’s running M 1 and M 2 at same time! δ((r 1,r 2 ),a) = (δ 1 (r 1,a),δ 2 (r 2,a)) # states increases because it’s the Cartesian product of M 1 and M 2 ’s states. Next section will show easier way to do union.

Non-determinism There are 2 kinds of FA’s –DFA: deterministic FA –NFA: non-deterministic FA NFA is like DFA except: –A state may have any # of arrows per input symbol –You can have ε-transitions. With this kind of transition, you can go to another state “for free”. Non-determinism can make machine construction more flexible. At first the theory seems more complex, but NFA’s will come in handy.

Example s1s2s3 s4 10, ε1 0, 1 From stateInput 0Input 1Input ε s1 s1, s2 s2s3 s4

continued See the non-determinism? Remember, any time you reach a state that has ε-transitions coming out, take it! It’s free. Let’s trace input 010110. s1s2s3 s4 10, ε1 0, 1