Automata and combinatorics

- Lectures 25-27.

- Regular languages
- Deterministic and non-deterministic finite automata
- Rules of sum and product, size of Cartesian products
- Permutations, combinations, r-permutations

Solve each of the following exercises.

- How many elements are in a set
- consisting of pairs of T-shirts and jeans, where there are 5 choices for T-shirts and 3 choices for jeans?
- of possible different set menu dinners each containing an appetizer, a main dish and a dessert, where there are 3 choices of appetizers, 5 choices of a main dish and 2 choices of desserts?

- How many strings of four decimal digits {0,...,9} (such as 1503, 9999,...)
- have distinct digits?
- do not contain the same digit four times?
- begin with an odd digit?
- have exactly three digits that are 4?

- List all
- permutations of {a,b,c}
- 2-permutations of {a,b,c,d}
- 2-combinations of {a,b,c,d}

- How many permutations of letters ABCDEFGH contain
- the string CDE?
- both strings CAB and DE?

- How many ways are there
- to choose 3 out of 10 students for a committee?
- to choose 3 out of 10 students, provided at least one of them must be first-year, and half of the 10 students are first-year?
- to seat n students and n faculty members around a (round) table so that students and faculty alternate?

## Group exercises

For this part of the lab, you will be working in groups of three. In the first part of the exercise, each of three people in the group picks one of the topics below, and solves the corresponding questions. Then, each of you will explain to two of your peers how you have solved these questions. Your explanation should be good enough that they can then solve similar questions on their own.

#### Topic 1: Regular expressions

Write a regular expression for each of the languages below.- A language of all strings over $\{a,b,c\}$ containing a substring "abc".
- A language of all strings over $\{0,1\}$ having 1 as a second-to-last bit (e.g, 010 and 1011 are ok, but not 001).

#### Topic 2: Deterministic finite automata

Recall that a finite automaton is deterministic if from every state it has exactly one outgoing edge for each letter from the alphabet. Draw deterministic finite automata accepting the following languages over {0,1} :

- A language of all strings that contain a substring "00".
- A language of all strings over $\{0, 1\}$ which end with 1.

#### Topic 3: Non-deterministic finite automata

Recall that in a non-determinisitc finite automata it is OK to have multiple edges from the same state labeled with the same label (this is interpreted as "or"), and some edges might be missing (this is interpreted as "stop and reject"). Draw non-deterministic automata for the following languages.

- A language of all strings that do not contain a substring 11 (hint: use "missing edges").
- A language of all strings that have 1 in the second-to-last bit (e.g, 010 and 1011 are ok, but not 001).

## Review after the group exercises

Consider the language of all strings over {0,1} that either contain "00" or have a 0 in the second-to-last position.

- Write a regular expression for this language.
- Draw a 4-state non-deterministic automaton for this language (use both multiple and missing edges).
- Draw a deterministic automaton for this language (hint: start by writing a 4-state deterministic automaton for "has 0 in second-to-last position", and attach it to the automaton that detects a "00" string).