0% found this document useful (0 votes)
17 views27 pages

Lec 07 Transition Graphs

Uploaded by

alishbalatif398
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views27 pages

Lec 07 Transition Graphs

Uploaded by

alishbalatif398
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Transition Graphs

Transition Graphs

• Relaxing the Restriction on Inputs

• Looking at TGs

• Generalized Transition Graphs

• Nondeterminism

2
Relaxing the Restriction on Inputs
Relaxing the restrictions on inputs

• Let’s consider a very specialized FA that accepts only the word


baa:

• Beginning at the start state, anything but the string baa will
drop down into the garbage collecting state and never be
seen again. Even the string baabb will fail.
• Hence the language accepted by this FA is L = {baa}

4
Relaxing restrictions on input
• Let us relax the restriction that an FA can only read one letter from the
input string at a time

• Suppose we now allow a machine to read either one or two letters of the
input string at a time. Then we may design a machine that accepts only
the word baa with fewer states as the one below:

5
Definition of A Transition Graph (NFA)

• A transition graph, abbreviated TG, is a collection of three


things:
1. A finite set of states, at least one of which is designated as the
start state (-), and some (maybe none) of which are
designated as final states (+).

2. An alphabet ∑ of possible input letters from which input


strings are formed.

3. A finite set of transitions (edge labels) that show how to go


from some states to some others, based on reading specified
substrings of input letters (possibly even the null string Λ).

6
• We should note the following from the definition of a TG:

1. Clause 3 in the definition means that every edge is labeled by some string
or strings of letters, not necessarily only one letter.

2. We are NOT requiring that there be any specific number of edges


emanating from any state: Some states may have no edge coming out at
all, and some may have thousands (e.g., edges labeled a, aa, aaa, aaaa, ...).

3. A successful path through a TG is a series of edges forming a path


beginning at some start state (there may be several) and ending at a final
state.

4. If we concatenate in order the strings of letters that label each edge in a


successful path, we produce a word that is accepted by this TG.

7
Example
Consider the Language L , defined over Σ = {a, b} of all
strings including Λ. The language L may be accepted by the
following TG

8
Example
• Consider the Language L of strings, defined over Σ = {a, b},
containing double a.

• The language L may be expressed by the following regular


expression (a+b)* (aa) (a+b)*.

• This language may be accepted by the following TG

9
Example
• Consider the language L of strings, defined over Σ={a, b},
having double a or double b.
• The language L can be expressed by RE (a+b)* (aa + bb)
(a+b)*.
• The above language may also be expressed by the following
TGs.

10
Example

• For example, consider the following TG:

• The path from state 1 to state 2 to state 3 back to state 1 and then to the
final state 4 corresponds to the string (abb)(Λ)(aa)(b) = abbaab.

• Some other accepted words are abba, abbaaabba, and b.

• When an edge is labeled with Λ, it means that we can take the ride it
offers for free (without consuming any letter from the input string).

11
Example contd.

• If we are presented with a particular string to run on a given


TG, we must decide how to break the string into substrings
that may correspond to the labels of edges in the TG.

• Let’s run the input string abbab on the machine in the


previous slide:
– The substring abb takes us from state 1 to state 2.
– We move to state 3 along the Λ-edge without any substring being
consumed.
– We are now in state 3 and what is left of the input string is the
substring ab. We cannot read aa, so we must read only a and go to
state 4.
– At state 4, we have b left in the input string but no edge to follow, so
we must crash and reject the input string abbab.

12
• Because we allow some edges to be traversed for free, it is
logical to allow for the possibility of more than one start
state, as illustrated below:

• These two machines are equivalent, in the sense that all the
strings accepted by the first are accepted by the second and
vise versa.
• Important Note: Every FA is also a TG. However, NOT every
TG satisfies the definition of an FA.

13
Looking at TGs

In this section, we will consider some more examples of TGs.


Example

• This TG accepts nothing, not even the null string.

• To be able to accept anything, it must have a final state.

15
Example

• This TG accepts only the null string Λ.


• Any other string cannot have a successful path to the final
state through labels of edges because there are no edges (and
hence no labels).
• Any TG in which some start state is also a final state will
always accept the null string Λ. This is also true of FAs.

16
Example

• This machine accepts only the words Λ, baa, and


abba.
• Anything read while in the final state will cause a
crash, because the final state has no outgoing
edges.

17
Example

• We can read all the input letters, one at a time, and stay in the left-side
state. When we read a b, if it is the very last letter of the input string, we
can use it to go to the final state. Note that this b must be the very last
letter, because once we are in the right-side state, if we try to read
another letter, we will crash.

• It is possible for an input string ending with a b to follow an unsuccessful


path that does not lead to acceptance (e.g., following the b-edge too soon
-
and crash, or looping back to the state when reading the last b).

• However, all words ending with a b can be accepted by some path. Hence,
the language accepted by this TG is (a + b)*b.

18
Example

• In this TG, every edge is labeled with a pair of letters. Thus, for a string to
be accepted, it must have an even number of letters.

• Let’s call the left state the balanced state, and the right state the
unbalanced state.

• If the first pair of letters that we read is a double (aa or bb), then we stay
in the balanced state. While in the balanced state, we have read an even
number of a’s and an even number of b’s.

19
EVEN-EVEN

• When a pair of unmatched letters is read (ab or ba), the machine flips over
to the unbalanced state, meaning that it has read an odd number of a’s
and an odd number of b’s.

• We do not return to the balanced state until another unmatched pair is


read. The discovery of two unmatched pairs makes the total number of a’s
and the total number of b’s read from the input string even again.

• This TG accepts exactly the language EVEN - EVEN.

• Recall that EVEN - EVEN is the language of all words containing an even
number of a’s and an even number of b’s, including the null string Λ.

20
Generalized Transition Graphs
(GTG)
Definition

A generalized transition graph (GTG) is a collection


of three things:
1. A finite set of states, of which at least one is a
start state and some (maybe none) are final
states.

2. An alphabet ∑ of input letters.

3. Directed edges connecting some pairs of states,


each labeled with a regular expression.

22
Example

• Consider this GTG:

• This GTG accepts all strings without a double b.


• Note that the word containing the single letter b can take the
free ride along the Λ-edge from start to middle, and then
have letter b read to go to the final state.
• Typo in textbook: The first edge should be labeled (ba + a)* as
in the figure above, not (ab + a)*.

23
• Note that there is no difference between the Kleene star
closure for regular expressions and a loop in transition graphs,
as illustrated in the following figure:

• In the first picture we may loop in the middle state or go to


the third state. To not loop corresponds to taking the Λ choice
from the b*-edge in the second picture.

24
NonDeterminism
NonDeterminism

• We have already seen that in a TG, a particular string of input


letters may trace through the machine on different paths,
depending on our choice of grouping.

• This figure shows part of some TG.

• The input string abb can go from state 3 to state 4, or to state


5, depending on whether we read the letters two and one, or
all three at once.

26
NonDeterminism

• The ultimate path through the machine is NOT determined by


the input alone. Human choice becomes a factor in selecting
the path. The machine does not make all its own
determination.

• Therefore, we say that TGs are nondeterministic.

27

You might also like