### CS30 - Spring 2015 - Class 23

#### Lecture notes

- assignment 10
- lab tomorrow
- will play NIM a bit
- then work on assignment

- NIM tournament in class next Tuesday

• talk at a high level about theoretical models of computation

• deterministic finite automata (DFA)
- defined by 5 components
1) a set of states Q
2) the alphabet \sigma
3) q_0 \in Q, the start state
4) F subset Q, the accepting (or final) states
5) the transitions between states
- (Q x \sigma -> Q)
- a transition for each state for each letter in the alphabet to some other state

- a simple (but fairly powerful) model of computation

• some DFA examples (found in DFA_examples)
- no_a: Strings of a's and b's with no a's
- b*

- even_a: Strings of a's with an even number of a's
- (aa)*

- 5a: Strings with a's that are multiples of 5
- (aaaaa)*

- one_a: Strings with only one a
- b*ab*

- a(a|b)*

- start_end: Strings that start and end with the same letter
- (a(a|b)*a)|(b(a|b)*b)|a|b

- odd: odd length strings
- (a|b)((a|b)(a|b))*

- two_a: strings with two or more a's
- (a|b)*a(a|b)*a(a|b)*

- two_exact_a: strings with exactly two a's
- b*ab*ab*

- ab: some number of repetitions of ab
- (ab)*

• non-deterministic finite automata (NFA)
- almost identical definition to DFA except:
- can have epsilon (or sometimes called lambda) transitions from one state to another
- doesn't read anything from the input, just transitions

- for a given state and input, can go to two or more states (rather than just a single one for DFAs)

- do not require that there is a transition for every alphabet letter for every state
- if you encounter a state without a transition for a particular letter, it does not accept

- tend to be a bit easier to work with than DFAs

- NFA's do not actually have any more expressive power
- in particular, for any NFA, there is a corresponding DFA that accepts the same language (i.e. same set of strings)

• some NFA examples (found in NFA_examples)
- start_end_a: start and end with a
- a(a|b)*a

- 2_or_3_a: strings of a's that have lengths divisible by 2 OR 3
- (aa)*|(aaa)*

- end_aa: ends in two a's
- (a|b)*aa

- aa_bb: has either aa or bb as a substring
- (a|b)*(aa|bb)(a|b)*

• regular language
- any language that can be described by a DFA (or an NFA)
- any language that can be described by a regular expression!