Transcript Slide 1
Conceptual Foundations
(MATH21001)
Lecture Week 8
Reading:
Textbook, Chapter 9: Automata,
Grammars and Languages
Conceptual Foundations © 2008 Pearson Education Australia
Lecture slides for this course are based on teaching materials provided/referred by: (1) Statistics for Managers using
Excel by Levine (2) Computer Algorithms: Introduction to Design & Analysis by Baase and Gelder (slides by Ben Choi to
accompany the Sara Baase’s text). (3) Discrete Mathematics by Richard Johnsonbaugh
1
Learning Objectives
In this lecture, you will learn:
Finite-state machines
Finite-state automata
Languages and grammars
Nondeterministic finite-state automata
Relationships between languages and automata
2
Finite-state Machines
A finite-state machine is an abstract model of a
machine with a primitive internal memory.
A finite-state machine M consists of
(a) A finite set I of input symbols.
(b) A finite set O of output symbols.
(c) A finite set S of states.
(d) A next-state function f from S x I into S.
(e) An output function g from S x I into O
(f) An initial state σ ε S.
We write M = (I, O, S, f, g, σ)
3
Example
Let I={a, b}, O={0, 1}and S={σ0, σ1}.
Define the pair of functions f and g by the
rules given in the table below.
S
σ0
σ1
f
g
I a
b a
σ0
σ1
σ1 0
σ1 1
Table 1
b
1
0
4
Example
• Then M = (I, O, S, f, g, σ0) is a finite state machine.
• Table 1 is interpreted as follows:
f(σ0, a) = σ0
f(σ0, b) = σ1
f(σ1, a) = σ1
f(σ1, b) = σ1
g(σ0, a) = 0
g(σ0, b) = 1
g(σ1, a) = 1
g(σ1, b) = 0
• The next state and output functions can also be
defined by a transition diagram.
5
What is a Transition Diagram?
Let M = (I, O, S, f, g, σ) be a finite state
machine. The transition diagram of M is a
diagraph G whose vertices are the members of S.
Transition diagram is a digraph. The vertices are
the states. The initial state is indicated by an
arrow.
If we are in state σ and inputting i causes output
o and moves us to state σ1, we draw a directed
edge from vertex σ to vertex σ1 and level it i/o.
6
Example – Transition Diagram
Transition diagram of example on slide 4 is shown
below. Table 1 shows that if we are in state σ0 and
we input a, then we will output 0 and will remain in
state σ0. Thus we draw a directed loop on vertex σ0
and label it a/0. By considering all such possibilities
we obtain the transition diagram as follows:
a/0
σ0
a/1
b/1
σ1
b/0
7
Finite-state Automata
A finite state automaton is a special kind of
finite state machine.
A finite state automaton A = (I, O, S, f, g, σ)
is a finite state machine in which the set of
output symbols is {0,1} and where the
current state determines the last output.
8
Example
Draw the transition diagram of the finite state
machine A defined by the table. The initial state
is σ0. Show that A is a finite state automaton.
S
σ0
σ1
σ2
f
g
I a
b a
σ1
σ2
σ2
σ0 1
σ0 1
σ0 1
b
0
0
0
9
Example – Transition Diagram
The transition diagram is shown below. If we
are in state σ0, the last output was 0. If we
are in either state σ1 or σ2, the last output
was 1; thus A is a finite state automaton.
b/0
a/1
a/1
σ0
σ1
a/1
σ2
b/0
b/0
10
Conceptual Foundations © 2008 Pearson Education Australia
Lecture slides for this course are based on teaching materials provided/referred by: (1) Statistics for Managers using
Excel by Levine (2) Computer Algorithms: Introduction to Design & Analysis by Baase and Gelder (slides by Ben Choi to
accompany the Sara Baase’s text). (3) Discrete Mathematics by Richard Johnsonbaugh
11
Languages & Grammars
Definition
Let A be a finite set. A formal language L over
A is a subset of A*, the set of all strings over A.
One way to define a language is to give a list of
rules that the language is assumed to obey.
12
Grammar
A grammar G =(N, T, P, S) consists of
A finite set N of non-terminal symbols
A finite set T of terminal symbols
A finite subset P
A starting symbol S which is a non-terminal.
13
Example – A grammar for
Integers
The following grammar generates all integers.
<digit>::=0|1|2|3|4|5|6|7|8|9
<integer>::=<signed integer>|<unsigned integer>
< signed integer>::=+< unsigned integer>|-< unsigned integer>
<unsigned integer>::=<digit>|<digit><unsigned integer>
14
Summary
In this lecture, we have
Introduced finite-state machines (FSM) and
finite-state automata (FSA).
Reviewed various examples of FSM and
FSA.
Discussed transition diagram.
Introduced language and grammar.
15