Mathematical Foundations of Computer Science - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Mathematical Foundations of Computer Science

Description:

Mathematical Foundations of Computer Science. Chapter 2: Finite Automata. Languages. A language (over an alphabet S) ... 'guts' of the machine. Finite Automata ... – PowerPoint PPT presentation

Number of Views:3175
Avg rating:3.0/5.0
Slides: 35
Provided by: fduu8
Category:

less

Transcript and Presenter's Notes

Title: Mathematical Foundations of Computer Science


1
Mathematical Foundations of Computer Science
  • Chapter 2 Finite Automata

2
Languages
  • A language (over an alphabet S) is any subset of
    the set of all possible strings over S . The
    set of all possible strings is written as S.
  • Example
  • S a, b, c
  • S ?, a, b, c, ab, ac, ba, bc, ca, aaa,
  • one language might be the set of strings of
    length less than or equal to 2.
  • L ?, a, b, c, aa, ab, ac, ba, bb, bc, ca, cb,
    cc

3
Finite Automata
  • A deterministic finite automaton (dfa) is a
    mathematical model for a machine that can accept
    certain types of languages.
  • The singular is automaton, the plural is automata.

4
Finite Automata
"guts" of the machine
on/off switch
accept or reject
tape read head
input tape
A finite automaton
5
Finite Automata
  • The machine, or automaton, when on, will at any
    moment be in some "state".
  • This type of machine has only a finite number of
    states.
  • The machine goes into new states as it reads the
    input tape.
  • When the light is on, the string up to that point
    is "accepted". When off, it is "rejected".
  • The machine has to read all the way to the last
    character on the tape.

6
Finite Automata
  • A deterministic finite automaton (dfa) is a
    quintuple M (Q, S , d, q0, F) , where
  • Q is a finite set of states,
  • S is a finite set of symbols (the alphabet),
  • q0 is one of the states in Q (called the initial
    state),
  • F is a subset of Q and represents the final, or
    accepting states of M,
  • and d Q ? S ? Q is the transition function of
    M.
  • The transition function specifies, for each state
    and symbol, the next state the machine will enter.

7
Finite Automata
  • The transition function specifies, for each state
    and symbol, the next state the machine will
    enter.
  • When we write d(q1, b) q2, we are saying that
    if the machine is in state q1 and the next symbol
    read is b, then the state of the machine becomes
    state q2.
  • The machine always starts in the initial state
    looking at the leftmost symbol on the tape.
  • The machine stops after reading the rightmost
    symbol on the tape.

8
Finite Automata
  • The transitive closure of d , written as d(q1,
    w) q2 is used to represent the fact that the
    machine, when in state q1, winds up in state q2
    by following the path that exists for the
    transitions specified by the series of symbols in
    w.
  • For example, if d(q1, a) q2, d(q2, b) q3 and
    d(q3, a) q4, then d(q1, aba) q4.

9
Finite Automata
  • The language accepted by a dfa is exactly the set
    of strings over the alphabet that result in the
    machine ending in an accepting state. The
    language is symbolized as L(M).
  • The transition function makes the automaton
    deterministic. At each moment in time, the
    machine has exact instructions as to what will
    happen next.

10
Bubble Diagrams
  • In order to visualize a particular finite
    automaton, we draw a bubble diagram, (or bubble
    chart).
  • Here's a simple example
  • The circles represent states, with a double
    circle being an accepting state.
  • The arcs represent the transitions of the
    transition function.

11
Bubble Diagrams
  • What language is accepted by this machine?
  • L x x ? a, b and x has an
    even number of b's

12
Example 1
  • Here is another example of a finite automaton M,
    in "bubble diagram" form
  • What is d(q1, b)?
  • What is d(q0. abbaba)?
  • Given that q3 is the only accepting state, what
    is L(M), the language is accepted by this
    machine?
  • Strings beginning with an a and containing at
    least two a's.

q1
q3
13
Example 2
  • Construct a dfa that accepts the languageL x
    ? a, b x begins and ends with the sequence
    aab.

b
a
a
a
a
a
b
AA
A
AA
A
AAB
b
a
a
b
accepting state. Why?
b
x
b
b
a,b
"trap" state
14
Example 2
  • Construct a dfa that accepts the languageL x
    ? a, b x begins and ends with the sequence
    aab.

b
a
a
a
a
a
b
q2
q4
q5
q1
q3
q0
b
a
a
b
bubble diagram format
b
q6
b
b
qT
a,b
15
Example 2
Table format
16
Example 3
  • Construct a dfa that accepts the languageL x
    ? a, b x has an even number of a's and an odd
    number of b's.

a
OE
EE
a
b
b
b
b
a
EO
OO
a
17
Example 4
  • Construct a dfa that accepts the languageL x
    ? a, b x consists of even number of a's
    followed by an odd number of b's.

a
b
a,b
a
b
a
b
b
a
18
Finite Automata
  • That's how finite automata are built, and that's
    how they work.
  • Some automata are easy to construct others quite
    tricky or difficult.
  • Representations
  • bubble diagram format
  • good for construction
  • good for visualizing behavior
  • table format
  • good for computer simulation
  • good for applying certain algorithms

19
Chapter 2, Section 1Homework
  • 2.1/1-15

20
Non-deterministic finite automata
  • Notice how annoying all the necessary detail is.
    Perhaps we can come up with a more powerful and
    more convenient automaton.

21
Non-deterministic finite automata
  • A non-deterministic finite automaton (nfa) is a
    quintuple M (Q, S , d, q0, F) , where Q is a
    finite set of states, S is a finite set of
    symbols (the alphabet), q0 is one of the states
    in Q (called the initial state), F is a subset of
    Q and represents the final, or accepting states
    of M, and d Q ? S, ? ? 2Q is the transition
    function of M.

22
Non-deterministic finite automata
  • d Q ? S, ? ? 2Q means that if the machine is
    in state q and sees an a (or perhaps merely
    ignoring the input ? he can wind up in any of
    the states within some set of states.
  • d(q, a) q1, q4, q7 goes to any of three
    states.
  • d(q, a) "dies"
  • d(q, ?) q, p goes to either of 2 states
    without looking at the input tape.

23
Non-deterministic finite automata
  • The only difference is in the transition
    function.
  • We now allow the machine to go to a new state
    WITHOUT looking at a symbol. (? transitions)
  • We also allow the machine the choice of going to
    any of a number of states for a given symbol!!!
    (non-deterministic transitions)

24
Non-deterministic finite automata
  • We have just made this machine smart, as we will
    shortly see.
  • Having non-deterministic transitions means that
    we can specify no transition for a qiven state
    and symbol as well, which makes design a little
    less cluttered because we don't have worry about
    "useless" stuff.

25
Non-deterministic finite automata
  • If there is no transition specified,
  • the machine merely dies.
  • It does not accept the string and can accept no
    more input,
  • just like for specifying trap states in a dfa.
  • But if there is ANY path from the initial state
    to an accepting state for a given string
  • that string is accepted and belongs to L(M).
  • even if only one out of a million paths leads to
    an accepting state!!!!
  • Now thats smart!

26
Constructing an nfa
  • Construct an nfa that accepts the languageL x
    ? a, b x begins and ends with the sequence
    aab.

b
end of string aab
q3
start of string aab
middle of string anything
27
Non-deterministic finite automata
  • But nfa's are no more powerful than dfa's !!!
  • If a language can be recognized by an nfa,
  • it can be recognized by a dfa.
  • We "prove" this by demonstrating an algorithm
    that converts any nfa into a corresponding dfa.
  • The book describes the algorithm, but it's hard
    to understand we'll look at how it works by
    studying the last example.

28
Chapter 2, Section 2Homework
  • 2.2/2-12

29
Converting nfa's to dfa's
  • Look at the nfa we just constructed
  • d(q0, a) q1 so d (Q0, a) in the
    corresponding dfa would equal Q1. The subscript
    of Q represents the set of states that the nfa
    could wind up in.
  • d(q0, b) so d (Q0, b) in the
    corresponding dfa would equal QT, the trap state.

30
Converting nfa's to dfa's
  • Of course d (QT, a) d(QT, b) QT since it's
    the trap state.
  • Now we proceed to state Q1 and draw arcs for a
    and for b.
  • We keep going until we add no more new states to
    the dfa and all the transitions have been
    specified.
  • Note that since d(q3, a) q4, q5, d(Q3, a)
    Q45

31
Converting nfa's to dfa's
b
because of the ? transition, if the nfa is in q3,
it could just as well be in q4. (the ? closure of
q3 is q3, q4
32
Converting nfa's to dfa's
  • Start with the initial state of the nfa
  • Create a corresponding initial state in the dfa
  • For each symbol of the alphabet, find the set of
    states that you could wind up in. Create a
    corresponding state in the dfa.
  • Keep going until there are no more states, and no
    more transitions need to be drawn.
  • Note When there are lambda transitions, you
    have to look at the ? closure.
  • Remember a ?a a?
  • Any state in the dfa which has in it the number
    of an accepting state of the nfa becomes an
    accepting state.

33
Chapter 2, Section 3Homework
  • 2.3/1-6, 8, 12

34
Chapter 2 Homework Summary
  • 2.1/1-15
  • 2.2/2-12
  • 2.3/1-6, 8, 12
Write a Comment
User Comments (0)
About PowerShow.com