This action might not be possible to undo. Are you sure you want to continue?

# Lecture Outline

Finite Automata Formal Deﬁnition DFA Computation Regular Operations

Finite Automata

The ﬁnite state machine or ﬁnite automaton is the simplest computational model of limited memory computers. Example: an automatic door opener at a supermarket decides when to open or close the door, depending on the input provided by its sensors.

is the number of 0’s (in a given string) multiple of 4. does a given string end in 00.Finite Automata The ﬁnite state machine or ﬁnite automaton is the simplest computational model of limited memory computers. to decide whether a given input satisﬁes certain conditions. depending on the input provided by its sensors. .e. Example: an automatic door opener at a supermarket decides when to open or close the door.. i. Examples of decision problems: does a given string have an even number of 1’s. Finite automata are designed to solve decision problems.

Example: Door Opener states: closed. rear. both. neither nonloop transitions: closed → open on front open → closed on neither . open input conditions: front.

open input conditions: front. both. neither nonloop transitions: closed → open on front open → closed on neither REAR BOTH NEITHER FRONT REAR BOTH FRONT CLOSED OPEN NEITHER . rear.Example: Door Opener states: closed.

δ. . The automaton “accepts” the input if its resulting state (after reading of the input string is complete) belongs to F . F ). q0 ∈ Q is the start state. DFA computation can be described informally using a tape. and a ﬁnite-state control with a read head advancing over the input. cells with symbols.Formal Deﬁnition Deﬁnition A deterministic ﬁnite automaton (DFA) is a 5-tuple (Q. q0 . Σ is a ﬁnite alphabet whose members are called symbols. an automaton reads its symbols one-by-one and changes its state (starting from q0 ) according to δ. Given an input string over Σ (written on the input tape). otherwise “rejects”. Σ. where Q is a ﬁnite set whose members are called states. δ : Q × Σ → Q is the transition function. and F ⊆ Q is the set of accept states (or ﬁnal states).

What is what in Door Opener REAR BOTH NEITHER FRONT FRONT REAR BOTH CLOSED OPEN NEITHER Q: Is it a DFA? .

What is what in Door Opener REAR BOTH NEITHER FRONT REAR BOTH FRONT CLOSED OPEN NEITHER This automaton is not a DFA since it supposedly operates inﬁnitely long and thus there are no starting state q0 and ﬁnal states F deﬁned. Σ. Recall that Q is a ﬁnite set whose members are called states. δ. it does correspond to some Q. What are the states of the Door Opener? . However.

Q = {CLOSED. However. OPEN} . Σ.What is what in Door Opener REAR BOTH NEITHER FRONT REAR BOTH FRONT CLOSED OPEN NEITHER This automaton is not a DFA since it supposedly operates inﬁnitely long and thus there are no starting state q0 and ﬁnal states F deﬁned. δ. it does correspond to some Q.

Σ. What are they in the Door Opener? .What is what in Door Opener REAR BOTH NEITHER FRONT REAR BOTH FRONT CLOSED OPEN NEITHER This automaton is not a DFA since it supposedly operates inﬁnitely long and thus there are no starting state q0 and ﬁnal states F deﬁned. δ. However. Recall that Σ is a ﬁnite alphabet containing possible input symbols. it does correspond to some Q.

However. BOTH. REAR. δ. Σ. it does correspond to some Q. NEITHER} . Σ = {FRONT.What is what in Door Opener REAR BOTH NEITHER FRONT REAR BOTH FRONT CLOSED OPEN NEITHER This automaton is not a DFA since it supposedly operates inﬁnitely long and thus there are no starting state q0 and ﬁnal states F deﬁned.

it does correspond to some Q. However. δ. Σ. Recall that transition function is a function δ : Q × Σ → Q deﬁning how the automaton behaves.What is what in Door Opener REAR BOTH NEITHER FRONT REAR BOTH FRONT CLOSED OPEN NEITHER This automaton is not a DFA since it supposedly operates inﬁnitely long and thus there are no starting state q0 and ﬁnal states F deﬁned. .

it does correspond to some Q. However. Σ. δ.What is what in Door Opener REAR BOTH NEITHER FRONT REAR BOTH FRONT CLOSED OPEN NEITHER This automaton is not a DFA since it supposedly operates inﬁnitely long and thus there are no starting state q0 and ﬁnal states F deﬁned. FRONT OPEN OPEN REAR CLOSED OPEN BOTH CLOSED OPEN NEITHER CLOSED CLOSED CLOSED OPEN .

labelled with symbols (elements of Σ). An incoming edge from nowhere encodes the starting state. Thus. Directed edges. Nodes with double border encode accept states (elements of F ). encode δ.State Diagram of a DFA Nodes encode the states (elements of Q). each node has |Σ| outgoing edges. Parallel edges can be combined into a single edge with multiple labels. .

1}. marking the starting and accepting states: start q1 q2 q3 . and transition function δ given by the following table: q1 q2 q3 0 1 q1 q2 q3 q2 q2 q1 We start with drawing nodes (labeled with elements of Q). ﬁnal state set F = {q2 }. alphabet Σ = {0. start state q1 . q2 .Drawing a State Diagram Q: Draw a state diagram of a DFA M1 with state set Q = {q1 . q3 }.

ﬁnal state set F = {q2 }. start state q1 . q2 . 1}. alphabet Σ = {0. q3 }. and transition function δ given by the following table: 0 1 q1 q1 q2 q2 q3 q2 q3 q2 q1 Then we draw outgoing edges (deﬁned by δ) for the ﬁrst node (q1 is this example): 0 start q1 1 q2 q3 .Drawing a State Diagram Q: Draw a state diagram of a DFA M1 with state set Q = {q1 .

1}. q2 . and transition function δ given by the following table: 0 1 q1 q1 q2 q2 q3 q2 q3 q2 q1 Similarly we draw outgoing edges for the other nodes and we are done: 0 start q1 1 q3 1 0 0 1 q2 . start state q1 . q3 }. ﬁnal state set F = {q2 }.Drawing a State Diagram Q: Draw a state diagram of a DFA M1 with state set Q = {q1 . alphabet Σ = {0.

Languages Deﬁnition Let Σ be an alphabet. i. any set of strings over Σ. The language corresponding to a decision problem is the set of strings encoding yes-instances.e. We let Σ∗ denote the set of all (ﬁnite) strings over Σ.. Given an input (string) is the answer “yes” or “no”? Strings for which the answer is “yes” are called yes-instances and the others are no-instances. . A language over Σ is any subset of Σ∗ . We use languages to encode decision problems.

. Thus recognizing a language means being able to distinguish membership from nonmembership in the language. thus solving the corresponding decision problem. We let L(M) denote the language recognized by M. We say that M recognizes A iﬀ M accepts every string in A and rejects every string in Σ∗ − A. Every DFA recognizes a unique language.Recognizng DFA Deﬁnition Let M be a DFA with alphabet Σ and let A ⊆ Σ∗ be a language over Σ.

Designing a DFA Q: Design a DFA recognizing the language B = {x ∈ {0. to distinguish whether the current symbol (that will be the last one at some point) matches the recorded ﬁrst symbol. . reject otherwise. In order to design such a DFA we need: to “record” the ﬁrst symbol of the input (using states as the only available sort of memory). 1} | |x| ≥ 2 and the 1st symbol of x equals the last symbol of x}. (at the end) accept if it does.

The computation (s0 . and si = δ(si−1 . s1 . the start state. and if the latter holds. . . . . we say that M rejects w . Thus s0 . Suppose w = w1 w2 · · · wn where wi ∈ Σ for all 1 ≤ i ≤ n. . Σ. wi ) for all 1 ≤ i ≤ n. . sn ) is accepting if sn ∈ F . δ. . q0 . s0 = q0 . . and is rejecting otherwise. If the former holds. starting with the start state. . sn ) where each si ∈ Q. . is the sequence of states that M goes through while reading w from left to right. we say that M accepts w . . s1 . Deﬁnition Let M = (Q. F ) be a DFA and let w ∈ Σ∗ be a string over Σ.DFA Computation We now deﬁne a DFA computation formally. The computation of M on input w is the unique sequence of states (s0 . .

.e.Examples Example: DFA that recognizes multiples of 3 in unary. Deﬁnition A language A ⊆ Σ∗ is regular iﬀ some DFA recognizes it. 1} with an even number of 1s. c} containing abacab as a substring. b.. (Idea is useful for text search. binary. i. Strings over {0. 1} with an even number of 1s or an odd number of 0s. A = L(M) for some DFA M.) Example: Strings over {0. Example: DFA that accepts strings over {a.

xk | k ∈ Z ∧ k ≥ 0 ∧ ∀i = 1. . . In other words. 2. the class of regular languages is closed under the union and concatenation operations. . . Read proofs in Sipser pp.Regular Operations Let A and B be two languages. . .44-47. . xi ∈ A} Theorem If A and B are regular languages then so are A ∪ B and A B. k. We deﬁne the following regular operations: Union: A ∪ B = {x | x ∈ A ∨ x ∈ B} Concatenation: A B = {xy | x ∈ A ∧ y ∈ B} Star: A = {x1 x2 .